Thursday, 27 May 2021

Access Token Generation and update existing record from Standard Salesforce REST API

 Hi ,

Here are we are going to learn how to generate access token when you are using connected app for authentication.

When you create a connected app then it provides consumer key (client_id) and consumer secret (client_secret).

Now you should use "username" and "password" of an integration user (any user who access access on your object) .

Now let's start generating access token:

1)Prepare url :

String urlStr = <baseurl>'/services/oauth2/token?grant_type=password&client_id='+<consumerkey>+'&client_secret='+<consumersecret>+'&username='+<username>+'&password='+<passwordwithsecuritytoken>;

Http h = new Http();         

HttpRequest req = new HttpRequest();

req.setEndpoint(urlStr);

req.setMethod('POST');

HttpResponse res = h.send(req);

 Map<String,object>  jsonMap= (Map<String,Object>)JSON.deserializeUntyped(res.getBody());

if(jsonMap.get('access_token')!=null){

String updateURLStr = <baseurl>'/services/data/v52.0/sobjects/Account/'+actId;

req = new HttpRequest();

req.setEndpoint(updateURLStr);

req.setMethod('PATCH');

req.setHeader('Authorization', 'Bearer '+String.valueOf(jsonMap.get('access_token')));

req.setHeader('Content-Type', 'application/json');

req.setBody(JSON.serialize(actObj));

res = h.send(req);


}

Reference:

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_what_is_rest_api.htm





Tuesday, 18 May 2021

Override Entity Permissions When using

Hi,


The new ignoreEditPermissionForRendering attribute on <apex:inputField> allows you to override entity edit permissions for users, even when the underlying permission on the object doesn’t allow edits. This override affects all users but is intended to be used only for guest users. This attribute works only with a custom controller in without sharing mode.

Where: This change applies to Salesforce orgs in Enterprise, Performance, Unlimited, and Developer editions.

When: This change was available first in Winter ’21 and then back-ported to Summer ’20.

How: This attribute bypasses entity edit permissions and field-level security edit checks, so any form field that uses <apex:inputField> with this attribute is open for edit. To validate fields or block edit access when using this attribute, use additional checks in the page's custom Apex controller.



Reference:

https://help.salesforce.com/articleView?id=release-notes.rn_networks_entity_input_field_update_228.htm&release=228&type=5

Tuesday, 11 May 2021

Asynchronous Apex features and when to use each

 Hi,

Apex offers multiple ways for running your Apex code asynchronously.

We have to choose the asynchronous Apex feature that best suits your needs.

The following table lists the asynchronous Apex features and when to use each.

Asynchronous Apex FeatureWhen to Use
Queueable Apex
  • To start a long-running operation and get an ID for it
  • To pass complex types to a job
  • To chain jobs
Scheduled Apex
  • To schedule an Apex class to run on a specific schedule
Batch Apex
  • For long-running jobs with large data volumes that need to be performed in batches, such as database maintenance jobs
  • For jobs that need larger query results than regular transactions allow
Future Methods
  • When you have a long-running method and need to prevent delaying an Apex transaction
  • When you make callouts to external Web services
  • To segregate DML operations and bypass the mixed save DML error


Reference:

What’s the difference between Einstein Article Recommendations and Suggested Articles?

How Does Einstein Article Recommendations Work? Einstein Article Recommendations helps support agents resolve customer cases efficiently by ...