You need to sign in to do that
Don't have an account?
Alex Waddell 18
Running into SOQL Query limit 101 when importing data using data loader
I am running into an error when mass creating assessments using dataloader.
I have a feeling that I running 3 queries inside of the For() is the cause of my issue. Can someone help me rework this code to avoid these issues moving forward?
I have a feeling that I running 3 queries inside of the For() is the cause of my issue. Can someone help me rework this code to avoid these issues moving forward?
trigger closeCaseOnIcmDischarge on Patient_Ass__c (After insert) { for(Patient_ass__c pAss : trigger.new){ Patient_Assessment_View__c pView = [Select id,Account__c From Patient_Assessment_View__C Where id = :pAss.Patient_Assessment_View__c]; List <Case> c = [Select id, Discharge_Reason__c, Discharge_Date__c, Accountid From Case Where status IN('New','On Service') AND RecordTypeId = '01236000000OJLq' And Accountid = :Pview.Account__c Limit 1]; List <TeleWell_Care_Plan__c> TW = [Select id,Use_Question_1__c From Telewell_Care_Plan__c Where Patient_Assessment_and_Care_Plan__c = :Pview.id LIMIT 1] ; if(c.size() > 0 && pAss.RecordTypeId == '01236000000nufHAAQ'){ c.get(0).status ='Closed'; c.get(0).Discharge_Reason__c = pAss.Discharge_Reason__c; c.get(0).Discharge_Date__c = System.today(); Update c; TW.get(0).Use_question_1__c = 'No'; Update TW; } Else{ } } }
Its a little complex, but basically you need to get the record Lists using the Ids. Basically, loop the records, get the Ids, do a query (outside the loop) using Ids IN :listOfIds, then loop that list to create another list of Ids, and do the next query, outside the loop.
The following is uncompiled and not tested, but I think it should get you on the correct path:
Note that also you were doing DML events inside the Loops also, which would also breach the governor limits. For those, add the records to be updated to a list of records, and then update that entire list in one call outside the loop.
Regards
Andrew
All Answers
Its a little complex, but basically you need to get the record Lists using the Ids. Basically, loop the records, get the Ids, do a query (outside the loop) using Ids IN :listOfIds, then loop that list to create another list of Ids, and do the next query, outside the loop.
The following is uncompiled and not tested, but I think it should get you on the correct path:
Note that also you were doing DML events inside the Loops also, which would also breach the governor limits. For those, add the records to be updated to a list of records, and then update that entire list in one call outside the loop.
Regards
Andrew