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
switi lokhandeswiti lokhande 

How to write system.debug in triggere which steps by step write it Ho

Konse step ke baad lihknaa chaiye vo answer dekhne k liye 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Switi,

Usually we can write system.debug() after  which you want to see the result .

For Example:
 
trigger ContactTrugger on Contact (before insert,before update) {
    List<Contact> conlist= new List<Contact>();
    If(Trigger.isinsert && Trigger.isbefore){
    
    for(Contact c:Trigger.new){
        if(c.Phone==null && c.MobilePhone!=null){
            system.debug('check phone is before  '+c.Phone);
            c.Phone=c.MobilePhone;
            system.debug('check phone after assigning'+c.Phone);
        }
        
    }
    }
    if(Trigger.isupdate && Trigger.isbefore){
        
        
        for (Contact c:Trigger.new){
            Contact oldcontact= Trigger.oldmap.get(c.id);
            if(c.Phone==null && c.MobilePhone!=null){
                c.Phone=c.MobilePhone;
            }
            if(c.phone!=null && c.MobilePhone !=oldcontact.MobilePhone && c.Phone==oldcontact.MobilePhone )
            {
                c.Phone=c.MobilePhone;
            }
        }
        
    }
}

In the first debug statement i used to check if the phone is assigned or not.

In the second debug I checked if phone number is assiigned correctly or not.

Let me know if you face any issues.

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

Thanks,
 
Vineela ProddaturuVineela Proddaturu
Hi, switi
Debugging is an important part in any programming development. In Apex, we have certain tools that can be used for debugging. One of them is the system. debug() method which prints the value and output of variable in the debug logs.

for more info:
https://www.sfdc99.com/2014/02/22/debug-your-code-with-system-debug/
https://www.tutorialspoint.com/apex/apex_debugging.htm#:~:text=Debugging%20is%20an%20important%20part,variable%20in%20the%20debug%20logs. 

I think,it helps you.
Thank you, pls mark it as best answer.