Salesforce Technical Questions with Answers -2

  • SF Technical Questions answers 2

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:

  1. Write code with the help of collections so that for every record you do not need to write a separate query or separate DML
  2. 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.
  3. Never write DML in any loop.
  4. Never write SOQL in any loop.
  5. Never write SOSL in any loop.
  6. Use @Future annotation to bypass Governor limit errors.
  7. Write such a code that will be taking limited utilization of resources

pic

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.

Satish is a certified Project Management Professional and Salesforce Admin. He is working as a Business Analyst and has immense interest in Product configuration, Automation, and Project delivery. You can connect with him on LinkedIn and Trailhead.

By |2023-01-11T16:29:15+00:00January 11th, 2023|Comments Off on Salesforce Technical Questions with Answers -2