You need to sign in to do that
Don't have an account?
ankush
To Avoid soql queries inside for loops
Can some one please help me how to avoid soql queries inside for loop. The below code working fine. Same functionality to work without soql queries iside for loop. Stuck on this.
if(trigger.isbefore && trigger.isdelete)
{
list<COI_Expertise__c> coilist=new list<COI_Expertise__c>();
list<panel_assignment__c> lp=[select Reviewer_Name__c,Panel__c,Active__c from panel_assignment__C where id=:Trigger.old];
system.debug('The list is' + lp);
for(panel_assignment__c l:lp){
Id ReviewerId=l.Reviewer_Name__c;
Id PanelId=l.Panel__c;
list<Research_Application__c> r=[select id from Research_Application__c where Panel__c=:panelId];
for(Research_Application__c ra:r){
Id rschappId=ra.Id;
list<COI_Expertise__c> ci=[Select id,Reviewer_Name__c from COI_Expertise__c where Research_Application__c=:rschappId];
for(COI_Expertise__c ce:ci){
if(ReviewerId==ce.Reviewer_Name__c)
ce.Active__c=false;
coilist.add(ce);
}
}
}
update coilist;
}
if(trigger.isbefore && trigger.isdelete)
{
list<COI_Expertise__c> coilist=new list<COI_Expertise__c>();
list<panel_assignment__c> lp=[select Reviewer_Name__c,Panel__c,Active__c from panel_assignment__C where id=:Trigger.old];
system.debug('The list is' + lp);
for(panel_assignment__c l:lp){
Id ReviewerId=l.Reviewer_Name__c;
Id PanelId=l.Panel__c;
list<Research_Application__c> r=[select id from Research_Application__c where Panel__c=:panelId];
for(Research_Application__c ra:r){
Id rschappId=ra.Id;
list<COI_Expertise__c> ci=[Select id,Reviewer_Name__c from COI_Expertise__c where Research_Application__c=:rschappId];
for(COI_Expertise__c ce:ci){
if(ReviewerId==ce.Reviewer_Name__c)
ce.Active__c=false;
coilist.add(ce);
}
}
}
update coilist;
}
Try the code below:
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
All Answers
Try the code below:
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
When you are deleting a record you only have Trigger.old available so you cannot compare it. If it was an insert or update it would be like the code below:
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.