Category: Governor Limit

“Bulkify Your Code” – Another Example with Use Case

This post is the continuation of my previous post”Bulkify Your Code” – Explanation of Salesforce’ Governor Limit with Use CaseUse Case -I have two custom objects (Airport__c and Country__c). Below screenshot will give you field details.My requirement is to make sure when I am inserting an Airport record, I need to check whether the country mentioned in the record is already present in the Country object, if not, then create a new Country record with name same as mentioned in the Airport’s Country field provided that Aiport is operational i.e. Operational__c == true.Solution -Initially it may look like the requirement is very easy to implement. But we need to keep in mind the Salesforce’s Governor Limit.If we go ahead with the approach of iterating over each new Airport record and then do a query against Country object to check whether that country is already there in the system, we will quickly hit Salesforce’s Governor Limit – “Total number of SOQL Issued – 100 (Synchronized) and 200 (Asynchronized)”.So we need to make sure that our code is efficient. Below is the optimized trigger which can handle the requirement and at the same time will make sure that we will not hit by Governor limit.trigger AirportTrigger on Airport__c (after insert) { List<Country__c> allCountries = new List<Country__c>(); List<String> allCountryNames = new List<String>(); //Fetch all Country Name and put it into a list...

Read More

“Bulkify Your Code” – Explanation of Salesforce’ Governor Limit with Use Case

“Bulkify Your Code” – I am quite sure you have heard this phrase a lot, but do you really know what is the meaning of this phrase and why this one is so important?This post is all about “Bulkify Your Code” where I will explain –What is the meaning of this phrase?Why this is so important?Explain with Use CasesSo let’s start with What is the meaning of “Bulkify Your Code” –If you want to combine repetitive tasks in your Apex classes/Triggers, you need to bulkify your code. For example – if you are given a task to check whether a student’s score is greater than 80, you can’t write a code which can check score of single student. Rather your code should check score of n number of students. So it means you need to repeat the same task of checking score for n number of students in your apex code and that is what called “Bulkify Your Code”So now definitely the question that came to your mind – Why “Bulkify Your Code” is so important?To explain the important, let me give you a real-life example. Say for example, you are staying in an apartment where along with your family, 100 other families are also staying. Each of these families (including your definitely) need water, right? To fulfil this requirement, what the owner will do is that he/she will...

Read More

Earlier Posts

  • 2024 (28)
  • 2023 (47)
  • 2022 (25)
  • 2021 (35)
  • 2020 (41)
  • 2019 (13)
  • 2018 (16)
  • 2017 (14)
  • 2016 (18)
  • 2015 (74)
  • 2014 (20)