Saturday, 31 August 2019

Trigger Framework Salesforce

In ApexHours we did one session on Apex Trigger Framework in Salesforce with ADAM OLSHANSKY. In that session we talk about what is a benefit of using a trigger framework, How many trigger framework are available, which one is lightweight apex trigger framework and Comparison of different approaches.

In that session we talk about all below Trigger Framework
1) Trigger Handler Pattern
2) Trigger Framework using a Virtual Class
3) Trigger Framework using an Interface
4) An architecture framework to handle triggers

Why Trigger Framework ?

 A framework may, however, greatly simplify your development efforts when your code base gets large. In a nutshell, your framework should have the following goals:-
  1. Generic code that can be extended for any object
  2. Ensures triggers are consistently handled and only required code is needed
  3. Allows for simple Triggers and Handlers
  4. Handles routing for you
  5. Enforces consistent trigger behavior
  6. Easily allows for trigger bypasses

Trigger Handler Pattern

Please check this post to learn about Handler pattern and code. Lets talk about what is the advantage of Trigger Handler Patter.
  1. Apex Class that handles trigger logic
  2. Allows code to be called from other code or tests
  3. Uses specific Trigger contexts and Trigger variables for routing
  4. Keep Triggers Simple
  5. Allow for greater flexibility
  6. Make code reusable
  7. Unit tests are much easier

Please check this recording for code walk-through. What is missing in Handler pattern ?
  1. Still duplicated code in every trigger
  2. How can we simplify things?
  3. How can we make our process repeatable?

Trigger Framework using a Virtual Class

 Please check this post to learn more about Virtual Class Trigger Framework.

Please check this recording for code walk-through. Accomplishments with this Trigger framework :-
  •  1 line trigger
  • Only need to add handler methods that we want to use
  • All routing is handled for us

Trigger Framework using an Interface

 Please check this post to learn about this framework.

 Please check this recording for code walk-through. Accomplishments with this Trigger framework :-

  • 1 line trigger
  • All routing is handled for us
  • All handlers are consistent and will have the same methods
  • Multiple ways to deactivate a trigger

An architecture framework to handle triggers

 Please check this post to learn about this framework.

Please check this recording for code walk-through. Accomplishments with this Trigger framework :-
  • 1 line trigger
  • All routing is handled for us
  • Establish all methods while letting us pick and choose which ones we want
  • Individual event handler methods

Please check our YouTube Recording to learn more about all Trigger Framework and Code.

Here is link for all frameworks:-


Monday, 19 August 2019

Create Object From Spreadsheet | Excel sheet | Lightning Object Creator

Now Converting excel spreadsheet data into Salesforce Objects is every easy. In Dreamforce 18, Salesforce promised to make app creation easier and faster when they introduced Lightning Object Creator. With the Lightning Object Creator, it only takes a few steps to translate the spreadsheet columns into fields, define field types and import all the spreadsheet data. With Lightning Object Creator, Salesforce is expanding integrations with Google Cloud.

This feature helps user to create mass number of fields (using excel template) of different field types in few clicks.

NOTE: You will be able to see it in your sandbox(es) from August 7 2019 or if you go to this link:

Lets see how it will work :-

Turning spreadsheets into custom objects is as easy as three simple steps.

Step 1) Navigate to  Lightning Object Creator

Click on Setup->Object Manager-> Then Select Custom Object From Spreadsheet.

Step 2) Upload Spreadsheet.

Now upload the spreadsheet from your computer, google sheet or Office 365 or Drive.

After uploading the Excel sheet Salesforce will automatically detect the fields. You can customize the Salesforce field name and field type. Additionally, you can choose to add a particular field to a page layout directly as well like below screen.

You can also view the data preview after click on below selected button

Step 3) Setup Object Properties

You can control of the object’s permissions including enabling chatter for the object, allowing search and reporting.

Some Important Point
  1. By default your excel file tab name will become Object name, we can change the Object name after uploading the file into Salesforce
  2. We can not create formula field, relationship fields and Rollup summary field.

For more detail please check below post


Amit Chaudhary
Capture.JPG  @amit_sfdc    @ApexHours
  Salesforce Apex Hours 

Saturday, 6 July 2019

Events in Lightning web components (LWC) | Communicate with Events

In this post we will talk about how to use the lightning web component events to communicate between components. Events in Lightning web components are built on DOM Events, a collection of APIs and objects available in every browser. Here we will be see how to the events using the CustomEvent interface and publish-subscribe utility.

Component Communication through events

There are typically 3 approaches for communication between the components using events.

  1. Communication using Method in LWC ( Parent to Child )
  2. Custom Event Communication in Lightning Web Component (Child to Parent )
  3. Publish Subscriber model in Lightning Web Component ( Two components which doesn't have a direct relation )

Tuesday, 2 July 2019

Field Level Security in SOQL With SECURITY_ENFORCED

Salesforce introduce the "WITH SECURITY_ENFORCED" clause in Spring 19 as beta. By using With SECURITY_ENFORCED clause in SOQL we can check the field and object level security in SOQL. To use this, just add the WITH SECURITY_ENFORCED clause in SOQL SELECT queries. If there are any fields or objects referenced in the SELECT clause that are inaccessible to the user, an exception is thrown and no data is returned

Here is sample code :-


Now we don't need to check field accessibility in Apex using Schema function. Before to With SECURITY_ENFORCED we used to check field level security like below

if( Schema.SObjectType.Account.Fields.Name.isAccessible() &&
    List<Account> accList = [Select Name,Phone from Account Limit 100];

Now we just need to add "With SECURITY_ENFORCED" in SOQL query like below code :-

   List<Account> accList = [Select Name,Phone from Account WITH SECURITY_ENFORCED ];

} catch( System.QueryException ee) {

    System.debug('You dont have access to all Account fields ');

  1. With SECURITY_ENFORCED is available in Apex only.
  2. Available in API version 45.0 or greater. This is available in Beta. 

Please check below post for more detail

Amit Chaudhary

Thursday, 20 June 2019

Asynchronous Apex Triggers | Change Data Capture | Change event trigger

There are many way of asynchronous processing in Salesforce like Future method, Queueable Apex , Batch job, Scheduler Apex and etc. In Summer 19 release Salesforce provide another feature called "Asynchronous Apex Triggers" that can process data asynchronously with the help of Change Data Capture.

A change event trigger is an “after-insert” trigger. The trigger fires after the change event message is published. You can create an after-insert trigger in the Developer Console the same way you create an Apex object trigger after enabling the object for Change Data Capture. To enable the objects for receiving change notification follow below step :-

Setup-> Integrations -> Change Data Capture.

Lets see how we can create the Asynchronous Apex Triggers.

You can create an after-insert trigger in the Developer Console the same way you create an Apex object trigger. When you create a trigger, pick the change event object from the sObject dropdown, which is populated with the change events available in your org.

Asynchronous Apex Trigger

trigger AsyncAccountTriggers on AccountChangeEvent (after insert) {


Some Important point to consider :-
  1. Here is list of supported object
  2. For a standard object, the change event name is StandardObjectNameChangeEvent for example AccountChangeEvent
  3. For a custom object, the change event name is CustomObjectName__ChangeEvent for example Employe__ChangeEvent (suffixed as __ChangeEvent) 
  4. Asynchronous Apex triggers are change event triggers that run asynchronously after a database transaction is completed
  5. Available for After Insert Event only
  6. With Asynchronous Apex Trigger we can move complex computations and logic out of the transaction 
Last week we did one session in Asynchronous processes. Here is recording of session

Some Important Link :-

1) Salesforce blog post :
2) Release Note :
3) Trailhead module :

Amit Chaudhary

Monday, 13 May 2019

Single Sign on Between Two Salesforce Org ( Federated Authentication (SAML) based SSO ) | SSO | SAML | Single sign on salesforce

Single sign-on is a process that allows network users to access all authorized network resources without having to log in separately to each resource. Single sign-on allows you to validate usernames and passwords against your corporate user database or other client application rather than having separate user passwords managed by Salesforce. In this post we will talk about Single Sing on Salesforce two orgs.

Options for Implementing SSO on


1) Delegated authentication

Using delegated authentication, does not validate passwords but instead uses an external Web service to validate user credentials. When a user attempts to login, the platform checks the user's profile to see if they are enabled for SSO. If so, it makes a Web services call to the the endpoint specified for the organization (environment), asking it to validate the username and password. The Web services checks the credentials against an identity store (for example LDAP or OpenID) and either returns "true" or "false". If true, the user is granted access to the application and proceeds normally. If false, the user is informed that their credentials are invalid.


2) Federated Authentication

As with delegated authentication, federated authentication does not validate the user's actual password on the platform either. Instead, the platform receives a SAML assertion in an HTTP POST request. The SAML assertion has a limited validity period, contains a unique identifier, and is digitally signed. If the assertion is still within its validity period, has an identifier that has not been used before, and has a valid signature from a trusted identity provider, the user is granted access to the application. If the assertion fails validation for any reason, the user is informed that their credentials are invalid. The rest of this article shows how to set this up.


About SAML

Security Assertion Markup Language (SAML) is an XML-based standard that allows you to
communicate authentication decisions between one service and another. It underlies many Web single sign-on solutions.


How to Implement SSO between two Salesforce orgs


To setup Single sign on between two Salesforce Org we need to setup one Salesforce Org as Service provider and other one as Identify provider
Identify provider (IDP) :- An identity provider is a trusted provider that lets you use single sign-on (SSO) to access other websites
Service provider (SP):- A service provider is a website that hosts apps.

Configuring Single Sign-On

Step 1 : Enable My Domain in IDP and SP Org

First step is to enable "My Domain" in both Salesforce org. This functionality will provide a unique name to your salesforce org.
  1. Click on “My Domain”

  2. Deploy each 'My Domain' to your users

Step 2: - Enable the Identity Provider in your IDP Org

Login to your IDP org and Navigate to Identity provider. Setup-> Security Controls -> Identity Provider.

In all new developer org your will found "Identity provider" is already enable like below screen

NOTE:- Make a note of Salesforce Identity endpoint URL which we will soon.

If you are using old developer org then you need to enable "Identity provider" and need to create Certificate like below screen

Step 3: Add Remote Site setting in SP Org

Now login to your SP org and add your Identity provider domain URL in SP org like below
Setup -> Security -> Remote Site Setting


Step 4: Enable Single Sign On in SP Org

  1. Enable Single Sign on. Navigate to “Setup > Identity > Single Sign-On Settings” and check “SAML Enabled” option.
  2.  Now provide SAML Single Sign on Setting detail. You can also download the certificate from step 2 with download certificate button and upload here with "New from Metadata file" button. But We will use New from Metadata URL here. Now we will use same URL which we coped in step2.
    Dont do any change in below screen. Do only one change that SAML Identity Type as Federation ID
    Make a note of Entity ID and Login URL from here. We will use same in IDP org Connected App

Step 5: Create Connected App in IDP Org

Now go back in your IDP org. And create one connected app with below step
  1. Create connected app, Setup -> App Manager -> New Connected App
  2. Now provide all required detail. Make sure on your connected App you need to perform below step
    1. Enable SAML
    2. Provide Entity Id (Use Entity ID from Step 4)
    3. ACS URL (Login URL from Step 4)
    4. Subject type should be Federation Id. 
    5. IDP Certificate as Identity Provider Label name
    6. Now once Connected app is ready. Click on Manage Button. Then Add the profile from related list.

Step 6: Update Authentication Configuration for my Domain in SP Org

Now go to SP org the navigate to My Domain (Setup -> My Domain). Then edit the Authentication configuration setting and select the IDP org in Authentication service.

Step 7: Test your configuration

Now its time to test our Single sign on.
  1.  Create one user in both org with same "Federation ID". 
  2. Then first login into Identity provider org. Then go your connected app -> Click on Manage . Then click on "IdP-Initiated Login URL" URL to check your Single sign on.
  3. Now all set. I hope Single Sign on is working fine :). But if you want to add a app in app App Launcher then edit your connected app and your IdP-Initiated Login URL in "Start URL" in above screen.
  4.  Now you can check SSO with App Launcher.

We did the same session in ApexHours as well with Atul. Please check below recording for SSO.

Agenda :-
  • Core Concepts
    • Single Sign On
    • Social Sign-On
    • Identity Provider
    • Service Provider
    • Authentication
    • Authorization
  • Advantages of Identity management
    • Centralized Control
    • Security
    • Policy Updates
    • Easy to use
  • Demo 1: Salesforce as Identity Provider
    • Steps to set Salesforce as IP
  • Demo 2: Salesforce as Service Provider
    • Steps to set Salesforce as SP
  • Other IDPs in market

If you want to learn about Azure Active Directory Seamless Single Sign-On with Salesforce please check this post .

Amit Chaudhary

Sunday, 28 April 2019

Salesforce Org Health Check | Security Health Check | Apex PMD Tools | Checkmarx

"It is health that's real wealth and not items of gold and silver", is something that very aptly applies to orgs as well. You do not need a org plagued with problem like CPU timeouts, Query timeouts and Row Lock errors. And the good part is that you simply yourself can be the doctor of your org.

The things can be as simple as checking the storage stats of the objects in your org or analysing the way your batches are scheduled and the time they take for execution. The next step after the analysis is complete is to provide remediation to the caused issues. And that is not too hard either. The main aim is to make small but necessary changes to the configuration of your system, while keeping the behavior intact and without compromising the performance.

We did one session in ApexHours with Saket Joshi on sale topic.

In that session we covered the frequency of performing these health-checks on your org to ensure scalability of the system. Once the issues are fixed, it is expected to have improved system performance and less issues caused because of either concurrency or data fragmentation.

Some Key Point :-

Your Salesforce org is unwell?

Identifying the wellness of your org

  1.     Performance Issues
  2.     Data Storage Limitations
  3.     Scalability and Planning
  4.     Record Locking & Contention

Symptoms of an Unhealthy Salesforce Org

Symptoms of an Unhealthy Salesforce Org

  1.     Storage Limits Exceeded
  2.     Frequent Issues
  3.     Record Locking & Contention
  4.     Unnecessarily Installed Packages
  5.     Concurrent and Ever-Running Batch Classes



  1.     Generate a report of issues found
  2.     Prioritizing the issues
  3.     Organizing the issues by complexity
  4.     Solutioning a quick-fix to the issues

Tools for Diagnosis

Some Common Tools for Diagnosis

  1.     Salesforce Health Checker ( URL)  
  2.     ApexPMD Tool ( URL )
  3.     Checkmarx Apex Code Scanner ( URL )  
  4.     Salesforce Accelerators (URL)   
  5.     Manual Org Assessment



1) Analyse and fix the record skew

  • Decentralization of records

2) Data Archival & Cleanup

  • Deletion of unnecessary data
  • Using third-party APIs (Amazon Cloud)

3) Fix the row lock issues

  • Avoid parallel processing
  • Using SOQL locks

4) Avoid the CPU Timeouts and/or Query Timeouts

  • Field Indexing
  • Using Async Apex for long running operations
  • Optimizing the query/report filters
  • Database refactorization

5) Uninstalling unwanted packages

6) Rescheduling the batches & schedulers

  • Analyse batch duration & change batch chunk size
  • Simultaneous running of non-related batches
  • Deciding the frequency

Here is recording of session.

Amit Chaudhary 
Capture.JPG  @amit_sfdc    @ApexHours
  Salesforce Apex Hours