You need to sign in to do that
Don't have an account?
Sandhya K 10
Update Account field with active contact
I have Created a field email__c on Account and I want to update Update this with the contact that is Active (Active__c checkbox on Contact)
When contact status is active, then I want to deactivate all related account contacts and update active contact email on account email filed . How do I achieve this. I am not knowing how do I deactivate the remaining contacts if the current contact is Active. Please guide me in SOlving this
When contact status is active, then I want to deactivate all related account contacts and update active contact email on account email filed . How do I achieve this. I am not knowing how do I deactivate the remaining contacts if the current contact is Active. Please guide me in SOlving this
public class updateAccwithActiveContactEmail { public Static void updateAccountwithActiveContact(List<Contact> newconlist){ List<Account> accToUpdate = new List<Account>(); List<Contact> conToUpdate = new List<Contact>(); Set<Id> accIdSet = new Set<Id>(); for(Contact c : newconlist){ accIdSet.add(c.AccountId); } system.debug(accIdSet); List<Account> accWithConlist = [Select Id,Email__c,(Select Id,Active__c,Email,AccountId from Contacts) from Account Where Id IN : accIdSet]; List<Contact> conlist = accWithConlist[0].Contacts; system.debug(accWithConlist); system.debug(conlist); system.debug(newconlist); for(Contact c : newconlist){ for(Account a : accWithConlist ){ for(Contact con :conlist ){ // if(c.Id == con.Id && c.Active__c == true){ if(c.Id != con.Id ){ con.Active__c = False ; con.Account.Email__c = c.Email; } // accToUpdate.add(a); conToUpdate.add(con); // system.debug(accToUpdate); system.debug(conToUpdate); } // update accToUpdate; } } } }
Try this:
-Thanks,
TK
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Try this:
-Thanks,
TK
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
With few changes I am able to get it done.The change that I made is , In line 19 Kept Active__c = true as got what I needed. Thank you.