+ 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);
            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){
            if(c.phone!=null && c.MobilePhone !=oldcontact.MobilePhone && c.Phone==oldcontact.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.

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:

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