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
Leonie ChristianiLeonie Christiani 

update fields based on a custom field match between objects


I am looking to do the following:
When a new case is created with a custom field (Unique ID) populated i want SFDC to find the matching unique ID in an account record and then autopopulate the Account name on the case object.

I appreciate any help i can get!

Thank you,
Deepak GerianiDeepak Geriani


On case trigger after insert write Select query on account and get the name of account and update or set the field on case object.

case trigger (after insert ){

for(case c :[
Account account = [select id, name from Account where id= :  c.uniquefieldApiName ];
c.Accountfieldname =;
update c;


this is just sample please use try catch block because you will get errors when you are not able to find the id or submit unrelvant data.

please mark it solved if your issue has been solved 

Jitendra Singh ShahiJitendra Singh Shahi

In the above answer, you will have a problem with the governer limit as you are making a DML query inside for loop. It is best practice to always create bulkify triggers and avoid making DML query in for loop. See the below link for the governer limit in apex and trigger best practice.

You can make your trigger bulkify using this: ( Maybe you have to modify this code for names of your field )
trigger yourTriggerName on Case(after insert ){
    Map<String, Case> uniqueFieldMap = new Map<String, Case>(); 
    List<Case> caseToUpdate = new List<Case>();
    for(Case case :{
        uniqueFieldMap.put(case.uniquefieldApiName, case);

    for(Accont acc: [select id, name from Account where id in: uniqueFieldMap.keyset()]){
            Case case = uniqueFieldMap.get(;
            case.Accountfieldname = account.Name;

        update caseToUpdate;

I hope this will help. let me know if you have any queries. if it helps please mark it as the best answer,  so others can take help from here.