When we are running the below batch getting:
Too many SOQL queries: 201 Error.
What are some steps I can take to avoid this error?
Batch: Will post the code.Sorry for the deletion
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
Sorry to say I didn't read the whole code (too long), but with a quick glance I found this query inside a
for(Opportunity opp : newOppListfromOpp) loop:
assetsList = [Select id,ParentId,Service_Contract__c,type__c,GlobalCare_Level__c,Asset_Value__c,smart_part_number__c from Asset where AccountId in :accList and GlobalCare_Level__c!='None' and GlobalCare_Level__c!='' and Type_of_Key__c != 'Demo' and Status = 'Active'];
You should never have SOQL queries inside loops. Fix that one and look for other occurrences, that is very much likely to be the cause of your Exception. The alternative is to make that query outside of a loop only once, and you can make a
Map<Id, SObject> to map the queried objects and be able access them inside the loop later, instead of making the query there.