function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
David81David81 

Working with Primary Contact in Account Contact Roles

I'm afraid the answer is a big fat "No", but maybe I'm wrong.

 

Can I really do anything when a Contact is marked as Primary in the Contact Roles list on the Account?

 

e.g. - I want to pull a field from said Contact into the Account record. Obviously, a formula field would be ideal, but a trigger would probably get the job done if need be. It seems I can't create a trigger on the AccountContactRole object and I don't have the nice lookup option in a formula field on the Account object to get data from the designated Primary Contact.

 

It would make sense that I should be able to do something with that relationship, but I'm just drawing a blank here.

EnthEnth

A workaround would be to add a custom field of Primary Contact as a lookup to Contact on the Account record. Some users find the Contact Roles annoying and I've used this to get round the same issue before, without having to resort to code (coz you can just formula field the rest).

 

If you can insert into AccountContactRoles, and you could have your trigger automatically create the primary contact for you, if you want to maintain/use both. 

David81David81
I had thought about just setting a custom lookup field called Primary Contact when a Contact Role marked as Primary is created, but it doesn't seem possible to write a trigger that fires on insert or update of AccountContactRoles.  Am I missing something?
David81David81
Is there no way to set off a trigger or other action through ContactRoles?
EnthEnth

Sorry, no other way I know of. As you've found, the AccountContactRole object does not appear in the list of objects when you create a trigger or a workflow.

 

I suppose if you don't like the Primary Contact Lookup on the Account idea (more below), then your other option is to use scheduled Apex to execute and check records created in AccountContactRole since the last time it ran...?

 

Just re-read the thread, not sure my idea got across. Previously I've done the following:

  1. Add a lookup custom field to account, called Primary Contact
  2. Write a trigger before/after insert/update of Account to see if the primary contact has been changed. You can also include here your real requirement for populating your Account record with details from the primary contact.
  3. Write a class with a method to createPrimaryContact. When passed the PrimaryContact__c old and new values it should check if the AccountContactRole exists and update it, or create a new one.
  4. Write a unit test method for your method above, and test it.
  5. Finally hook up your trigger with your new method, passing the required Lists from the trigger.old and trigger.new.

HTH.

Message Edited by Enth on 03-19-2010 12:19 PM
Message Edited by Enth on 03-19-2010 12:22 PM