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
Qihao GuoQihao Guo 

debug code

trigger addCase on Account (After update) {
   List<Account> allAccounts = new List<Account>([Select id,(select id from cases where status in('New','Open')) from account where id in :Trigger.new]);
   List<Case> newCases = new List<Case>();
    
    for(Account myAccount :allAccounts){
    
        if(myAccount.cases !=null){
            Case c = new Case();
            c.Accountid = myAccount.Id;
            c.Type = 'ICM';
            c.Origin = 'WEB';
            c.Status = 'New';
            newCases.add(c); 
            System.debug('create successfully');
        }
 
        
    }
    if(!newCases.isEmpty()){
        insert newCases;
        System.debug('create successfully');
    }
 
}
Here is my code to create a new case. If I want to debug, what code should I put in execute anonymous windows?
Best Answer chosen by Qihao Guo
PriyaPriya (Salesforce Developers) 
Hi ,

Try this :- 
 
Account a = New Account ();
a.Name = 'test Account';
Insert a;
a.Type = 'Prospect';
Update a;

Execute above code in Anonymous window and then check the debug log.
 

Kindly mark it as the best answer if it works for you.

 

Thanks & Regards,

Priya Ranjan