Start tracking your progress
Trailhead Home
Trailhead Home

Learn What's New for Platform Developers

Learning Objectives

After completing this unit, you’ll be able to:

  • Make HTTP callouts from asynchronous Apex code to Salesforce APIs.
  • Mark Apex methods as cacheable.
  • Use iframes to isolate untrusted third-party content in a Visualforce page.
  • Extract dependency information for unlocked packages.

Introduction

Let’s take a look at some additional highlights for Platform developers in the Winter ’19 release.

Streamline API Calls to Your Org from Apex Code

Use the new System.Url.getOrgDomainUrl() method to interact with Salesforce REST and SOAP APIs in Apex code. Previously, orgs with My Domain enabled could access some API features from Apex code only after setting up remote site settings or named credentials. Some objects, such as DatedExchangeRate, are accessible only through the API. You can now interact with those objects using Apex code, building endpoints with the getOrgDomainUrl() method. You can also use the endpoints to access your org’s limits information, invoke flows, interact with list views, create and customize picklist value sets and custom fields, and more.

You can use getOrgDomainUrl() in orgs with or without My Domain to retrieve the canonical URL for the org in which the Apex code is running. For example, https://yourDomain.my.salesforce.com, for orgs with My Domain, or, for orgs without My Domain enabled, https://yourInstance.salesforce.com.

This example uses the User Interface API to get default values so that you can clone a record.

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm() + '/services/data/v44.0/limits');
req.setMethod('GET');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
HttpResponse res = h.send(req);

API calls sometimes require a session ID and a URL. You can obtain that session ID using the updated System.UserInfo.getSessionId() method. You can use getSessionId() both synchronously and asynchronously. In asynchronous Apex (Batch, Future, Queueable, or Scheduled Apex), this method returns the session ID only when the code is run by an active, valid user. When the code is run by an internal user, such as the automated process user or a proxy user, the method returns null.

You can’t make API calls from your Lightning components’ JavaScript code, including related Apex controller code. This behavior is unchanged from previous releases.

Note

Note

This change applies to Lightning Experience, Salesforce Classic, and all versions of the Salesforce app in Professional, Enterprise, Performance, Unlimited, Developer, and Database.com editions.

See also:

Mark Apex Methods As Cacheable

Prior to Winter ’19, to cache data returned from an Apex method, you had to call setStorable() in JavaScript code on every action that called the Apex method. Now you can mark the Apex method as storable (cacheable) and get rid of any setStorable() calls in JavaScript code.

Marking a method as storable improves your component’s performance by quickly showing cached data from client-side storage without waiting for a server trip. If the cached data is stale, the framework retrieves the latest data from the server. Caching is especially beneficial for users on high-latency, slow, or unreliable connections, such as 3G networks.

This change is versioned. Existing component code with an API version of 43.0 or earlier continues to work without any changes.

To cache data returned from an Apex method for any component with an API version of 44.0 or later, annotate the Apex method with @AuraEnabled(cacheable=true). For example:

@AuraEnabled(cacheable=true)
public static Account getAccount(Id accountId) {
    // your code here
}

To update an existing component to API version 44.0, remove setStorable() calls in JavaScript code. Annotate the Apex method with @AuraEnabled(cacheable=true) instead of @AuraEnabled, or you get an error response for the action.

Note

Note

This change applies to orgs with Lightning components in Lightning Experience, Salesforce Classic, and all versions of the Salesforce app.

 

Improve Security By Isolating Untrusted Third-Party Content with iframes

You can now isolate HTML static resources on a separate domain using iframes. Using a separate domain to embed information from untrusted sources protects your Visualforce content.

To reference a static HTML file on a separate domain, use $IFrameResource.<resource_name> as a merge field, where resource_name is the name you specified when you uploaded the static resource.

Note

Note

This feature applies to Lightning Experience, Salesforce Classic, and all versions of the Salesforce app in Contact Manager, Group, Professional, Enterprise, Performance, Unlimited, and Developer editions.

See also:

Extract Dependency Information for Unlocked Packages

For an installed unlocked package, you can now run a simple SOQL query to extract its dependency information. You can also create a script to automate the installation of unlocked packages with dependencies.

The SubscriberPackageVersion Tooling API object now provides dependency information. Using a SOQL query on SubscriberPackageVersion, you can identify the packages on which your unlocked package has a dependency. You can get the (04t) IDs and the correct install order for those packages.

Example

Package B has a dependency on package A. Package D depends on packages B and C. Here’s a sample sfdx-project.json that you would have specified while creating a package version. Package D dependencies are noted as packages A, B, and C.

{    "packageDirectories": [
       {
            "path": "pkg-a-workspace",
            "package": "pkgA",
            "versionName": "ver 4.9",
            "versionNumber": "4.9.0.NEXT",
            "default": true
        },
        {
            "path": "pkg-b-workspace",
            "package": "pkgB",
            "versionName": "ver 3.17",
            "versionNumber": "3.17.0.NEXT",
            "default": false,
            "dependencies": [
                {
                    "package": "pkgA",
                    "versionNumber": "3.3.0.LATEST"
                }
            ]
        },
        {
            "path": "pkg-c-workspace",
            "package": "pkgC",
            "versionName": "ver 2.1",
            "versionNumber": "2.1.0.NEXT",
            "default": false
        },
        {
            "path": "pkg-d-workspace",
            "package": "pkgD",
            "versionName": "ver 1.1",
            "versionNumber": "1.1.0.NEXT",
            "default": false,
            "dependencies": [
                {
                    "package": "pkgA",
                    "versionNumber": "3.3.0.LATEST"
                },
                {
                    "package": "pkgB",
                    "versionNumber": "3.12.0.LATEST"
                },
                {
                    "package": "pkgC",
                    "versionNumber": "2.1.0.LATEST"
                }
            ]
        }
    ],
    "namespace": "",
    "sfdcLoginUrl": "https://login.salesforce.com",
    "sourceApiVersion": "44.0",
    "packageAliases": {
        "pkgA": "0HoB00000008Oq6KAE",
        "pkgB": "0HoB00000008OqBKAU",
        "pkgC": "0HoB00000008OqGKAU",
        "pkgD": "0HoB00000008OqGKAQ"
    }
}

Before installing pkgD (with ID=04txx000000082hAAA), use this SOQL query to determine its dependencies.

sfdx force:data:soql:query -u {USERNAME} -t
   -q "SELECT Dependencies FROM SubscriberPackageVersion
       WHERE Id='04txx000000082hAAA'" --json

You see this output when you run the query, with the (04t) IDs for pkgA, pkgB, and pkgC in that order.

"Dependencies":{"Ids":[
   {"subscriberPackageVersionId":"04txx000000080vAAA"},
   {"subscriberPackageVersionId":"04txx000000082XAAQ"},
   {"subscriberPackageVersionId":"04txx0000000AiGAAU"}]}
Note

Note

This change applies to Lightning Experience, Salesforce Classic, and all versions of the Salesforce app in Group, Professional, Enterprise, Performance, Unlimited, and Developer editions.

These are just a few key highlights for Platform developers. Be sure to check out the full Winter ’19 Release Notes in the Resources section. Also try your skills using the Lightning Map Component in the next unit.

Resources

retargeting