You need to sign in to do that
Don't have an account?
Nickodemus
Trigger new custom object record upon Contact update
Hi all,
I'm really new to Apex, so totally clueless right now...
I want to create a related list on Contact that stores all previous Accounts that a Contact has been associated with... To solve this I've created a 'junction' object (called 'Associated Account')) as a M-D of Contact with the following fields:
In theory it would give an Account history in the related list of each Contact.... is this the best way to attack this challenge?
Many thanks,
Nick
I'm really new to Apex, so totally clueless right now...
I want to create a related list on Contact that stores all previous Accounts that a Contact has been associated with... To solve this I've created a 'junction' object (called 'Associated Account')) as a M-D of Contact with the following fields:
- Associated Account Name (Auto Number)
- Contact (M-D)
- Account (lookup)
- Start Date (required)
- End Date
- Currently Active (Checkbox - checked by default)
In theory it would give an Account history in the related list of each Contact.... is this the best way to attack this challenge?
Many thanks,
Nick
I guess you can achieve this using trigger. following psuedo code can work -
1) create after update & after insert trigger on contact
2) upon insert, check the contact.AccountID. If it is not null then create a new record of associated account.
3)upon update, check for old contact.AccountId &new contact.AccountId if they are different then insert associated account.
regards,
Santosh
You can use the following code.
Trigger Handler Class
Donot forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Thanks Mudasir Wani.
I've put that code into my org, but I'm afraid, i don't really understand what it's doing, and I don't know what to put into the createAssociatedAccounts method. As i say, unfortunately, I know very limited APEX, and although i know what i want it to do, i don't know how to get it done :( Any further help would be AMAZING... if you've got the time.
Many thanks.
What i understood is that you want to have contacts associated to multiple accounts.
But now you have choosen this approach
There is another way to do it have a look may be this will help
https://success.salesforce.com/answers?id=90630000000gvRIAAY
Approach --
Contact Roles is the only standard feature, through which you can associate a contact with multiple accounts, Cases and Opportunites.
1. You need to add Contact roles related list on Account page layouts,
2. You can edit Contact Role list from Contact role settings
Setup>Customize>Accounts>Contact Roles
3. When you click on 'New' button from Contact role related list, you will be able to lookup a contact and set role and save it under account.
However I have another solution for you.
You an create a "Contact Role" custom object . Here could be the field details
1. Name field could be auto number, (You do not need Name field)
2. Contact Name : Lookup to contact
2. Account Name : Lookup to account
3 Picklist (In which you mention Roles)
You will be able to see/edit Contact Role(Custom) related list below contact and Account both pages.
If this doesnot help then we can work on trigger.
Donot forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
From what i can tell, the trigger is going to be the best way to accomoplish this, but I'm not knowledgeable enough to write the Apex code...