You need to sign in to do that
Don't have an account?
sibil joe
how to avoid query inside a loop in trigger?
public static void setAccount(List<Account> newList){
List<Account> pirList = new List<Account>();
List<Account> p1 = new List<Account>();
for(Account newAcc: newList){
if(newAcc.RecordTypeId == pirRecId){
p1.add(newAcc);
p1 = [SELECT id,FirstName,LastName,MiddleName
FROM Account
WHERE
FirstName =: newAcc.FirstName AND
LastName =: newAcc.LastName AND
MiddleName =: newAcc.MiddleName ];
for(Account patient:p1){
patient.lookup = newAcc.Id;
}
update p1;
}
}
}
This function is called from a trigger in after insert
List<Account> pirList = new List<Account>();
List<Account> p1 = new List<Account>();
for(Account newAcc: newList){
if(newAcc.RecordTypeId == pirRecId){
p1.add(newAcc);
p1 = [SELECT id,FirstName,LastName,MiddleName
FROM Account
WHERE
FirstName =: newAcc.FirstName AND
LastName =: newAcc.LastName AND
MiddleName =: newAcc.MiddleName ];
for(Account patient:p1){
patient.lookup = newAcc.Id;
}
update p1;
}
}
}
This function is called from a trigger in after insert
Please try with below code.
If this helps, plese mark it as best answer.
Regards,
Ankaiah Bandi
Thank you for your response!
However, given that p1 is a list, how is it possible to use p1.FirstName?
Thank you,
Sibil