You need to sign in to do that
Don't have an account?
Abhishek Singh 88
how to take SOQL query out of for loop.
Hi All,
I have query in for loop.I tried it to pull out side but it is not behaving properly. It is not updating respective record properly if take query out of loop.here is my code.
baseapplist is inside for loop. Want to keep outside of loop.
Thanks.
I have query in for loop.I tried it to pull out side but it is not behaving properly. It is not updating respective record properly if take query out of loop.here is my code.
for(BMCServiceDesk__BMC_BaseElement__c berec:childCis) { for(BMCServiceDesk__BMC_BaseRelationship__c brrec:sourcedestinationlist) { if(brrec.BMCServiceDesk__Destination_ClassName__c=='BMC_Application') besourceid.add(brrec.BMCServiceDesk__Destination__c); } baseapplist=[select id,name,HITRUST__c,PCI__c,PHI__c,Fisma_High_New__c,Fisma_Low_New__c,Fisma_Mod_New__c,SOC__c,SOC2__c,SOX__c,Environment__c,UAR__c,BMCServiceDesk__ClassName__c from BMCServiceDesk__BMC_BaseElement__c where ID IN:besourceid]; for(BMCServiceDesk__BMC_BaseElement__c baseapp:baseapplist) { if(baseapp.HITRUST__c) flag1=true; } for(BMCServiceDesk__BMC_BaseElement__c basebe:newbelist1) { if(oldbelist1.get(basebe.id).HITRUST__c!=basebe.HITRUST__c && basebe.HITRUST__c==false) { if(flag1) { berec.HITRUST__c=true; } else{ berec.HITRUST__c=false; } baseelementlist.add(berec); }}}
baseapplist is inside for loop. Want to keep outside of loop.
Thanks.
Please try the given below code with the help of this, you can solve your problem, it may be helpful to you.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
All Answers
It also looks like you only pasted a portion of the code here. It's really difficult to interpret why there are so many loops using the same BMCServiceDesk__BMC_BaseElement__c object. Furthermore, it's hard to provide an adequate replacement for the supplied snippet. Here's a start to get your ideas flowing:
Good luck.
-greg
Please try the given below code with the help of this, you can solve your problem, it may be helpful to you.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
Thanks.