You need to sign in to do that
Don't have an account?
Mohd Nabeel
UpdateContact: execution of AfterInsert caused by: System.SObjectException: Invalid field Account Id for AggregateResult Class.AccountContact.updateCheckBox: line 22, column 1 Trigger.UpdateContact: line 3, column 1
Hi,
I am trying to create an account and when the account is created a contact will be created and the checkbox should be true..
i have created an account but the checkbox remainis false and when i am again trying to create a new contact i am getting this error... UpdateContact: execution of AfterInsert caused by: System.SObjectException: Invalid field Account Id for AggregateResult Class.AccountContact.updateCheckBox: line 22, column 1 Trigger.UpdateContact: line 3, column 1
public class AccountContact{ public static void onBefore(List<Account> acctList){ List<Contact> conList = new List<Contact>(); for(Account acc: acctList){ Contact con = new Contact(AccountId = acc.ID); con.FirstName = 'Info'; con.LastName = 'Default'; con.Email = 'info@websitedomain.tld'; acc.OnlyDefaultContact__c = TRUE; conList.add(con); } insert conList; } public static void updateCheckBox(List<Contact> contList){ Set<id> accountIds = new Set<id>(); for(Contact con: contList){ accountIds.add(con.Accountid); } List<Account> updateAccount = new List<Account>(); for(AggregateResult ar: [Select count(id), AccountId from Contact where AccountId IN : accountids group by AccountId having count(id)>1]){ updateAccount.add(new Account(id = (id)ar.get('Account Id'),OnlyDefaultContact__c = FALSE)); } } } //trigger trigger InsertContact on Account (after insert) { if(Trigger.isBefore && Trigger.isInsert){ AccountContact.onBefore(Trigger.new); } } trigger UpdateContact on Contact (after insert) { if(Trigger.isInsert && Trigger.isAfter){ AccountContact.updateCheckBox(Trigger.new); } }
Hi Mohd,
I have gone through your problem please refer bellow code:-
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
All Answers
Please refer below code it works correctly:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Actually i am new to salesforce thats why little bit confused in these things..
Your help will be highly appreciable..
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Hi Mohd,
I have gone through your problem please refer bellow code:-
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com