You need to sign in to do that
Don't have an account?
3421
update outside the loop
I have a Batch Class where I am looking for Contact matches to Account and would like to update Contact with associating Account.
How do I write update outside the loop? I want to update the Account in the map to the contact from initial loop
Here is the code
How do I write update outside the loop? I want to update the Account in the map to the contact from initial loop
Here is the code
Set<String> emailDomains = new Set<String>(); Set<String> emailDomains001 = new Set<String>(); Set<Id> ctId = new Set<Id>(); List<Contact> ctlist = [select Id, FirstName,LastName,Email,Business_Name__c,Member_Type__c from Contact where Email <> null and LastModifiedDate = N_DAYS_AGO:5]; for (Contact ct : ctlist){ if(ct.Type__c == 'Test'){ ct.AccountId = '0015467Dvbg'; update ct; } else if(ct.Account.Name == ct.Name__c && ct.Type__c <> 'Test'){ emailDomains.add(ct.Email.split('@').get(1)); } else if (ct.Account.Name <> ct.Name__c && ct.Type__c <> 'Test' ){ emailDomains001.add(ct.Email.split('@').get(1)); } Map<String,Account> emailDomainToAccountMap = new Map<String,Account>(); List<Account> acclist = [select Id, Name,Domain__c from Account where Domain__c <> null and Domain__c IN :emailDomains]; List<Account> acclist1 = [select Id, Name,Domain__c from Account where Domain__c <> null and Domain__c IN :emailDomains001]; if(!emailDomains.isEmpty() && (!emailDomains.contains('gmail.com') || !emailDomains.contains('yahoo.com') || !emailDomains.contains('outlook.com') || !emailDomains.contains('hotmail.com'))){ for (Account a : acclist){ emailDomainToAccountMap.put(a.Domain__c,a); } } }
The emaildomains in contacts are mapped with emailDomainToAccountMap, but where are we updating that contact with Account? I mean in the second else if conditions and third else if condition, I was not sure how to map that with the Account retreived through map
if(conUpdate.size()>0){
}