Sunday 19 August 2018

Best in Market - List of Code Review tools #Salesforce

Salesforce is an awesome platform, and has an incredible community that helps their developer and admins to grow in their careers. With Salesforce’s communities we get a lot of great tools which make developer and admin life easy. One of the important practices in project implementation is code review, as it insures your team has visibility into your applications code. Here is the list of few tools which I have found to help review codes:





1 Checkmarx : 



Checkmarx provides an awesome tool to secure your apex and visualforce code as well. It's easy to integrate with your salesforce org and provides you a whole report.
Report has the points of changes and what to changes, I personlly recommend this tool for your application and code security.
https://www.checkmarx.com/

2. Codescan: 



Code Analysis Tools for Salesforce
Its an appexchange tool which is really easy to use and install in your salesforce org. It help developers to identify bugs and increase the quality of your code.
This tool provides incredible UI to analyse you orgs apex code.
https://www.codescan.io/ 



3. PMD source code analyzer :



 PMD is also of the recommended tool to use for your apex code, its easily catches the defects of your apex code and provide you how to get ride of those defects.
It searches the unused variables, empty catch blocks, unnecessary object creation. This tool really help to clean your code in apex as well as in Javascript and visualforce.
https://pmd.github.io/ 

4. Clayton : 




Clayton is a next gen tool which does everything when you need your Salesforce application to be the best. It's very easy to setup and use. 
Clayton integrates into your code repositories and enforces quality and security standards across your organisation, at all times, while your apps are built. It provides you analyses over not only apex but lightning component code as well.
https://www.getclayton.com/ 

5. Code Climate :




 It Automated code review for test coverage, maintainability and more so that you can save time, it provides you real time feedback of your code that help to maintain
 good code as you go. It provides test coverage line by line as well, integrated with your GitHub repo, run analysis locally and team management with permission visibility.

 https://codeclimate.com/ 


Tuesday 29 May 2018

Difference between Application Events and Component Events in Lightning #Salesforce

Component Events

A component event is fired from an instance of a component. A component event can be handled by the component that fired the event or by a component in the containment hierarchy that receives the event. The component that fires an event is known as the source component.



The component that fires an event can set the event’s data. To set the attribute values, call event.setParam() or event.setParams().

Fire a component Event

In terms of firing an event you need to register that component event in your component and then you can fire the same. it looks something like below



A component can handle its own event by using the <aura:handler> tag in its markup. The name attributes in <aura:registerEvent> and <aura:handler> must match, since each event is defined by its name.



Application Events

Application event in simple words can be used in multiple components and component that has the handler for the event will be notified.



To create a custom application event, you need to use the <aura:event> tag in the event resource. You need to define type="Application" tag. To use you need to register application event same way as component event



To fire the application event you need to use event.setParam();



Events are of the most widely used in lightning component. so when you should use which one is also important.

thanks

Tuesday 22 May 2018

Converting Curl Request into Apex HTTP Request #Salesforce

Recently in a project I was working with a requirement, where we need to integrated Salesforce with that system, when I started going through the API documentation of the another system, they have provided everything with the curl request and response was in JSON.




So many of you guys might have already explored curl and converting the request as per another system requirement, but for me this was the first time. So if any of you have better approach then the one I am going to explain, please let me know.

So What is Curl ?

"cURL is a command line tool for getting or sending files using URL syntax.
Since cURL uses libcurl, it supports a range of common Internet protocols, currently including HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, LDAP, DAP, DICT, TELNET, FILE, IMAP, POP3, SMTP and RTSP.
cURL supports HTTPS and performs SSL certificate verification by default when a secure protocol is specified such as HTTPS. When cURL connects to a remote server via HTTPS".

Wiki Link

So here is of the curl request that I was dealing with, and I have taken a normal one which can be easily converted to apex.


So in above request the main thing to be taken care is to identify the parameter, header, body, method and endpoint. To identify these you need to look for -X -u -d -H

-x stands for request method
-u stands for authorization header
-d stands for body of the request
-H also stands for header

So by knowing the parameter defined in the curl request you can easily and quickly create a request in apex. So the request in apex format looks like below




So here is an small description of curl request formatting.
Thank you!

Thursday 8 February 2018

Caching Data with Storable Actions #Lightning Component Salesforce

Caching data at the client side can significantly reduce the number of server round-trips and improve the performance of your Lightning components. Server actions support optional client-side caching, and the Lightning Data Service is built on top of a sophisticated client caching mechanism.

In Lightning terminology, a server action is an Apex method that you invoke remotely from your Lightning Component. A storable action is a server action whose response is stored in the client cache so that subsequent requests for the same server method with the same set of arguments can be accessed from that cache.



Storable actions are the only currently supported type of storage. Storable actions cache server action response values. The storage name must be actions. Caching is especially beneficial for high-performance, mostly connected applications operating over high latency connections, such as 3G networks When you initialize storage, you can configure the expiration time, which is the duration in seconds that an entry is retained in storage..

Using storable actions, the cache behavior is controlled by two parameters set internally in the framework :
  • Expiration age: This is the age of the cached response. Whenever the response is older then the existing one and same vice versa. Expiration age is currently set to 900 seconds in Salesforce lightning.
  • Refresh age: Refresh age is the age of the response, when it gets refreshed, if the response is newer then the existing one, it will override the response, but lightning also calls the server method and get the response, if it different then the existing then it will override it as well. Refresh age is 30 second in lightning experience.

what to cache ?

The caching of the data should be decided on what is the response of your action, there are two type of action, one which returns everytime same thing, and another one is which is doesn't return the same response or dynamic.

The method which returns the same response each time called should be cached and other not,The setStorable function takes an optional argument, which is a configuration map of key-value pairs representing the storage options and values to set.

Cache Miss

If the action is not a cache hit as it doesn’t match a storage entry:
  • The action is sent to the server-side controller.
  • If the response is SUCCESS, the response is added to storage.
  • The callback in the client-side controller is executed.

Cache Hit

If the action is a cache hit as it matches a storage entry:
  • The callback in the client-side controller is executed with the cached action response.
  • If the response has been cached for longer than the refresh time, the storage entry is refreshed. When an application enables storable actions, a refresh time is configured. The refresh time is the duration in seconds before an entry is refreshed in storage. The refresh time is automatically configured in Lightning Experience and the Salesforce mobile app.
  • The action is sent to the server-side controller.
  • If the response is SUCCESS, the response is added to storage.
  • If the refreshed response is different from the cached response, the callback in the client-side controller is executed for a second time..

How to enable Storage Actions ?

To configure client-side storage for your standalone app, use <auraStorage:init> in the auraPreInitBlock attribute of your application’s template. For example:. 


<aura:component isTemplate="true" extends="aura:template">
    <aura:set attribute="auraPreInitBlock">
        <auraStorage:init
          name="actions"
          persistent="false"
          secure="true"
          maxSize="1024"
          defaultExpiration="900"
          defaultAutoRefreshInterval="30" />
    </aura:set>
</aura:component>


Thanks