Summer 16 is already in production and most of you already knows what’s there in pandora box. In this post, I will share my favorite 20 features of Summer 16 release.
Salesforce Summer 16
1. Clone Sandbox (Pilot) : This feature is not yet generally available however worth mentioning. Till now, we could create Sandbox only from production, however Summer 16 gives us a way to create brand new sandbox from other existing sandbox instead of production.
2. New Trace Flags in Debug Log : Now we can add trace flags on Automated Process, User, Apex Trigger and Apex classes as well. Before this release, we could only add trace flag on user. This enhancement will give developers more control over what to display in debug log and overcome debug log size limit problems.
How to resolve apex debug log size limit issue, Difference between Eclipse and developer console, Interactive Apex Debugging, Keyboard shortcuts for Developer console and Other best practices
While developing applications on Force.com platform using Apex, I am sure you may have been in need of debugging your code. Salesforce being cloud platform, method to debug code is very different as compared to other programming languages. In this post we will discuss all about Apex code debugging, challenges, solutions and other best practices.
Introduction to debug logs in salesforce with step by step procedure and screenshot, Difference between Debug log and System log in Salesforce
For the newbie and intermediate developers, most of the time it becomes very necessary to log the program at some stage / line and look into those that what actually is happening with the code.
In salesforce it is very easy to log and track the apex program. To log the apex code use below line of code:
System.debug(“Your message”);
or
System.debug(Logginglevel,”Your Message”);
Log levels available in Apex are (listed from lowest to highest) :
pageOutput=”true” – add the tracing information at the bottom of the ASPX page.
localOnly=”false” – tracing will be available to any web page.
requestLimit=”10″ – How many request should be saved on the server.
mostRecent=”true” – whether or not display the recent tracing information if the request reach at the limit.
After adding above tag in web.config, the output of ASP.NET page will look like:
Here you can see much of informations displayed like SessionId, Request Status, Controls available on that page, All the events of the page with start and end time etc and thus you can figure out the performance of your web application.
No Trace for a particular Page
Create a web page and in aspx file and at header write the tag Trace=”false”
Create few controls like link button and view the page in browser. You will see that the page is displayed with no tracing information, although its turned ON in web.config but page level tracing has the precedence over application level tracing.
Writing Custom Trace Information
Now on the click event of Link buttons write the custom trace information.
when you will click on the WriteLink button, below output will be seen.
ASP.NET Trace
and when you will click on warn button, the message will be displayed in Red color. so it is suggested to display the the important trace message as a warn.
ASP.NET Trace
Page.Trace Vs System.Diagnostics.Trace
Create a new class file and write a static function which will write the Trace Message. You will notice that Trace object is not available by default like ASPX page instead you will need to import the package “System.Diagnostics”.
So, there is lot difference in System.Diagnostic.Trace and Page.Trace.
Trace from Diagnostics display the trace information in output window of Visual studio whereas the Trace from page displays the Trace information in ASPX Page.
Integrate System.Diagnostics with ASPX Page (Routing all Trace information to web page)
We will need to add the listener in web.config file to route all the tracing information to the single web page.
To integrate the System.Diagnostics Trace with ASPX page, write below line of code in web.config.
.NET has provided us the flexibility of writing our own Trace Listeners in the form of the TraceListener class. Every Trace Listener is inherited from this class; therefore, in order to implement your own Trace Listener, you must inherit your Trace Listener class from this class.
TraceListener class has many virtual and abstract methods; at the very least, each inheritor of this class must implement the Write and WriteLine methods; other important methods are Fail, Close, and Flush. Inheritors are not supposed to implement these methods but it is a good idea to implement these methods. Descriptions of these methods are given in the beginning of the article.
Method Name
Result
Fail
Outputs the specified text with the Call Stack.
Write
Outputs the specified text.
WriteLine
Outputs the specified text and a carriage return.
Flush
Flushes the output buffer to the target media.
Close
Closes the output stream in order to not receive the tracing/debugging output.
Write and WriteLine methods are overloaded; following is a list of all the overloaded version of the Write method:
public override void Write(string message)
public override void Write(object o)
public override void Write(string message, string category)
public override void Write(object o, string category)
For this article, I have created a Trace Listener, DatabaseTraceListener, which actually stores trace and debug messages into a database.
add below code in Web.config which stores the connection string information.
TraceDateTime column stores the date and time of the trace message
TraceCategory column stores the actual category of the trace message
TraceDescription column stores the trace message
StackTrace column contains the stack trace
DetailedErrorDescription column contains the detailed error message which will be passed in second parameter of the Fail method.
create below stored procedure in SQLExpress
Now create a class named “DatabaseTraceListener” which inherit the abstract class “TraceListener”. You can check the code snippets in Source code of this article.
if you want to implement your own Trace Listener, simply derive your listener class from TraceListener class, implement at least the Write and WriteLine methods and you are done.
In our Example, Flush and Close methods simply save all the cached messages into the database.
Saving Trace information in File
We can also save the trace information in log files.
To save the trace information in File, simply add the following entry in web.config