Salesforce Lightning Controller compound filed issue.

Salesforce Lightning Controller compound filed issue.

Salesforce Lightning Apex Controller will not support compound fields.  When you use compound fields with @AuraEnable annotation you will be receiving an “Error message: Error: An internal server error has occurred”

Here is the code.

 

Developer Console error message.

Solution : 

You have to use individual fields instead of compound fields. 

 

Salesforce Lightning Time Ago

In this blog, I am going to explain the time ago lightning components. Time Ago is future will allow displaying the dates in “time Ago “format.

The Application which you are going to build with this blog is going to look like as show like below image.Opportunity table that contains the closed date and created date will be displayed in the time ago format.

What you are going to do 

  • Opportunity Lightning Time Ago Application
  • Opportunity Time Ago Component
  •  Using Timeago.js in components 

Prerequisite

  • My Domain Should is enabled.
  • bootstrap static resource. Static resource name “bootstrap”
  • time ago JavaScript static resource. Static resource name “timeago”

Step 1:  Creating “OpportunityTimeAgo” lightning APP.

This Application is the container to place the lightning Time ago components. 

Go to Developer Console, Create a Lightning App bundle with name “OpportunityTimeAgo” and add the below code.

 . 

Step 2:  Creating Apex Class “OpportunityCls” 

Now you are going to create an Opportunity list Component which contains time ago feature. After that, we will be adding to the Above App

 

Step 3: Creating “OpportunityList” Component

This Component will fetch the List of opportunities and display it in table format 

Add the Below logic to OpportunityListController.js

 

Code Highlights 

  • Opportunities attributes are contained list of Opportunities return from Apex Controller. 
  • aura: handler that will be executed on the component initialization.

adding OppotynityList Component  to OpportunityTimeAgo App .

go to Developer Console — > Open Lightning resource à “OpportunityTimeAgo” and add the OpportunityList component to it as shown below.

Step 4 : Creating “OpportunityListTimeAgo” Component

Create an OpportunityListTimeAgo Component with the below code.This Component will be displayed the date in time ago format.

Add below code to OpportunityListTimeAgoController.js 

Code Highlights 

  •  OpportunityListTimeAgo Component have a attribute “timeAgo” which will be used to pass from the OpportunityList.cmp Component . 
  • aura:handler used to convert the date into TimeAgo format . 

Step 5 : Adding OpportunityListTimeAgo.cmp to OpportunityList.cmp 

add OpportunityListTimeAgo to the OpportunityList component as show below .

Github URL for Complete code: https://github.com/rajamohanvakati/Lightning-Time-Ago