You need to sign in to do that
Don't have an account?
Ryan Mason 5
I need to take this SOQL query out of my for loop. I've been researching using the Map method but honestly stuck when it comes to applying the logic to what I have:
for (Lead newLead : newLeadList)
{
system.debug('here ryan');
Id referringAccount = newLead.Referring_Account__c;
Account accountPulls = [SELECT Account_Pulls_Medication_History__c FROM Account WHERE Id =: referringAccount];
system.debug('here ryan'+accountPulls);
if (accountPulls.Account_Pulls_Medication_History__c)
{
system.debug('here ryan2');
if(newLead.Medication_History_Pull__c == null)
{
newLead.Medication_History_Pull__c = 'Pending';
system.debug('here ryan3');
}
}
}
Any help would be much appreciated
Take SOQL out of For loop
I need to take this SOQL query out of my for loop. I've been researching using the Map method but honestly stuck when it comes to applying the logic to what I have:
for (Lead newLead : newLeadList)
{
system.debug('here ryan');
Id referringAccount = newLead.Referring_Account__c;
Account accountPulls = [SELECT Account_Pulls_Medication_History__c FROM Account WHERE Id =: referringAccount];
system.debug('here ryan'+accountPulls);
if (accountPulls.Account_Pulls_Medication_History__c)
{
system.debug('here ryan2');
if(newLead.Medication_History_Pull__c == null)
{
newLead.Medication_History_Pull__c = 'Pending';
system.debug('here ryan3');
}
}
}
Any help would be much appreciated
get Account Ids
do Select statement for accounts
build a map of the accounts
Loop the list
check the map
update lead as required.
so:
The above code is supplied uncompiled, but should be close to what you need
regards
Andrew
All Answers
get Account Ids
do Select statement for accounts
build a map of the accounts
Loop the list
check the map
update lead as required.
so:
The above code is supplied uncompiled, but should be close to what you need
regards
Andrew