You need to sign in to do that
Don't have an account?
Ram_SF14
How to create a AccountContactRole using trigger ?
Hi All
I am newbie to Salesforce. I was wondering if anyone can help me ?
How to create a AccountContactRole using trigger ? (When Account and its corresponding Contact is created that contact should become AccountContactRole)
Your help is much appreciated
I am newbie to Salesforce. I was wondering if anyone can help me ?
How to create a AccountContactRole using trigger ? (When Account and its corresponding Contact is created that contact should become AccountContactRole)
Your help is much appreciated
Please find the sample code to insert AccountContactRole. Keep in mind that accountId and Contact Id are mandatory fields to create accountcontactrole. Refer to the documentation for more information
- https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_accountcontactrole.htm
Hope this helpsMark this as solved if it's resolved.
Thanks,
Nagendra
Contact is the required field on AccountContactRole object.So that you have to insert the Contact object or write query for the contact object.
I have write a sample code for your problem
Please mark it's best answer if your problem has been solved.
Thanks & Regards
David Hales(1021)
I should point out that if you enable "Allow users to relate a contact to multiple accounts" under Setup | Feature Settings | Sales | Account Settings, then Salesforce will automatically create an AccountContactRelation record for every Contact in an Account, with the "isDirect" field set true. The advantage of AccountContactRelation is that the Roles field is a multi-select picklist and you can have a Start Date and End Date on the relationship. Contacts will show in the "Related Contacts" related list on the Account record.
<pre>
trigger CreateAccountContactRole on Contact ( after insert )
{
List<AccountContactRole> acrs = new List<AccountContactRole>();
for ( Contact contact : Trigger.new )
{
acrs.insert
( new AccountContactRole
( ContactId = contact.Id
, AccountId = contact.AccountId
, Role = 'Insert Your Role Here'
, isPrimary = true
)
);
}
insert acrs;
}
</pre>