Skip to content

Instantly share code, notes, and snippets.

@karanrajs
Last active October 8, 2015 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karanrajs/7d231386e20d357884dc to your computer and use it in GitHub Desktop.
Save karanrajs/7d231386e20d357884dc to your computer and use it in GitHub Desktop.
trigger efficientSOQL on Invoice_Statement__c(before insert,before update)
{
//perform SOQL query outside the for loop
//This query runs once for all item in the Trigger.New
for(Invoice_statement__c inv : [Select Id,Description__c,(select Id,Units_Sold__c from Line_Item__r) From Invoice_Statement__c where Id IN : Trigger.newMap.KeySet()])
{
for(Line_Item__c li:inv.LineItem__r)
{
//do any operation
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment