Search This Blog

Friday, June 5, 2020

How to view full or complete system.debug logs in Salesforce - Salesforce Globe For You

How to view complete system.debug logs in salesforce?  - Salesforce Globe For You 

Problem: When we use system.debug in Apex methods for debugging and when we run that method,the debug log string gets truncated and displays half of the result sometimes.

Solution:you can view complete debug value using 'Open Raw Log' option in the logs tab of Developer console.
Example:

public class ViewCompleteJSONController {
    public static void viewJSON() {
        List<LeadWrap> lstLeadWrap = new List<LeadWrap>();
        For(Lead objLead:[Select id,name,company,status from Lead]) {
            LeadWrap objWrap = new LeadWrap();
            objWrap.name = objLead.name;
            objWrap.company = objLead.company;
            objWrap.status = objLead.status;
            lstLeadWrap.add(objWrap);
        }
        system.debug('Lead JSON:'+JSON.serialize(lstLeadWrap));
    }
    public class LeadWrap {
        public String name {get;set;}
        public String company{get;set;}
        public String status {get;set;}
    }
}

When we run the method in developer console using Debug --> Open Execute Anonymous Window

ViewCompleteJSONController.viewJSON();

The debug log gets display but string may appear as truncated.

To view complete string ,go to that logand right click,you will get the option to 'Open Raw Log' as shown in the image below.

Now,on click it,the debug log appears completely.

Enjoy

Tuesday, June 2, 2020

Display object names as picklist or drop-down in visual force page

Display object names as drop-down in visual force page.
Apex Class:

public class ObjectNameAsPicklistController {
    public List<SelectOption> lstObject {get;set;}
    public String selectedObject {get;set;}
    public ObjectNameAsPicklistController() {
        lstObject = new List<SelectOption>();
        for(String obj:schema.getGlobalDescribe().keyset()) {
            system.debug('obj:'+obj);
            lstObject.add(new selectOption(obj,obj));
        }
    }
    
}
Page:ObjectAPINameAsPicklist
<apex:page controller="ObjectNameAsPicklistController">
<apex:form>
    <apex:pageBlock>Select Object:<br/>
        <apex:selectList value="{!selectedObject}" label="Select Object:" title="Select Object:">
            <apex:selectOptions value="{!lstObject}"/>
        </apex:selectList>
    </apex:pageBlock>
</apex:form>
</apex:page>

Output: