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

Trigger for Primary Account
Hi Folks
I require code for the following scenario.I have a custom object called Employment history. I need to:
Build a trigger which identifies the primary account (likely to be the latest active employment record) and adds this value to the parent account field
Ensure this field isn't visible to standard users
Ensure this field is wiped if their employment history is deleted or if all records are set to inactive.
Any ideas?
Many thanks
I require code for the following scenario.I have a custom object called Employment history. I need to:
Build a trigger which identifies the primary account (likely to be the latest active employment record) and adds this value to the parent account field
Ensure this field isn't visible to standard users
Ensure this field is wiped if their employment history is deleted or if all records are set to inactive.
Any ideas?
Many thanks
This will help you learn apex development.
Refer this if you have just started apex development:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_HelloWorld.htm
Ive tried this Is this anywhere close?
trigger PrimaryAccount on Account (before update, before insert) {
//Set of Account Ids
for(Account fcon : Trigger.New)
{
if(fcon.DRM_Active_c != TRUE)
fcon.DRM_Contact_employer = fcon.ParentId;
}
}
every time an Account is updated or inserted, you check for the DRM Active flag.
If it's true, you assign the Parent Account to DRM Contact Employer (this should also be a lookup to Account).
I don't think this is what your requirement is. How have you identified the Primary Account here?
It should be everytime a Contact is updated or inserted you check the DRM Actiive flag.
If its true you assign the DRM Contact Employer as the Parent Account.
The Primary account will be whatever Account the DRM Contact Employer is.
Hope this makes more sense.