Salesforce Interview Question – Part 5

Share This Post

1. What is an Object?

Ans. An object in Salesforce is a fundamental data structure used to store and manage data. Objects can represent various types of entities such as standard objects (like Accounts, Contacts, Opportunities) or custom objects (created by users to suit their specific needs). Objects contain fields to store data and can also have related records through relationships.

2. What is the difference between master details and lookup relationships?

AspectMaster-Detail RelationshipLookup Relationship
NatureParent-child relationship with cascade behaviorSimple association between two objects
OwnershipChild record is owned by the parentChild record is not owned by the parent
Deletion BehaviorCascade deletion of child records (dependent)Child records remain even if parent is deleted
Required RelationshipAlways required on the child sideOptional relationship
Roll-Up SummaryCan have roll-up summary fields on the parentCannot have roll-up summary fields
Field CreationChild records remain even if the parent is deletedCreates a custom field on the child object
SharingInherits parent’s sharing settingsInherits parent’s sharing settings (by default)
PolymorphicSupports polymorphic relationships (multiple parents)Does not support polymorphic relationships
HierarchicalCan be used to create hierarchical relationshipsCannot be used to create hierarchical relationships

3. what is the junction object?

A junction object is a custom object in Salesforce used to create a many-to-many relationship between two objects. It contains two master-detail relationships (or lookup relationships) to the objects you want to relate. Junction objects are typically used to model complex relationships that can’t be represented directly by a single relationship.

4. what is the difference between role and profile?

AspectRoleProfile
PurposeDefines a user’s position in the hierarchyDefines what a user can do in Salesforce
Data AccessControls data visibility and sharingControls object access and permissions
Hierarchy ControlDetermines user’s place in the hierarchyDoes not affect hierarchy structure
Multiple AssignmentCan have multiple rolesA user can have only one profile

5. what is the difference between a profile and a permission set?

AspectProfilePermission Set
UsageAssigned to users as part of their user settingsAssigned to users on top of their existing profile
Object PermissionsControls object-level accessProvides additional object and field permissions
Field PermissionsDetermines field-level accessProvides additional field-level permissions
User PermissionsDefines user-level capabilitiesProvides additional user-level capabilities
Tab VisibilityControls access to tabs and appsCan extend or modify tab and app visibility
System PermissionsGrants general system-level privilegesProvides additional system-level privileges

6. what is the sharing rule?

Ans. A sharing rule is used to extend access to records that the organization-wide default sharing settings might restrict. It’s a way to selectively share records with specific users or groups based on predefined criteria.

7. what is the difference between with sharing and without sharing?

Aspectwith sharingwithout sharing
Data VisibilityEnforces record-level and field-level securityIgnores record-level and field-level security
User ContextUses the user’s permissions and sharing settingsRuns in system context with full data access
Impact on SharingAdheres to organization-wide defaults and sharing rulesBypasses organization-wide defaults and sharing rules
Use CasesTypically used to enforce data security in business logicUsed when sharing rules and security are not relevant
Governor LimitsOperates within the constraints of user permissionsSubject to governor limits without user context
CollaborationSuitable for scenarios where data should be protected based on user accessSuitable for administrative tasks and data operations

8. what is the wrapper class?

Ans. A wrapper class is a custom Apex class that is used to hold and manage multiple related data elements from different sources. It’s commonly used to bundle data from multiple objects or query results and pass them to Visualforce pages or Lightning components.

9. what is the batch?

Ans. A batch class in Salesforce is used to process a large number of records in smaller, manageable chunks (or batches). It’s particularly useful when you need to perform operations on a large number of records that might exceed governor limits.

10. can we call batch class from the batch class?

Ans. Yes, you can call one batch class from another batch class. This can be useful for chaining batch jobs to execute in a specific order.

11. what is the way to call batch class?

Ans. You call a batch class by creating an instance of the batch class and then invoking the Database.executeBatch() method, passing in the instance as a parameter.

12. what is the validation rule?

Ans. A validation rule is a business logic rule that you define to enforce certain data entry standards or consistency. It prevents users from entering data that doesn’t meet the specified criteria.

13. what is the record type?

Ans. A record type is a way to categorize and distinguish different types of records within an object. Each record type can have its own set of page layouts, picklist values, and business processes.

14. what is the difference between custom settings and custom metadata?

AspectCustom SettingsCustom Metadata Types
PurposeStore configuration data or application settings that can be accessed across the organization.Store configuration data or application settings that can be accessed across the organization.
Data StorageStored in Salesforce as records (sObjects) with API limits for data retrieval.Stored in Salesforce as records (sObjects) with no API limits for data retrieval.
Visibility ScopeHierarchical (org-wide, profile, user) or org-wide only.Org-wide. Custom metadata records can be accessed by all users.
Schema TypeEach custom setting has its own schema defined in Salesforce.Defined using custom metadata type definition.
Configuration ChangesCan be changed via the UI or programmatically (Apex).Can only be changed via API (Apex, API, or Metadata API).
DeploymentCan be migrated between environments using Change Sets, Packages, or Metadata API.Can be included in Change Sets, Metadata API, and other metadata deployment tools.
ProtectionCan be protected to prevent unauthorized changes.Can be protected using managed packages for controlled changes.
Record RelationshipsCustom settings cannot have direct relationships with other objects.Custom metadata records can have lookup relationships to other custom metadata types.
Apex Triggers and WorkflowCustom settings can be accessed and modified using Apex triggers and workflow rules.Custom metadata can be accessed and modified using Apex triggers, but only through Apex code.
Use CasesCommon for storing configuration settings, feature toggles, and app preferences.Common for storing configuration settings, feature configurations, and app metadata.

15. what is the use of wire in LWC?

Ans. The wire is a JavaScript decorator used in Lightning Web Components (LWC) to get data from an Apex method or a wire adapter. It helps you retrieve and refresh data in a reactive manner, automatically handling data updates when they occur.

16. what are the different types of controllers on the vf page?

Ans. In Visualforce pages, you can use three types of controllers:

  • Standard Controller: Represents a standard object, like an Account or Contact.
  • Custom Controller: A user-defined Apex class that extends the ApexPages.StandardController class.
  • Extension Controller: A user-defined Apex class that extends or enhances the functionality of a standard or custom controller.

17. what is the difference between render and rendered in vf page?

Aspectrender Attributerendered Attribute
PurposeSpecifies whether a component should be displayedSpecifies whether a component should be rendered
Attribute TypeBooleanBoolean or Expression (True/False)
Expression SupportSupports dynamic binding using controller variablesSupports dynamic binding using controller variables or formula expressions
Conditional DisplayUses the value provided to determine visibilityUses a condition to determine rendering
Interaction with CSSDirectly controls the rendering of the componentConditional rendering can affect CSS rules
Interaction with JSThe component’s existence depends on conditionThe component’s existence depends on the condition
Apex AccessCan be used directly within Visualforce markupCan be used directly within Visualforce markup
Example<apex:outputText value="Hello" render="{!showText}" /><apex:outputText value="Hello" rendered="{!showText}" />

18. what are the benefits of using vf pages?

Ans. Visualforce pages in Salesforce offer benefits such as custom user interfaces, integration with data, control over data presentation, and the ability to incorporate business logic.

19. how can we call the parent component to the child component?

Ans. Communication from a child component to a parent component in Lightning Web Components can be achieved by using events.

20. how can we pass the data from the parent to a child component?

Ans. Data is passed from a parent component to a child component in LWC through component properties (attributes).

21. what are the context variables in trigger in Salesforce?

Ans. These context variables help you determine various aspects of the trigger execution, such as the type of trigger event, the records being processed, and more. Here are some commonly used context variables in Salesforce triggers:

  1. Trigger.isBefore: This Boolean context variable is true if the trigger is executing in the “before” context, meaning before the records are saved to the database.
  2. Trigger.isAfter: This Boolean context variable is true if the trigger is executing in the “after” context, meaning after the records are saved to the database.
  3. Trigger.isInsert: This Boolean context variable is true if the trigger is executing due to an insert operation.
  4. Trigger.isUpdate: This Boolean context variable is true if the trigger is executing due to an update operation.
  5. Trigger.isDelete: This Boolean context variable is true if the trigger is executing due to a delete operation.
  6. Trigger.isUndelete: This Boolean context variable is true if the trigger is executing due to an undelete operation (recovering a deleted record).
  7. Trigger.new: This context variable holds a list of the new versions of the records being processed in the trigger. In an update trigger, this holds the updated values.
  8. Trigger.newMap: This context variable holds a map of the new versions of the records being processed, where the keys are record IDs and the values are the record objects.
  9. Trigger.old: This context variable holds a list of the old versions of the records being processed in the trigger. In an update trigger, this holds the values before the update.
  10. Trigger.oldMap: This context variable holds a map of the old versions of the records being processed, where the keys are record IDs and the values are the old record objects.
  11. Trigger.size: This context variable holds the total number of records in the trigger context. It’s a count of the records in Trigger.new or Trigger.newMap.
  12. Trigger.operationType: This context variable provides the type of operation that caused the trigger to fire. It can have values like 'INSERT', 'UPDATE', 'DELETE', 'UNDELETE', etc.

22. why we use Test.StartTest() and Test.StopTest()?

Ans. In Salesforce, Test.StartTest() and Test.StopTest() are methods used in unit tests. They are used to define a block of code that is separate from the rest of the test context. The key purpose of these methods is to reset governor limits. Salesforce enforces certain limits on DML operations, SOQL queries, and more. Wrapping code between Test.StartTest() and Test.StopTest() allows you to reset the limits specifically for that block of code, enabling you to test the impact of your logic without being constrained by the governor limits.

23. What is the purpose of @future Annotation?

Ans. The @future annotation is used in Salesforce Apex to indicate that a method should be executed asynchronously in the background. It allows you to offload long-running or potentially resource-intensive operations to avoid impacting the immediate user experience.

Methods annotated with @future are processed in a separate context and have their own governor limits.

24. What is the mixed DML error?

Ans. The “Mixed DML Operation” error occurs in Salesforce when you try to perform a transaction that involves a mix of both setup (metadata) objects and non-setup (standard/custom) objects in a single context.

This usually happens when you perform DML operations on both types of objects within the same transaction, and Salesforce enforces a restriction to prevent certain types of mixed operations due to potential security concerns.

25. How can resolve the mixed dml error?

Ans. To resolve the mixed DML error, you need to ensure that DML operations on setup objects and non-setup objects are separated into different transactions. Here are a few approaches:

  • Use Future Methods or Queueable Jobs: You can use @future annotated methods or Queueable Apex to move the DML operations on setup objects to a separate asynchronous context.
  • Use Asynchronous Apex: If possible, move one set of DML operations to an asynchronous context using methods like Queueable or Batch Apex.

26. Write a Query to get all the accounts records that have at least one contact record.

SELECT Id, Name
FROM Account
WHERE Id IN (SELECT AccountId FROM Contact)

27. What is the Cross-object formula field?

Ans. A Cross-Object Formula Field is a calculated field in Salesforce that allows you to reference and perform calculations on fields from related (parent or child) objects. It enables you to display data from related records without having to create custom code. This is particularly useful when you want to display information from a related object on a record’s detail page.

For example, you might have a custom object called “Invoice” and another standard object called “Account.” You could create a Cross-Object Formula Field on the Invoice object that references fields from the related Account object, such as the Account’s Industry field. This way, each Invoice record could display the Industry of its associated Account.

28. What is the SOQL Query?

Ans. SOQL stands for “Salesforce Object Query Language.” It’s a query language used to search your organization’s Salesforce data for specific information. SOQL is similar to SQL (Structured Query Language), but it’s designed specifically for querying Salesforce objects and their relationships.

SOQL queries allow you to retrieve records based on conditions, perform aggregate functions (like SUM, COUNT, etc.), and navigate through object relationships. You can use SOQL in various contexts, including Apex code, Visualforce pages, and API calls.

29. what is the difference between the cross-object formula field and the roll-up summary field?

AspectCross-Object Formula FieldRoll-Up Summary Field
PurposeDisplay calculated data on a record and child objectsDisplay aggregated data on a parent and child objects
Calculation TypeCalculations on related object fieldsAggregations (SUM, COUNT, AVG, etc.)
Data Display LocationOn the record being viewedOn the parent record
Related Object RelationshipRequires a master detail or lookupRequires a master detail or lookup and child objects
Supported OperationsSupports various operations such as arithmetic, concatenation, etc.Supports aggregations like SUM,COUNT, AVG, MIN, MAX, etc.
Example Use CaseDisplay Account Industry on an Invoice recordDisplay total Opportunity amounts on an Account record

30. is it possible to invoke one controller method from another in aura component?

Ans. Yes, you can definitely invoke one controller method from another in a Salesforce Lightning Aura Component. Aura Components are part of the Salesforce Lightning Framework, which allows you to build dynamic web applications for Salesforce.

In Aura Components, you can call a controller method from another method within the same controller, as long as they are part of the same Aura Component. This is a common practice to organize your component’s logic and improve code reuse.

Here’s a simple example in Aura Component:

({
    doMethodA: function(component, event, helper) {
        console.log('Executing Method A');
        helper.doMethodB(component); // Invoking helper method from another helper method
    }
})

Conclusion

I hope you like this blog and if you want any help let me know in the comment section.

Stay tuned, there is way more to come! Follow me on LinkedIn, Instagram, Twitter, Trailhead. So you won’t miss out on all future articles.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

NetSuite Salesforce Integration: An Automation Guide

NetSuite Salesforce Integration is the seamless connection between NetSuite, a leading cloud-based Enterprise Resource Planning (ERP) system, and Salesforce, a premier Customer Relationship Management (CRM) platform.