Friday, July 28, 2017

Language Translation in VisualForce Page

Salesforce provide functionality through which you can create single VF page and that can be translated in different languages based on language or locale preference of current logged in user.

You need to upload the translation of all custom fields which you are going to use in VF page and can utilize custom labels to display warning, error information on VF page.

In order to render the VF page in particular language, use Language attribute on <apex:page> tag. You can also bind this values with controller variable so that you can render VF page in different language.

<apex:page controller="SK_LocalizationTestController" language="{!selectedLang}">

I have created a very simple VF page to illustrate this functionality by displaying account information. I have dropdown on VF page through which user will select language and VF page will re render to display page in selected language.





Note:
  • If you are displaying page message using <apex:pageMessages>, then use custom label on apex class to display message. Upload all translation for custom label in salesforce.
  • For custom fields also you need to upload language translation. Please refer Translation Workbench under Set Up.
  • The language attribute does accept ISO country codes plus an optional locale like en,en_US,de,de_DE etc.
  • For displaying header or pageblock section title, use custom labels.

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   
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    
FETCHING FILE FROM EXTERNAL/PUBLIC URL AND STORING IT IN SALESFORCE   

Monday, July 24, 2017

Changes to Lightning Data Services (LDS) in Summer'17 Release

Lightning Data Service is used to load, create, edit, or delete a record in Lightning component, without using server side Apex code. Lightning Data Service takes care of sharing rules and field-level security.

Below are changes to LDS in Summer'17 Release

  • force:recordPreview has been deprecated. Now use force:recordData instead of force:recordPreview. 
  • targetFields attribute is added to force:recordData, which is populated with a simplified view of the record’s fields. targetFields is automatically updated a record changes.
  • The targetRecord attribute of force:recordData,  has been updated to return records in a new format. 
Old JSON format was :
{
    "AnnualRevenue": null,
    "BillingCity": "Toronto",
    "CreatedById": "005R0000000IXV3IAO",
"CreatedBy.Name": "Admin User",
"CreatedBy": {
        "Id": "005R0000000IXV3IAO",
        "Name": "Admin User",
        "sobjectType": "User"
    }
}


New JSON Format is:
{
  "apiName": "Account",
  "fields": {
  "AnnualRevenue": {
  "displayValue": null,
  "value": null
  },
  "BillingCity": {
  "displayValue": null,
  "value": "Toronto"
  },
  "CreatedBy": {
  "displayValue": "Admin User",
  "value": {
  "apiName": "User",
  "fields": {
  "Id": {
  "displayValue": null,
  "value": "005R0000000IXV3IAO"
  },
  "Name": {
  "displayValue": null,
  "value": "Admin User"
  }
  },
  "id": "005R0000000IXV3IAO",
  "recordTypeInfo": null
  }
  },
  "CreatedById": {
  "displayValue": null,
  "value": "005R0000000IXV3IAO"
  }
  }
 }

The following example shows the targetFields attribute within the force:recordData component.

<force:recordData aura:id="skss"  recordId="{!v.recordId}"  layoutType="{!v.layout}"
  fields="{!v.fieldsToQuery}"  mode="VIEW"   targetRecord="{!v.record}"
  targetFields="{!v.simpleRecord}"   targetError="{!v.error}" />

For complete understanding of LDS along with code, refer Lightning Data Services : Way to perform operation on records without using server-side Apex class  blog

More Blogs>>: 
LIGHTNING DATA SERVICES    
PASSING LIGHTNING COMPONENT ATTRIBUTE VALUE FROM VF PAGE    
FIRE LIGHTNING EVENTS 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    

Thursday, July 20, 2017

Inheritance in Lightning Components

Lightning framework also support component inheritance in same way as it is supported in Apex.
You can mark any component as extensible means component can be inherited by any component. Inheritance allows us use attributes and javaScript functions of extensible component in all inherited components.

Consider a scenario in which you have many components which call server side apex controller method from their helper function. So instead of writing callToServer method in all components helper function, you can create a component and mark it as extensible component and write callToServer function in helper function. Now in all your components, extends this component and on any action just call callToServer function.

I have created component "SK_CallToServerUtility" which contain javascript function in helper which performs call to server side apex methods.

In order to mark any component as extensible, just specify extensible="true" in component attribute.

<aura:component extensible="true">
    <!-- below attribute value will be set by components which will inherit it-->
    <aura:attribute name="msg" type="String" default=""/>
{!v.body}
</aura:component>

If you want to inherit any extensible component, then specify component name in extends attribute in component like extends="c:SK_CallToServerUtility".

Please refer below code to have better understanding about inheritance in lightning components.



Code Explaination:

I have created SK_AccountList component which will initially display latest 100 account records by calling callToServer function in doInit function.

When user enter some search string and click search account, then table will display account records with name matching with search string again by calling callToServer function present in SK_CallToServerUtility component  which is inherited by SK_AccountList component.

Also in SK_AccountList component, we are setting the attribute value("msg") of SK_CallToServer component.

Hope this will help in basic understanding of how to use inheritance in Lightning Components!!

Looking forward for everyone's comments and feeback.

More Blogs>>: 
PASSING LIGHTNING COMPONENT ATTRIBUTE VALUE FROM VF PAGE    
FIRE LIGHTNING EVENTS 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    

Saturday, July 1, 2017

Firing Event from Lightning Component and Passing Parameter to VF Page

In this blog, I am going to explain the way through which you can pass parameter from Lightning component by firing event from it and handling it in VF page and display the passed parameter in VF page.

If you want to understand how you can fire event from VF page and handle it in Lightning component, then refer below blog:

How to Fire Lightning Events from VF Page in Lightning

I have created a VF page which contains input text which will display Account Id which will be passed from Lightning component. This VF page also contains div container which will display lightning app which contains our lightning component.



Below is complete code for above example:

Note:
  • If you don't have namespace in your org then on VF page use "c:" instead of "skforce:" like c:SK_AccListViewApp
Hope this will help!!!

Looking forward for your comments and suggestions...

More Blogs>>: 
PASSING LIGHTNING COMPONENT ATTRIBUTE VALUE FROM VF PAGE    
FIRE LIGHTNING EVENTS 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    

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!!