I have to populate contact1(a text custom field) on case with the value from account object field account member(custom field).When i create a case and select a account name ..value from accountmember field of account object should get populated in contact1 field on case object. Please help me out with solution.

  • Did you consider a formula field ? Jun 11, 2014 at 13:26

4 Answers 4


You can use a workflow rule for this functionality. Create a workflow with the field update as the workflow action. As Account is a lookup on the case object, you can reference account object's field in the field update using the formula editor in the field update screen.


You can create an Apex Trigger to do this operation. It will take the ID of the Account record from the newly inserted/updated (based on the events on which you have written the trigger) case using the AccountId field. Then it will copy the value from Account record and then update the "contact1" field on the Case object. You will have to use Trigger Context Variables in your code.

You can follow the below links for more information :

You can use google to get a lot of similar examples.

If you still face some issues, please feel free to comment on this Post.


Apart from using a Workflow, this is the code of Trigger that you can use :

/* Note that this is just a working code. However, you might need to modify this code in order to make it appropriate for your use or make it bulkified so that it can handle multiple records */
trigger copyAccountMemberinContact1 on Case(before insert, before update) {

    List < Id > newOrUpdatedCases = new List < Id > ();
    List < account > acclist = new List < account > ();
    list <case> casesToBeUpdated = new List <case>();

    for (case c: trigger.new) {

    acclist = [Select AccountMember__c from Account where Id in : newOrUpdatedCases];

    System.Debug('newOrUpdatedCases' + newOrUpdatedCases);  
    System.debug('acclist ' + acclist);

    for (integer i = 0; i < casesToBeUpdated.size(); i++) {
        casesToBeUpdated[i].Contact1__c = acclist[i].AccountMember__c;

/******** Please mark the post as an answer if it has answered your question ************/

With your help, I was able to successfully apply this trigger code on task and event record, to update a custom activity field (Related_Firm_Static__c). We need to capture the static account on each contact activity as our clients often change companies. This code applied to task and event objects copies the contact's related account name at the time of the activity. Now I have to write my test class in hopes it passes for deployment to our prod. Thank you for the help with this!

trigger copyAccountFirmStatic on Task(before insert) {

    List < Id > newTasks = new List < Id > ();
    List < contact > conlist = new List < contact > ();
    list <task> tasksToBeUpdated = new List <task>();

    for (task c: trigger.new) {

    conlist = [Select Account.Name from Contact where Id in : newTasks];

    System.Debug('newTasks' + newTasks);  
    System.debug('conlist ' + conlist);

    for (integer i = 0; i < tasksToBeUpdated.size(); i++) {
        tasksToBeUpdated[i].Related_Firm_Static__c = conlist[i].Account.Name;
  • Can you please explain why this is posted an answer? Looks like you wanted to post a question in the community instead of answering. Please reconsider and take appropriate action. Let us know if you have any further queries. Apr 25, 2015 at 17:07
  • 1
    Sorry for the confusion--I am not asking a question. I was sharing the code that successfully captures and updates the related contact's account name on activity record. Apr 25, 2015 at 18:29
  • 1
    Further, this code won't work in all bulk loading scenarios. For example, if the same contact is on multiple tasks being loaded by the data loader, it will crash. This code shouldn't be used, and definitely shouldn't be the answer.
    – sfdcfox
    Apr 26, 2015 at 15:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .