You need to sign in to do that
Don't have an account?

Too many SOQL Queries 101
Hey Yall,
How could I adjust the trigger code below and move the SOQL Query from inside the FOR loop?
How could I adjust the trigger code below and move the SOQL Query from inside the FOR loop?
trigger OLISyncQLIFields on OpportunityLineItem (before insert,before update) { date vServiceEnd; date vServiceStart; string vQuoteId; string vPricebookEntryId; string vOpportunity; for(OpportunityLineItem oppLine : Trigger.new){ vQuoteId = oppLine.QuoteId__c; vPricebookEntryId = oppLine.PricebookEntryId; for(QuoteLineItem quoteLine : [select Id, Service_Start__c, Service_End__c from QuoteLineItem where (QuoteId = :vQuoteId and PricebookEntryId = :vPricebookEntryId)]){ vServiceEnd = quoteline.Service_End__c; VServiceStart = quoteline.Service_Start__c; } oppLine.ServiceEndDate__c = vServiceEnd; oppLine.ServiceStartDate__c = vServiceStart; } }
Check the apex best practice documention here https://developer.salesforce.com/page/Apex_Code_Best_Practices