You need to sign in to do that
Don't have an account?
Rahul Allada
How do I bulkify this code and avoid SOQL query inside for loop?
How to bulkify this code? And avoid Query inside for loop
trigger dummyTrigger on Case (before insert){ if(trigger.isBefore && trigger.isInsert){ List<case> ca = new List<case>(); system.debug('Inside trigger'); for( case c: trigger.new){ if(c.Service_Type__c == 'Apply Service' && c.entitlementid==null && c.AssetId!=null) { system.debug('Inside If-'); List<servicecontract> servCon=new List<servicecontract>([select id from servicecontract where AccountId=:c.AccountId and Asset__c=:c.AssetId and sla__c=null and startdate!=null]); Entitlement ent; if(servCon.size()>0) { ent = [select id from entitlement where accountid=:c.AccountId and servicecontractid=:servCon[0].id and AssetId=:c.AssetId]; } c.entitlementid = ent.id; c.servicecontractid = servCon[0].id; } } } }
How do I bulkify this code and avoid SOQL query inside for loop?
> https://salesforce.stackexchange.com/questions/47469/general-trigger-bulkification-best-practices
The above link has general best practices that you can follow to bulkify your trigger implementation.
Let me know if it helps you and close your query by marking it as the best answer so that it can help others in the future.
Thanks.
Please try like below:
If there is syntax error is coming please fix because i have typed in Notepad++ also read the code first to understand.
Put debug logs also wherever you want to test.
Thanks,
Maharajan.C