You need to sign in to do that
Don't have an account?
Akansha Yadav 3
Help in optimizing the code
List<Account> accs = [SELECT Id, Is_Paid__c FROM Account WHERE PersonContactId=:conIds];
if(accs!=null && !accs.IsEmpty())
{
for(Account acc : accs)
{
acc.Is_Paid__c = true;
}
if (accs!=null && !accs.IsEmpty())
{
update accs;
}
}
if(accs!=null && !accs.IsEmpty())
{
for(Account acc : accs)
{
acc.Is_Paid__c = true;
}
if (accs!=null && !accs.IsEmpty())
{
update accs;
}
}
Try this code:
for(Account acc : [SELECT Id, Is_Paid__c FROM Account WHERE PersonContactId=:conIds]){
if (acc.FIELD !=null){
acc.Is_Paid__c = true;
update acc;
}
}
Best Regards
Rafael
If you need check if exist some register that have relationship with "conIds", you don't need check if is null or not.
Below is the optimized code.
Here is an approach to make above update:
This is a good approach to use SOQL query in for loop. Second thing, you just need a size check of list before updating the records. Please let me know if it helps.
Thanks,
Anjita