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
rubel rana 6rubel rana 6 

Debug in Salesforce.

I am beginner in Salesforce.
In other languages, I can debug easily, like in PHP , I can echo any variable, then I can understand, what is happening. 
In Salesforce class, I have many queries which contains some variable also. I wanted to system.debug the queries, but only first one is printing, other system.debug is not printing. Why it is happening?

And how to  efficiently, can debug in Salesforce?

Thank you guys.
Rubel
AbhinavAbhinav (Salesforce Developers) 
Could you please share the related code snippet as well.

Thanks!
rubel rana 6rubel rana 6

query = 'Select ' + businessGroupFieldApiName + ' ClosedBusinessActivity, sum( ' + amountField + ' ) '
                + ' from OpportunityLineItem '
                + ' where  CALENDAR_YEAR(Opportunity.Start_Date__c) = :ActionYear  '
                + ' AND Opportunity.Type = \'' + typeSelected + '\''
                + ' AND ( Opportunity.StageName =  \'' + 'Closed Won' + '\''
                + ' OR Opportunity.StageName = \'' + 'Won License' + '\')';
        query += ' AND Opportunity.AccountId NOT IN :ExcludeSpecialAccounts AND Product2.Provider__c NOT IN :ExcludeSpecialProviders';
        if (RunAs != 'Company')
            query += ' AND Opportunity.OwnerId=  \'' + RunAs + '\'';
        query += ' group by ' + businessGroupFieldApiName + ' ';
             
        AggregateResult[] ClosedBusinessResults = Database.query(query);

 
Ankit Maini.Ankit Maini.
You can debug query at any point, it will print the string , String variables will print but if you try to print list it won't.
Similar to your example.
 
String fieldName = 'Name';
List<String> phoneList = new List<String>{'12345','3545'};
String query = 'Select '+fieldName;
system.debug('query1 =  '+query);
fieldName = 'Phone';
query += ', '+fieldName+ ' from Account where phone in :phoneList';
system.debug('query2 =  '+query);

Output will be:
USER_DEBUG [4]|DEBUG|query1 =  Select Name
USER_DEBUG [7]|DEBUG|query2 =  Select Name, Phone from Account where phone in :phoneList