You need to sign in to do that
Don't have an account?

Trigger to Update field on Account on Insert/Update of Contact Role
I think the title explains it - i am looking for some help writing a trigger that updates a specified field on the account record when we have a Contact Role that of a specific role and is primary. thanks.
Hey JAW99
The help and documentation are a great place to get started for this. What you want to do is add a trigger to contact for after insert and after update that will update the account.
If you want something more specific then PM me and I will help as far as I can.
Paul
Hey JAW99
The sort of thing you will be wanting then is something like this:
That's only the sort of very bare bones of it but it should get you started. You can add triggers through the UI (Setup -> Develop -> Triggers) or use the Eclipse plugin to develop a new trigger.
I hope that helps a bit, if you need more detail please list specific fields and actions.
Paul
Try the following code:
trigger updateAccount on Contact(after insert, after update){
public Id cId;
public Id aId;
List<CaseContactRole> ccr = [select Id,ContactId, Role from CaseContactRole where ContactId IN :Trigger.New.Id];
for(CaseContactRole cRole : ccr){
if(cRole.Role==<replace the role you wish to compare>){
cId = cRole.ContactId;
}
}
for(Contact c : [select accountId from contact where id = :cId]){
aId = c.AccountId;
}
for(Account acc : [select Id from Account where id=:aId]){
acc.<field name you wish to update> = <updated value>;
update acc;
}
Let me know if you face any difficulty................