SOQL Queires in VSCode — November 30, 2020

SOQL Queires in VSCode

SOQL Files#

VS Code supports writing SOQL in both Apex files and standalone .soql files. When writing .soql files, we recommend that the file is located outside the directories registered in your sfdx-project.json because this is not a file to deploy to your org. The purpose of the .soql file is to provide a way to build and test a SOQL query before you import it to your Apex code. By default, a new project has a folder scripts/soql that contains an example accounts.soql file. You can use this folder to save all of your SOQL queries.

Code Completions#

VS Code supports code completions for SOQL .soql files (and will eventually support code completion in Apex files). To use this feature, you must refresh the SObject definitions so that the SOQL language server can provide code completion suggestions. Run SFDX: Refresh SObject Definitions from the Command Palette.

  • To see code completion suggestions, press Ctrl+space when you’re working in a .soql file.
  • To navigate between the suggestions, use the arrow keys.
  • To auto-complete from the suggestion, press Enter.
Animation showing code completion for a basic SOQL query
Continue reading
Field Tracking and History objects in Apex — November 29, 2020

Field Tracking and History objects in Apex

Field History Tracking

You can select certain fields to track and display the field history in the History related list of an object. Field history data is retained for up to 18 months through your org, and up to 24 months via the API. Field history tracking data doesn’t count against your Salesforce org’s data storage limits.

You can track the field history of custom objects and the following standard objects.

  • Accounts
  • Articles
  • Assets
  • Campaigns
  • Cases
  • Contacts
  • Contracts
  • Contract line items
  • Crisis
  • Employee
  • EmployeeCrisisAssessment
  • Entitlements
  • InternalOrganizationUnit
  • Knowledge
  • Leads
  • Opportunities
  • Orders
  • Order Products
  • Products
  • Price Book Entries
  • Service Contracts
  • Solutions

Modifying any of these fields adds an entry to the History related list. All entries include the date, time, nature of the change, and who made the change.

Continue reading
ARROW FUNCTIONS -Javascript simplified — November 26, 2020

ARROW FUNCTIONS -Javascript simplified

An arrow function expression is a compact alternative to a traditional function expression, but is limited and can’t be used in all situations.

Limitations:

Basic syntax

One param. With simple expression return is not needed:

param => expression

Multiple params require parentheses. With simple expression return is not needed:

(param1, paramN) => expression

Multiline statements require body brackets and return:

param => {
  let a = 1;
  return a + param;
}

Multiple params require parentheses. Multiline statements require body brackets and return:

(param1, paramN) => {
   let a = 1;
   return a + param1 + paramN;
}

Comparing traditional functions to arrow functions

Let’s decompose a “traditional function” down to the simplest “arrow function” step-by-step:
NOTE: Each step along the way is a valid “arrow function”

Continue reading
Relationship table – a quick look — November 23, 2020

Relationship table – a quick look

This table summarizes whether a standard object can be:

  • The master in a master-detail relationship with a custom object. Master-detail relationships involve cascading deletes and sharing rules that the parent controls.
  • The lookup in a lookup relationship on a custom object. In other words, whether a custom object can have a lookup to the standard object.
  • Extended with custom fields.
Standard ObjectMaster-DetailLookupCustom Fields
AccountYesYesYes
CampaignYesYesYes
CaseYesYesYes
ContactYesYesYes
ContractYesYesYes
EventNoNoYes
LeadNoNoYes
OpportunityYesYesYes
Product2NoYesYes
SolutionYesYesYes
TaskNoNoYes
UserNoYesYes

How to use continuation method in Lightning Web Components (LWC) — November 18, 2020

How to use continuation method in Lightning Web Components (LWC)

Continuation Class

Continuation Class is used to make asynchronous callouts using REST and SOAP services.

Continuation process executes “in the background” without the user having to wait for the response.

Continuation integration has 2 parts.

  1. Build a message and send request.
  2. Get the response and return the response to page.

Steps to write continuation method invoked when LWC is loaded:

Step 1 Before you start calling an external webservice, you have to add callout URL to remote site in the Salesforce user interface. Here, remote site url name is CALLOUT_URL.

Step 2 – To make a callout, write an Apex method that returns a Continuation object with continuation = true and @AuraEnabled annotation.

@AuraEnabled(continuation=true)
public static Object sendRequest() {
 // Create continuation and set timeout in seconds.
 Continuation con = new Continuation(40);
 //More code 
 return con;
}

In this example, method sendRequest() will return the Continuation object and the callback method getResponse() will receive the response.

Step 3 – Set an Apex callback method in the continuationMethod property to be called after the callout completes. In this example, the callback method is getResponse.

con.continuationMethod='getResponse';

Step 4 Set an endpoint for a callout by adding HttpRequestobject to the Continuation object.

Note – A single Continuation object can contain a maximum of three callouts.

HttpRequest req = new HttpRequest();
 req.setMethod('GET');
 req.setEndpoint(CALLOUT_URL);
 con.addHttpRequest(req);
Continue reading