In this series of blogs and articles, Cloudely experts present you the Salesforce interview questions and answers, real-time scenarios, use cases, errors, turnarounds, answers to our reader’s queries and more. We hope you will find it helpful.
Question #1: What is  Bulkification(Apex/Triggers)?
Bulkification means the code we write must work on one as well as many(bulk) records. In other words, the code needs to be written in such a way that it should run in case of single or 1000’s of records.
- We must avoid using index values like Trigger.New[0], as we never know how many records we may get in Trigger.new at runtime.
- Use for each loop in case of 1 record or many reocrds. In other words, the business logic which we write for single record, the same should be written for these multiple records using for loop. In this loop, we need to process one by one all records from the collection and implement business logic on it.
- No usage of SOQL inside for loop.
- No usage of SOSL inside for loop.
- No usage of DML inside for loop.
- Store the data in collections so that the code will get executed for single as well as multiple records.
- We must always try to perform actions like DML, SOQL etc with bulk records rather than single record.
Example:
insert p1; ==> WRONG
insert PenList; ==> RIGHT
Note: Bulkification and Governor limit concepts run hand in hand with real time projects.
Suggested Reading: Salesforce Interview Questions Series 1
Question #2: Can you please explain about Governor Limit(s)?
As Salesforce Apex works in shared server format, meaning “multi-tenant architecture”, Salesforce wants the resources not to be over utilized by any client (tenant). Hence we have these stringent rules for any company using Salesforce software. If a particular Apex code exceeds any Governor Limit, run time exceptions will be displayed by Salesforce and the user has to rectify the code for bypassing the Governor Limits.
Ideal ways to ensure the code does not hit Governor Limits:
- Write code with the help of collections so that for every record you do not need to write a separate query or separate DML
- Reduce the count of queries and try to fetch all needed data in the same query rather than calling again and again from the database.
- Never write DML in any loop.
- Never write SOQL in any loop.
- Never write SOSL in any loop.
- Use @Future annotation to bypass Governor limit errors.
- Write such a code that will be taking limited utilization of resources
Question #3: What is the difference between Public Group/s and Queue?
Ownership:
- Public Group never changes owner, the same person remains owner even after Sharing.
- Queue, we use for ownership change.
Object access:
- Public Group can work on all objects.
- Queue can work on only mentioned objects.
Scope in projects:
- Public Group can be used to share a record with a large number of users easily. (by Manual Sharing/Sharing Rule)
- Queue is used in Lead management(for load balancing in business) and also in the Approval process .
Delete Access:
- Users in Public Group cannot delete record (Public Group gives only Read and E)
- Users in Queue can delete the records.
Think Salesforce, Think Cloudely
At Cloudely, we deliver everything Salesforce. Implementations, Support, Managed Services, Training and Staffing – Think Cloudely for your Salesforce A-Z requirements.
Explore our online Salesforce training programs.
Found this article informative? Share this article.
Looking for expert answers to Salesforce questions? Send them to salesforce@cloudely.com. Our Salesforce experts will answer your queries.