Category Archives: Salesforce

OWD for Standard Objects in New Org

The default organization-wide sharing settings for Standard Objects are:

Object Default Access
Account Public Read/Write
Activity Private
Asset Controlled by
Parent
Calendar Hide Details and Add Events
Campaign Public Full Access
Case Public Read/Write/Transfer
Contact Controlled by Parent
Contract Public Read/Write
Custom Object Public Read/Write
Lead Public Read/Write/Transfer
Opportunity Public Read Only
Price Book Use
Service Contract Private
Users Public Read Only
Private for external
users

Public Full Access:
This option is available for setting the Campaign object only along with other access options. Through public access the user can have the ability to search records, reports, add related records, edit details of the records and can delete the record.
When the Campaign object is set to public full access, all users in that organization can be able to view, edit, transfer and delete.

Public Read/Write/Transfer:
This option is available for Leads and Cases objects only along with other access options. When lead or case objects are set to public read/write/transfer, then all users can view,edit, transfer and report on all the case and lead records.

Public Read/Write:
Whenever a record is set to public read/write the user can view, edit and report on all the records.

Public Read Only:
When a record is set to public read-only the user can search the records, view and report on every record but the user cannot edit that record. Only record owners and assigned users can edit that records.

Private:
When a record is set to private only that record owner and users above that role in an hierarchy can view, edit and report on those records.

Read REST API GET Parameters in Apex Class

URL: /services/apexrest/AccountAPI?id=AccountId
Method: Get

@RestResource (urlMapping='/AccountAPI/*')
global with sharing class AccountRESTService {
    @HttpGet
    global static Account getAccount() {
        RestRequest req = RestContext.request;
        String accountId = req.params.get('id');
        Account acc = [SELECT Id, Name FROM Account WHERE Id =: accountId];
        return acc;
    }
}

URL: /services/apexrest/AccountAPI/AccountId
Method: Get

@RestResource (urlMapping='/AccountAPI/*')
global with sharing class AccountRESTService {

    @HttpGet
    global static Account getAccount() {
        RestRequest req = RestContext.request;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account acc = [SELECT Id, Name FROM Account WHERE Id =: accountId];
        return acc;
    }
}

Difference Between Inbound and Outbound Web Service in Salesforce

Inbound Web Service:
Inbound web service is when Salesforce exposes SOAP/REST web service, and any external/third party application consume it to get data from your Salesforce org. It is an Inbound call to Salesforce, but outbound call to the external system. Here, Salesforce is the publisher and external system is the consumer of web services.

Outbound Web Service:
Outbound web service is when Salesforce consume any external/third party application web service, a call needs to send to the external system. It is an Inbound call to the external system, but outbound call to Salesforce. Here, external system is the publisher of web services and Salesforce is the consumer.

There are two commonly used web service:

    • SOAP(Simple Object Access Protocol)
      • SOAP is a web service architecture, which specifies the basic rules to be considered while designing web service platforms.
      • It works over with HTTP, HTTPS, SMTP, XMPP.
      • It works with WSDL.
      • It is based on standard XML format.
      • SOAP Supports data in the form of XML only
      • SOAP API preferred for services within the enterprise in any language that supports Web services.
    • REST (Representational State Transfer)
      • REST is another architectural pattern, an alternative to SOAP.
      • It works over with HTTP and HTTPS.
      • It works with GET, POST, PUT and DELETE verbs to perform CRUD operations.
      • It is based on URI.
      • REST Supports both XML and JSON format.
      • REST API preferred for services that are exposed as public APIs and mobile, since JSON being Lighter the app runs smoother and faster.

Queueable Apex in Salesforce

The class which implements the Queueable interface are basically called as Queueable apex class. This interface enables you to add jobs to the queue and monitor them, which is an enhanced way of running your asynchronous Apex code compared to using future methods. The interface has only one method execute which takes the parameter of QueableContext.

For Apex processes that run for a long time, such as extensive database operations or external Web service callouts, you can run them asynchronously by implementing the Queueable interface and adding a job to the Apex job queue. In this way, your asynchronous Apex job runs in the background in its own thread and doesn’t delay the execution of your main Apex logic. Each queued job runs when system resources become available. A benefit of using the Queueable interface methods is that some governor limits are higher than for synchronous Apex, such as heap size limits.

It allows you to submit jobs for asynchronous processing similar to future methods with with these additional benefits:
Non-primitive types: Your Queueable class can contain member variables of non-primitive data types, such as sObjects or custom Apex types. Those objects can be accessed when the job executes.
Monitoring: When you submit your job by invoking the System.enqueueJob method, the method returns the ID of the AsyncApexJob record. You can use this ID to identify your job and monitor its progress, either through the Salesforce user interface in the Apex Jobs page, or programmatically by querying your record from AsyncApexJob.
Chaining jobs: You can chain one job to another job by starting a second job from a running job. Chaining jobs is useful if you need to do some sequential processing.

Example:
This example is an implementation of the Queueable interface. The execute method in this example inserts a new account.

public class QueueableExample implements Queueable {

    public void execute(QueueableContext context) {
        Account acc = new Account(Name='Biswajeet');
        Insert acc;        
    }
}

To add this class as a job on the queue, call this method:

ID jobID = System.enqueueJob(new AsyncExecutionExample());

After you submit your queueable class for execution, the job is added to the queue and will be processed when system resources become available. You can monitor the status of your job programmatically by querying AsyncApexJob or through the user interface Setup || Monitoring || Apex Jobs.

To query information about your submitted job, perform a SOQL query on AsyncApexJob by filtering on the job ID that the System.enqueueJob method returns.

AsyncApexJob jobInfo = [SELECT Status,NumberOfErrors FROM AsyncApexJob WHERE Id=:jobID];

Test class for Queueable Jobs:

@isTest
public class AsyncExecutionExampleTest {
    static testmethod void test1() {
        //startTest/stopTest block to force async processes to run in the test.
        Test.startTest();        
        System.enqueueJob(new AsyncExecutionExample());
        Test.stopTest();

        Account acct = [SELECT Name FROM Account WHERE Name='Biswajeet' LIMIT 1];
        System.assertNotEquals(null, acct);
        System.assertEquals('Biswajeet', acct.Name);
    }
}

Note:

  • The execution of a queued job counts once against the shared limit for asynchronous Apex method executions.
  • You can add up to 50 jobs to the queue with System.enqueueJob in a single transaction.
  • Limits.getQueueableJobs() helps to check how many queueable jobs have been added in one transaction.
  • No limit is enforced on the depth of chained jobs, which means that you can chain one job to another job and repeat this.
  • You can add only one job from an executing job with System.enqueueJob, means that only child job can exist for parent queueable job.
  • For Developer Edition and Trial organizations, the maximum stack depth for chained jobs is 5.

Difference Between Deactivate User and Freeze User in Salesforce

Deactivate User:

  • Deactivating a user in Salesforce means that user will not be deleted from the system but will no longer be able to log in to Salesforce and their records can be transferred to another user. They cannot be part of workflows or part of any automated processes.
  • Deactivating a user will be available user licenses available for use in your organization.
  • Deactivated users lose access to any records that were manually shared with them, or records that were shared with them as team members. Users higher in the role hierarchy relative to the deactivated users also lose access to those records. However, you can still transfer their data to other users and view their names on the Users page.

Freeze User:

  • Freezing a user in Salesforce means that only stops the user from being able to login.
  • In some cases, you can’t immediately deactivate a user (such as when a user is selected in a custom hierarchy field or a user that’s assigned as the sole recipient of a workflow email alert). To prevent users from logging into your organization while you perform the steps to deactivate them, you can freeze user accounts.
  • Freezing user accounts doesn’t make their user licenses available for use in your organization.