You need to sign in to do that
Don't have an account?
Lalit Dhupar 13
update custom field on account with contact name with trigger
Hello,
i am new to salesforce and I have a custom field on account as Consecutive_Contacts_Name__c. Whenever a new contact is inserted the field should have value of the contact first name if Consecutive_Contacts_Name__c =null on account. if Consecutive_Contacts_Name__c != null it should have the previous value +',' + recent contact first name. Below is my code but it is not working properly. Could anyone please help on the same.
rigger ContactOnAccount on Contact (after insert) {
List<Account> accList = new List<Account>();
for (Contact con:[select FirstName, Account.Consecutive_Contacts_Name__c, Account.Id from Contact where id in:trigger.new])
{
Account acc = new Account(id=con.Account.id);
acclist.add(acc);
if(acc.Consecutive_Contacts_Name__c == '' && acc.Consecutive_Contacts_Name__c == Null)
{
acc.Consecutive_Contacts_Name__c = con.FirstName;
update acclist;
}
else{
acc.Consecutive_Contacts_Name__c = acc.Consecutive_Contacts_Name__c + ',' + Con.FirstName;
update acclist;
}
}
}
i am new to salesforce and I have a custom field on account as Consecutive_Contacts_Name__c. Whenever a new contact is inserted the field should have value of the contact first name if Consecutive_Contacts_Name__c =null on account. if Consecutive_Contacts_Name__c != null it should have the previous value +',' + recent contact first name. Below is my code but it is not working properly. Could anyone please help on the same.
rigger ContactOnAccount on Contact (after insert) {
List<Account> accList = new List<Account>();
for (Contact con:[select FirstName, Account.Consecutive_Contacts_Name__c, Account.Id from Contact where id in:trigger.new])
{
Account acc = new Account(id=con.Account.id);
acclist.add(acc);
if(acc.Consecutive_Contacts_Name__c == '' && acc.Consecutive_Contacts_Name__c == Null)
{
acc.Consecutive_Contacts_Name__c = con.FirstName;
update acclist;
}
else{
acc.Consecutive_Contacts_Name__c = acc.Consecutive_Contacts_Name__c + ',' + Con.FirstName;
update acclist;
}
}
}
Hi Lalit,
try this codeIt will if any issue comes in above solutions
Thanks:)
All Answers
Please update line:
Hope this works, else we need to query on Account and update accordingly.
Thanks,
Gaurav
Skype: gaurav62990
try the below code. Let us know if you still have the problem.
Hi Lalit,
try this codeIt will if any issue comes in above solutions
Thanks:)