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.


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!