Wednesday, June 28, 2017

How to find Salesforce API version of your Org in Apex

Sometimes it is required to find out current API version of your Org (Sandbox/Dev Org/Production) in order to perform some operations like making HTTP request to SFDC URI which contains api version.

As of now, I was not able to find any method in apex through which I can get my org current api version So I have created utility class which uses Tooling API to get all version related to org and returning latest/current api version like 39.0,40.0 etc.

Below is complete code for this.


You can run below scripts in developer console to get current API version after saving above class in your org.

Decimal currentAPIVersion = UtilityClassForSFDC.findAPIVersionOfOrg();
system.debug('***************currentAPIVersion:'+currentAPIVersion);

After running you may get "Unauthorized endpoint url". Just add your SFDC base URL in remote site setting to avoid this exception.

Hope this will help!!!
Looking forward for your comments and suggestions..


More Blogs>>: 
USING DATABASE.UPSERT WITH EXTERNAL ID  
DYNAMIC APEX IN SALESFORCE  
SOQL INJECTION IN SOQL  
CUSTOM METADATA AND CUSTOM SETTINGS IMPLEMENTATION TRICKS  
SMART TABLE USING ANGULARJS IN VISUALFORCE PAGE  
REST API TUTORIAL FOR SALESFORCE  
VISUALFORCE COMPONENT FOR RECORD STATUS BAR  
FETCHING FILE FROM EXTERNAL/PUBLIC URL AND STORING IT IN SALESFORCE  

Monday, June 26, 2017

How to Fire Lightning Events from VF Page in Lightning

Salesforce provide an option to include lightning components in VF page by adding it to Lightning app and referencing that in VF page.

In this blog, I am going to show an example to fire lightning events from VF page. here I will be passing account billing country from VF page by firing component event and displaying its value in component through event handler.




Below is complete code for firing event from VF page.  Below code also contain sample code to pass component attribute value from VF page.

Hope this will help!!
Looking forward for everyone's comment and suggestions..


More Blogs>>: 
PASSING LIGHTNING COMPONENT ATTRIBUTE VALUE FROM VF PAGE    
DYNAMICALLY CREATING AND DESTROYING LIGHTNING COMPONENTS    
RAISING AND HANDLING CUSTOM EVENTS IN sALESFORCE lIGHTNING    
WHY TO USE DESIGN RESOURCE AND HOW TO ADD DYNAMIC OPTION TO DATASOURCE    
PASSING LIGHTNING COMPONENT ATTRIBUTE VALUE FROM VF PAGE    
PASSING INNER WRAPPER CLASS TO LIGHTNING COMPONENT    
LIGHTNING COMPONENT FOR RECORDTYPE SELECTION FOR ANY SOBJECT    
CUSTOM COMPONENT TO SHOW/HIDE SPINNER IMAGE    

Sunday, June 25, 2017

Passing Lightning Component attribute value from VF page

As we know that we can include Lightning component in VF page by creating a Lightning App and add it to VF page by specify particular script. Sometime it is required to pass some dynamic value to component so that it can behave differently based on component attribute value.

Below is sample code which explains how to passed component attribute from VF page. Here we are passing Account name to lightning component by using standard controller on VF page.

In order to test the output, open below URL:
https://your-domain-url/apex/lightningVF?id=xxxxxxxxx

where xxxxxxxxx is Account Id.

Note:
  • Whenever you use extends="ltng:outApp" in Lightning app,  SLDS is automatically get applied your components.
  • If you don't want to apply SLDS, just use extends="ltng:outAppUnstyled"
  • If you are having org namespace, then always use " <namespace>:lightningComponentName" instead of  "c:lightningComponentName"  in VF page.

Hope this will help!!

Friday, June 23, 2017

Custom Component to show Loading Spinner in Lightning during Server or Client side Operations

We have created a lightning component which can be used to display Loading Spinner image whenever you perform any server side (apex method call) or some complex operation on client side (component controller).

How to use this component?
  • Create a attribute in your component of boolean type to show and hide spinner.
<aura:attribute name="showSpinner" type="Boolean" default="false" />
  • Add below component reference in your mark up. Here showSpinnerCmp is component name.
<c:showSpinnerCmp show="{!v.showSpinner}"/>
  • In your controller just toggle the showSpinner value to true/false to display/hide spinner.
component.set("v.showSpinner",true); //to show spinner
component.set("v.showSpinner",false); //to hide spinner

You can find complete code for showSpinnerCmp component below.
You can now save this component and can used with any other component.



Hope this will help!!!


More Blogs>>: 
DYNAMICALLY CREATING AND DESTROYING LIGHTNING COMPONENTS    
RAISING AND HANDLING CUSTOM EVENTS IN sALESFORCE lIGHTNING    
WHY TO USE DESIGN RESOURCE AND HOW TO ADD DYNAMIC OPTION TO DATASOURCE    
PASSING INNER WRAPPER CLASS TO LIGHTNING COMPONENT    
LIGHTNING COMPONENT FOR RECORDTYPE SELECTION FOR ANY SOBJECT    

Thursday, June 1, 2017

Generic Dynamic & Responsive Datatable Lightning Component with Sort, Search and Pagination Feature

Sometimes it is required to display set of records in Lightning component with different features like sort, search and pagination. In order to perform this operation every time with help of server side controller is not advisable approach specially for lightning experience.

I have created Lightning datatable component which can display records from any sobject. You need to specify below mention component attributes and it will display record in datatable with all features.


  • objAPIname (Like Account, Contact etc.)
  • fieldsAPINameList (comma seperated field API names like "Name,Type,Industry")
  • columnsLabelList (comma seperated column labels which you to specify like "Account Name, Type, Industry")
  • sortingOrder (specify field to sort records like "LastModifiedDate DESC")
  • columnForHyperLink (specify Field API name which will appear as hyper link for record detail page)
  • filterCriteria (criteria to filter records like "Industry !=null")
  • recordsLimit (number of records returned from sobject like 200, 100 etc)

Now we are going to display contact records in datatable by using below syntax in any app or withing any component:


<c:LightningJSONDataTable objAPIname="Contact"     
fieldsAPINameList="Name, Account.Name, Email"
columnsLabelList="Contact name, Account Name, Email"
sortingOrder="LastModifiedDate DESC" 
columnForHyperLink="Name"
filterCriteria="Email != null" 
recordsLimit="100"/>

below is image snapshot:


You can download the complete code from below URL:

Or you can install unmanaged package from below URL in your org:

https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000BGlf


Hope this will help!!!

More Blogs>>: 
DYNAMICALLY CREATING AND DESTROYING LIGHTNING COMPONENTS    
RAISING AND HANDLING CUSTOM EVENTS IN sALESFORCE lIGHTNING    
WHY TO USE DESIGN RESOURCE AND HOW TO ADD DYNAMIC OPTION TO DATASOURCE    
PASSING INNER WRAPPER CLASS TO LIGHTNING COMPONENT    
LIGHTNING COMPONENT FOR RECORDTYPE SELECTION FOR ANY SOBJECT