Category: debug

How to generate Debug Logs for Guest Users || Changes done in Winter’17 Release

Recently while working on public sites, I have noticed that debug logs are not getting generated for guest users in the same way it was used to work earlier. Debug log is always handy while working in Salesforce. It will help you to debug the problems, help you to understand the flow etc. So while debug log was not getting generated, it became so difficult for me to debug the issues. After few hours of searching in Google, I have realized that in Winter’17 release, Salesforce changed the way of debug log generation for Guest Users. By “Guest User” I wanted to mean users having Guest User License. The reason behind the change is – Public sites are getting used by many users(Guest Users). So setting up a debug log for Guest sUer may generate multiple debug logs which will quickly fill up the debug log.  After Winter’17 release, Salesforce made some changes and due to that debug logs will be generated only for those targeted users. But what will differentiate those target users from the all other users using that public sites? Good questions. Answer to the question is that debug log will only be generated for those Guest users using the browser which has a special cookie.  Really is it “Cookie”? Yes, now cookie will decide whether the debug log will be generated or not.  Ok, the next...

Read More

Apex Debugger || All you need to know || Advanced Configuration

This post is in continuation of my previous post where I have explained the basic configuration of Apex Debugger. If you haven’t gone through that, I would request you to please go here.So with the assumption that you have configured Apex Debugger correctly and can do debugging, in this post, I will explain some advanced configurations which you can do with Apex Debugger.So let’s start -Choose for which user you want to enable the Apex Debugger – You can choose the user for which you want to enable the Apex Debugger. For that open Debug Configuration. Then check the Whitelisting Enabled and Use SOQL where clause option. Then put the where clause. For example in the below screenshot, I have put the ID of the user and clicked on the Query button Choose the request type – With this option you can select the request type for which you want to enable the Apex Debugger. Currently we can enable Apex Debugger for the below options – Execute Anonymous, Inbound Email Service, Invocable Action, Lightning/Aura, Quick Action, REST, Run Tests Synchronous, SOAP, Synchronous, Visualforce, Visualforce Remote Method. If you don’t choose anything, it means it is enabled for all the above types of requests.Choose Entry Point – With this option, you can choose the entry point. For example if you want to enable Apex Debugger for particular Visualforce page, you can...

Read More

Apex Debugger || All you need to know || Basic Configuration

Finally, Salesforce brings Debugging feature. I was waiting for this one for a long time and I am quite sure that many other developers like me also waited for this one.Today in this post, I would like to explain how you can use this feature and make your Salesforce developer life more powerful.Before I start, I would like to mention that this feature is not available in Developer orgs, it is only available in Sandboxes. You need to contact Salesforce to enable this feature in your Sandboxes. There is cost involved in getting this one enabled. To know about the cost, please contact Salesforce.With the assumptions that you have enabled this feature in your Sandbox, you need to setup your Sandbox as well as your Eclipse workplace. Below are the steps mentioned in Salesforce guide -Setup Sandbox for Apex Debugger -Setup IDE -First you need to Install or Update IDE plugin as instructed below -Once done, create a Salesforce project as instructed here. Note – Make sure you mark your Eclipse project as work online.Setup Eclipse Debugger -This is the most important step where you need to setup your Eclipse Debugger. To do that -Click on the Debug Icon in the toolbar and select Debug Configuration. Select Remote Apex DebuggerClick on the New Launch Configuration IconGive some name of your configurationClick Browse and select your projectClick Apply, and...

Read More

JSON Parsing with Apex in Salesforce – Part II

This post is in continuation of my previous post regarding JSON Parsing.In this post, what I am going to share is-How to parse a little more complex JSON containing array. Once the JSON data is parsed, how to display the same information in Visual Force Page.Check the below link to understand what I am trying to achieve at the end of this post let’s start with creating the Visual Force Page<apex:page controller=”StudentDetailController”> <apex:form > <apex:pageBlock Title=”JSON Parser Example”> <apex:commandButton value=”Parse JSON Data” action=”{!parseJSONData}” reRender=”studentData” /> </apex:pageBlock> <br /> <apex:pageBlock id=”studentData”> First Name: <apex:inputText value=”{!firstName}” /> Last Name: <apex:inputText value=”{!lastName}” /> <br/> <apex:pageBlockSection title=”Language Known:” collapsible=”false”> <apex:selectList value=”{!selectedLanguage}” multiselect=”false” size=”1″> <apex:selectOptions value=”{!languageOptions}”/> </apex:selectList> </apex:pageBlockSection> </apex:pageBlock> </apex:form></apex:page>Now the controller-public class StudentDetailController{ public String firstName{get;set;} public String lastName{get;set;} public String selectedLanguage{get;set;} private StudentDetailWrapper m; public List<SelectOption> languageOptions; public void parseJSONData(){ m = new ParseStudentData().parseData(); doAllInitialization(); } public void parseJSONData(String jsonMessage){ m = new ParseStudentData().parseData(jsonMessage); doAllInitialization(); } public List<SelectOption> getLanguageOptions(){ if(null == languageOptions){ languageOptions = new List<SelectOption>(); } return languageOptions; } private void doAllInitialization(){ initializeStudentName(); initializeLanguageOptions(m.language); } private void initializeStudentName(){ this.firstName = m.firstName; this.lastName = m.lastName; } private void initializeLanguageOptions(List<String> language){ languageOptions = new List<SelectOption>(); for(String aLanguage : language){ languageOptions.add(new SelectOption(aLanguage, aLanguage)); } }}Now the class which will do the JSON Parsing-public class ParseStudentData { private StudentDetailWrapper m; public StudentDetailWrapper parseData(String jsonMessage){ return doParsing(jsonMessage); } public StudentDetailWrapper parseData(){ String jsonMessage = ‘{“firstName” : “Sudipta”,...

Read More

Custom Logging Framework in Salesforce

In my current project, I have a requirement where I have to implement a custom logging framework. Salesforce put the debug/exception log with System.debug() statement, but going through that debug log to identify the issue is always a challenge. So the better approach is to store the exception as soon as it occurred somewhere so that later point we can always refer that to identify what happened.In order to achieve that below is what I did-First I have created an object(API Name: Custom_Log__c) to store the exception logs-Below are the custom field inside the object-Class__c(Text Area(255))   From which class the exception is comingMethod__c(Text Area(255))  From which method the exception is comingMessage__c(Long Text Area(32768))  Stack trace of the exceptionPriority__c(Picklist) – Possible values are DEBUG, ERROR, FATAL, INFO, WARNINGNow I need to create the below custom settings -EnableCustomLogging with possible values true/false. The reason behind is that with EnableCustomLogging = true, exceptions will be stored in the custom object i.e. Custom_Log__c and with EnableCustomLogging = false, exception will be stored in the debug log with System.debug() Now with this setup, I have created the visual page.Source Code:<apex:page controller=”CustomLogController”> <apex:form > <apex:commandButton value=”Divide By Zero Exception!” action=”{!divideByZeroException}” /> <br/> <apex:commandButton value=”Null Pointer Exception!” action=”{!nullPointerException}” /> </apex:form></apex:page>Now the controller – CustomLogController:public class CustomLogController { public void divideByZeroException(){ Integer number1, number2; try{ number1 = 10; number2 = 0; Integer number3 = number1/number2; }catch(Exception ex){ String message = ‘Error: ‘ +...

Read More