Custom Lightning Component Related List With Real Time REST Data

For this tutorial I’ll show a technique on how to integrate external data and display the data real time in Salesforce. This would not use an external object but a simple custom related list component that uses lightning:datatable base component and a controller than retrieves data via callout to an external REST resource and display them in Salesforce.

This is how it would look like.

For this I’m calling this a static REST resource which returns the following JSON response.

Next we need to display this data in a related list in Salesforce. We create a simple lightning component that we can add using Lightning App builder.

Start with the following lightning component markup.

And controller that calls a helper.

The helper creates a server side call that creates the REST callout. Then on successful response I’m setting the value for the mycolumns attribute by assigning a Javascript object assigning the properties of the column for the datatable. Then I simply assign the mydata attribute assigning and using JSON.parse to turn the response to a Javascript object. With that simple code I have a related list.

Note: you do not need the var actions as this is for another method I’m working on.

Then for my controller I have this simple call to my server

Then I simply drop the component on Lightning App Builder to the related list section for quick UI match. That should be it.

Salesforce Queueable Apex and Future annotations

Introduced for some time now particularly in Winter 15. Queueable Apex addresses some short coming of the @future methods. It’s an offspring of the marriage of @future methods and Batch Apex.

Queueable Apex allows you to submit jobs for asynchronous processing similar to future methods with the following additional benefits:

  • Non-primitive types – you can pass SObjects and custom apex types
  • Monitoring – you can monitor the job from the Apex jobs page in Setup or query the AsyncApexJob record
  • Chaining Jobs – create sequential jobs

How to use Queueable Apex:

  • Create a class that implements the Queueable interface
  • If you are going to make callouts you need to extend your implementation to Datatabase.AllowCallouts
  • To allow multiple primitive types create a contructor and call the public void execute method.
  • To execute the class, call it from your logic
  • There you can chain jobs by calling another Queueable class on the execute method.

Things to note: This counts to the your limit of 250 limit for asynchronous process per 24 hours.

How to parametize POST request on Salesforce Apex REST

On a standard POST call to a REST endpoint. The receiving endpoint expects a payload on the body of the POST. The service then parses the content of the body.

For example on the following Salesforce endpoint

https://integration-architect-dev-ed.lightning.force.com/apexrest/MyService

I created a POST request and sent on the body the following JSON:

{“companyName”:”GenePoint”,”caseType”:”Software”}

With Apex REST here are two ways you can create your REST POST service method

  • Create the method and supply the parameters for the function. Salesforce Apex REST will attempt to deserialize the payload data into those parameters.

Note: With this method passing the following XML payload will also work.

Consider the following when choosing which method to implement

  • If payload is easy and won’t change – method with parameters.
  • Do you have accept both JSON and XML payload – method parameters
  • For complex payload structure – method with User-defined type payload or the json String payload

Resource:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_methods.htm

Salesforce List Custom Settings is Greyed Out

Just ran into this when I was creating a new Custom Setting for a new org. The List Settings Type was greyed out.

Found out this is something new for Spring 18. It is now an application level settings that needs to be enabled even for System Administrators.

Starting with the Spring ’18 release, Admins have the ability to control the List type Custom Setting creation. By default, the “Manage List Custom Settings Type” is disabled, which is why Custom Setting type List is greyed out. To allow the creation of custom settings when using application-level data definitions you’ll need to enable Manage List Custom Settings Type.

To enable do the following:
Go to Setup > Data > Schema Settings and toggle button to enable “Manage List Custom Settings Type”

Then go back to Custom Settings.

Resolve ANT with Dollar Signs ($$) on Variables

Quick little tip. On my Ant deployment script for Salesforce I run into an issue where my password which was assigned to a variable contained double dollar sign characters. Ant would by default strip out any string with ‘$$’ sign into ‘$’ because it was expecting a value.

This caused my password to stop working.

I ended up breaking my password into two variables.

from

sf.password = time$$machine

to

sf.password = time$

sf.password2 = machine

Then on my build.xml file, I created a new property to store the dollar value and updated the passwordToken property.

<property name="dollar" value="$" />
<property name="passwordToken" value="${sf.password}${dollar}{sf.password2}${sf.token}"/>

That is the post for the day.