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
Suhaas Kapardhi B SSuhaas Kapardhi B S 

Trigger on case to update the account name

I need o update the accounts name in the case record when I create a Case using custom modal which i have created. Below is the code which I have written.

trigger modalAccount on Case (after insert, after update) {
    
    Set<id> cas = new Set<id>();
    List<Account> acclist = new List<Account>();
   
    for(Case c:Trigger.new ){
         cas.add(c.AccountId);
        }
    
    List<Account> acc = [Select id, Name From Account Where id in: cas];
    
    for(Account temp:acc){
        temp.Name= 'sample Account Name';
        acclist.add(temp);  
    }
    update acclist;
}


The code which I have written is not working. 

Please help
Best Answer chosen by Suhaas Kapardhi B S
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suhas,

Which means there is an issue in LWC component. You need to check your LWC component. It is creating case but not relating the Case to the Account.

The trigger which you have written is working as intended.

If this solution helps, Please mark it as best answer.

Thanks,

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suhaas,

I see this code is working as expected. The Account is updating . The Account and Case here we are using are standard ones.

Can you share the modal which you created and are Account and Case standard?

Thanks,
 
Suhaas Kapardhi B SSuhaas Kapardhi B S
I have created a modal on account using lwc
Sai PraveenSai Praveen (Salesforce Developers) 
HI Suhaas,

This should be issue. If the Case is creating correctly and assoiating to the Account this logic will work.

Thanks,
 
Suhaas Kapardhi B SSuhaas Kapardhi B S
when i create case using, the record is being saved, but the account name is not populating. I dont know what is the problem
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suhas,

Which means there is an issue in LWC component. You need to check your LWC component. It is creating case but not relating the Case to the Account.

The trigger which you have written is working as intended.

If this solution helps, Please mark it as best answer.

Thanks,
This was selected as the best answer