How to generate Debug Logs for Guest Users || Changes done in Winter’17 Release


Recently while working on public sites, I have noticed that debug logs are not getting generated for guest users in the same way it was used to work earlier. Debug log is always handy while working in Salesforce. It will help you to debug the problems, help you to understand the flow etc.

So while debug log was not getting generated, it became so difficult for me to debug the issues. After few hours of searching in Google, I have realized that in Winter’17 release, Salesforce changed the way of debug log generation for Guest Users. By “Guest User” I wanted to mean users having Guest User License.

The reason behind the change is – Public sites are getting used by many users(Guest Users). So setting up a debug log for Guest sUer may generate multiple debug logs which will quickly fill up the debug log. 

After Winter’17 release, Salesforce made some changes and due to that debug logs will be generated only for those targeted users. But what will differentiate those target users from the all other users using that public sites? Good questions. Answer to the question is that debug log will only be generated for those Guest users using the browser which has a special cookie. 


Really is it “Cookie”? Yes, now cookie will decide whether the debug log will be generated or not. 

Ok, the next question is how can I set that special “Cookie” in my browser? The answer is also very simple and below are the steps you need to follow –

  • Open the site in your browser. [Note – I am using Google Chrome, but any browser will work].
  • Open the Chrome DevTools console by right clicking in the page and opening the “inspect” section. 
  • Execute the below command to set the cookie –
  1. If the domain is .force.com domain, paste the below command in the console and execute – document.cookie=”debug_logs=debug_logs;domain=.force.com”;
  2. If you use the custom domain(say yourCustomDomain.com), paste the below command in the console and execute – document.cookie=”debug_logs=debug_logs;domain=yourCustomDomain.com”;
This new feature is available in both Lightning Experience and Salesforce Classic.
I hope this post will help you while debugging your public sites.
Please post your feedback. Thanks.


Salesforce Platform Developer – I Certification Tips


I have cleared another Salesforce Certification yesterday – It’s Platform Developer – I. In this post, I am going to share my study notes. Hopefully it will help others as well.

If you are an experienced developer or admin having more than 6 months of experience, it is very easy to clear this certification. But if you are new to Salesforce, then I think this study note is going to help you. I found 50% – 60% questions are scenario based.

During the exam, I am sure you will get multiple questions which will make you confuse in terms of more than one correct answers. My suggestion is that read the question/scenario 2-3 times, there will be one/two words which will lead to the correct answer. If you still not able to find the correct answer, mark the question for review and go to the next question. Don’t spend too much time in one question.

Note – Don’t treat this as a Certification dumps. Rather the intention of the post is to share my strategy, topics I covered during my preparation.

Another important point to mention here is that when I gave this certification the release from Salesforce was Winter’17. With every release, Salesforce brings new features so you need to go through the release notes as well.

Let’s start by topics mentioned in the Certification Syllabus. 
  1. Salesforce Fundamentals [Weighting: 10% i.e. # of Questions: 6]
    • Describe the considerations when developing in a multi-tenant environment
      • Study Guide:
      • Notes:
        • Keep tenant-specific data secure in a shared database so that one tenant can’t see another tenant’s data.
        • Customize various schema objects and an application’s user interface in real time without affecting the functionality or availability of the system for all other tenants.
        • Can the system’s code base be patched or upgraded without breaking tenant-specific schemas?
        • Will the system’s response time scale as tens of thousands of tenants use the service?
    • Describe how the Salesforce platform features map to the MVC pattern
      • Study Guide:
      • Notes:
    • Describe the capabilities of the core CRM objects in the Salesforce schema
    • Identify the common scenarios for extending an application’s capabilities using the AppExchange
    • Given a scenario, identify common use cases for declarative customization
      • Study Guide:
        • Scenario based question which will focus on test takers ability to identify whether to use formula, roll-up summary field, validation rule, workflow rule, process builder or approval process. Refer trailhead modules ‘process automation’ and ‘formula fields and validations’
      • Notes:
  2. Data Modeling and Management [Weighting: 12% i.e. # of Questions: ~8]
  3. Logic and Process Automation [Weighting: 46% i.e. # of Questions: ~28]
    • Describe how to programmatically access and utilize the object schema.
    • Describe the capabilities and use cases for formula fields.
      • Study Guide:
      • Order of execution:
        • Formula fields are executed/evaluated at access time, be it through VF page or API or Apex.
      • Formula Field Limitations:
        • The value of Formula field can’t depend on another formula field.
        • You can’t delete fields which is getting referenced in formula field.
        • You can’t use long text area, encrypted, or Description fields in formulas.
        • Default value formulas for a record type can only reference fields for that record type.
        • However formula fields and formulas for approval, validation rule can access fields from that object as well any object which are associated with that object either through lookup or master-detail relationship.
      • Formula Field Data Types:
        • Checkbox
        • Currency
        • Date
        • Date/Time
        • Number
        • Percent
        • Text
      • Cross-Object Formula Fields:
        • Cross-Object formula works with master-detail as well as lookup relationship. You need to make sure cross-object formula field is on the detail side of the master-detail relationship.
        • Cross-Object formula can reference fields from objects that are upto 10 relationships away.
        • Cross-Object formula referencing Currency field converts the currency value as per the record where the formula field is added.
        • However is the currency field is from a custom settings, then the value will not be converted.
        • Salesforce allows a maximum 10 unique relationships per object in cross-object formulas.
        • You can’t reference cross-object formulas in roll-up summary fields.
        • In cross-object formulas, you can’t reference merge fields for objects related to Activities. For example, merge fields for Account and Contact are not available in cross-object formulas in Task and Event object.
        • Important – While creating formula field, if you are referencing fields from an object where you don’t have read access, you will still be able to see the information. For example – If in the Case object, you are creating a formula field which is referencing fields from Account object and you don’t have read/view permission on Account object, you will still be able to see the information in Case page layout.
        • Important – Cross-Object formula is all about getting information of Parent object in Child object. So in the exam, if you are getting questions where you need to fetch child information in parent record, then it should be roll-up summary field.
    • Describe the capabilities and use cases for roll-up summary fields.
      • Study Guide:
      • Roll-Up Summary Field:
        • Roll-Up Summary Field works only the master-detail relationship.
        • Roll-Up Summary Field should be set in the master object.
        • When you delete a record in the detail side, Salesforce doesn’t recalculate the value of Roll-Up Summary field. Select the option Force a mass recalculation on this field on the edit page of the roll-up summary field to manually recalculate  the value.
        • Auto number fields are not available for aggregate in roll-up summary field.
        • Once you have created Roll-Up summary field, you can’t change the relationship to Lookup.
        • Changes to the value of Roll-Up summary field can trigger assignment rules to run.
        • A Roll-Up summary field can trigger workflow rules and field validations.
        • If your organization is having multiple currency, then currency on the master record will determine the currency of the roll-up summary field.
        • Salesforce will not allow updating/saving related records if it is violating validation rule on Roll-Up Summary field.
        • Fields that user cannot see due to FLS on the detail record are still calculated in a roll-up summary field.
        • Roll-up summary field is not available in the edit page. So they can’t be used as error location for your validation.
    • Describe the capabilities of the declarative process automation features.
      • Study Guide:
      • Notes:
        • If there is a situation where you need to choose between Process Builder and Workflow, you should always select Process Builder as Process Builder supersedes Workflow.
        • Workflow can update only parent fields in cross-object update whereas Process Builder can update either parent or child.
        • The only thing which you can do with Workflow, but not with Process Builder is send outbound messages without code. However, you can work around this limitation by calling Apex code from a Process Builder.
        • If the process is too complex for Process Builder, you should always go for Visual Workflow.
        • If you need to get information from customer, then Visual Workflow should be your solution approach. Based on the information received from user, write your logic to perform multiple logics.
        • Where approval is required, you need to go for Approval Process.
        • Check the below picture for capabilities –  https://trailhead.salesforce.com/business_process_automation/process_whichtool
    • Describe when to use declarative automation features vs. Apex classes and triggers
    • Describe how to declare variables and constants in Apex and how to assign values using expressions. 
    • Describe the primitive and complex Apex data types and when to use them.
      • Study Guides:
        • Topic should be covered by the above link
      • Notes:
    • Describe how to use and apply Apex control flow Statements.
      • Study Guides:
      • Notes:
        • Need to understand the difference between SOQL For Loops versus Standard SOQL Queries.
        • Standard SOQL Query can retrieve count as well number of sObject records.
        • SOQL For Loops always retrieve all sObjects using efficient chunking with calls to the query and queryMore methods of the SOAP API.
        • Developer should always use SOQL For Loop when handling with many records just to make sure they are not getting hit by the heap size limit.
        • Queries including an aggregate function don’t support queryMore.
        • SOQL For Loop can process records one at a time using a single sObject variable or in batches of 200 sObjects at a time using an sObject list. It is recommended to to go for batch option when you want to use DML statements within the for loop body.
        • Using inline SOQL query within SOQL For Loops can throw QueryException with the message “Aggregate query has too many rows for direct assignment, use For Loop”. This exception is thrown when accessing large number of child records(200 or more) of a retrieved sObject inside the For loop. To avoid such exception, we need to use a for loop to iterate over the child records and not to use inline SOQL query.
    • Describe how to write and when to use Apex classes and interfaces.
      • Study Guides:
      • Notes:
        • Inner class can’t have Static Variables. Only top-level class(outer class) variables can be declared static.
        • Inner class behaves like a static Java Inner class, but it doesn’t required the Static keyword. An inner class can have instance variables like an outer class, but there is no implicit pointer to an instance of the outer class(using the this keyword). So to access outer class variables inside inner class, you need to pass the reference of outer class to inner class by passing the this.
        • The private access modifier is the default.
        • The public access modifier means methods and variables can be used by any Apex in this application or namespace.
        • The global  access modifier means methods and variables can be used by any Apex that has access to the class, not just the apex code in the same application. If you are writing methods for SOAP API or if your method is going to be accessed by other Apex code, you should mark your method as global. A global  methods can only be put inside a global class.
        • Methods and classes are final by default.
          • The virtual  keyword allows extension and override.
          • The override keyword must be used to override the base class.
        • Interface methods are always global.
        • Classes and Interfaces can be defined in triggers and anonymous block, bit only as local.
    • Describe how to use basic SOSL, SOQL, and DML statements when working with objects in Apex.
      • Study Guides:
      • Notes:
        • Upsert will either create the new record or update the existing record. It will find the existing record based on the specified field to match. If nothing mentioned, it will match based on the ID value.
        • Merge  will merge upto three records of the same sObject type into one of the record, deleting the others and reparenting any related records.
        • You can retrieve all the fields including ID field for one sObject record, but you can’t do that with DML statements. You need to write SOQL for that.
        • DML Limit: 150 statements per Apex transaction.
        • For upsert, you can select any field which is marked as External ID for Custom Object. For Standard Object, you can select any field which has idLookup property set to true. For example – Email field of Contact or user has idLookup property set to true. So you can use those fields in upsert operation to match the existing record.
        • For upsert, the logic –
          • If key is not matched, new record will be created.
          • If key is matched, existing record will be updated.
          • If key is matched with multiple records, an error is generated and the object is neither inserted nor updated.
        • Delete will delete the record and place it in recycle bin for 15 days.
      • DML Exception:
        • If a DML statement failed, it returns an exception of type DmlException.
      • DML Exception:
        • Database methods have an optional allOrNone parameter that allows you to specify whether the operation should partially succeed.
          • allOrNone = false: Successful records will be committed and errors will be returned for the failed records. Also, no exceptions are thrown here.
          • allOrNone = true: This is the default value. Database methods behave like DML statements and will throw an exception if a failure is encountered.
        • Database.insert() -> Database.SaveResult[]
        • Database.upsert() -> Database.UpsertResult[]
        • Database.delete() -> Database.DeleteResult[]
      • Should we use DML Statements or Database Methods?
        • Use DML Statements if you want any errors which may occur during bulk DML operation should be reported back as an Apex exception and as a developer, you can take control of the errors by using try-catch block and stop the execution immediately.
        • Use Database methods if you want to allow partial success of bulk DML operation i.e. even if few of records failed, you want rest of the records to go ahead and succeed. Using this approach, you can stop sending Apex exception and you as a developer take care of the failed record separately through code.
    • Describe the basic patterns used in triggers and classes to process data efficiently.
    • Describe when to use and how to write triggers.
      • Study Guides:
      • Notes:
        • If a trigger was invoked due to DML operation from Apex, any one error will make the entire operation rolls back. However, the runtime engine will still process every record in the operation context to compile a comprehensive list of errors.
        • If a trigger was invoked due to bulk DML call/operation, runtime engine sets aside the bad records and attempts to do a partial save of the records that did not generate errors.
        • If a trigger ever throws an unhandled exception, all the records are marked with an error and no further processing takes place.
        • Trigger.new and Trigger.old can’t be used the DML operations.
        • You can’t delete trigger.new
      • Trigger and Merge Statements:
        • Merge events do not fire their own trigger event. Rather they fire delete and update events –        
          • Delete Event: A Single merge operation fires a single delete event for all losing records.When a record is deleted after losing in the merge operation, MasterRecordId field is set to the ID of the winning record. The MasterRecordId field is only set in after delete context.  
          • Update Event: A single merge operation fires a single update event for the winning record only. Any child records that are reparented as a result of merge operation do not fire triggers.
          • Following is the order of events when a merge occurs:
            • The before delete trigger occurs.
            • The system deleted the necessary records due to merge, assign new parent records to the child records, and sets the MasterRecordId field on the deleted records.
            • The after delete trigger fires.
            • The system perform the updates required for the master record. Normal update trigger happens.
      • Triggers and Recovered Objects:
        • The after undelete trigger event only works with recovered objects – i.e. the records that were deleted and then recovered from the Recycle Bin through the undelete DML statements.
        • The after undelete trigger runs only on the top-level objects. For example, if you delete an Account, an Opportunity which is associated with that Account will also get deleted. Now if you undelete the same Account from Recycle Bin, the associated Opportunity records will also be undeleted. But undelete trigger will only execute for Account, not for Opportunity.
      • Order of Execution:
    • Describe the implications of governor limits on Apex transactions.
    • Describe the relationship between Apex transactions, the save execution order, and the potential for recursion and/or cascading
    • Describe how to implement exception handling in Apex
      • Study Guides:
      • Notes:
        • List of Built-In Exceptions –
          • DmlException: Any problem with DML statements like insert statement missing a required field.
          • ListException: Any problem with List such as attempting to access an index that is out of bounds.
          • NullPointerException: No need the explain. World Famous Exception.
          • QueryException: Any problem with SOQL Queries, such as assigning a query that returns no records or more than one record to a singleton sObject variable.
          • SObjectException: Any problem with sObject records, such as attempting to change a field in an update statement that can only be changed during insert.
        • Common Exception Methods –
          • getCause
          • getLineNumber
          • getMessage
          • getStackTraceString
          • getTypeName
          • getDmlFieldNames(Index of the failed record): Returns the name of the fields that caused the error for that particular record.
          • getDmlId(Index of the failed record): Returns the ID of the failed record.
          • getDmlMessage(Index of the failed record): Returns the error message for the specified failed record.
          • getNumDml: Returns number of failed records.
    • Describe how to write Visualforce Controller 
    • Describe when and how to use Standard Visualforce Controllers vs. Apex Custom Controllers and controller extensions.
    • Describe the programmatic techniques to prevent security vulnerabilities in Apex and Visualforce.
    • Describe how Apex impacts the ability to make declarative changes.
  4. User Interface [Weighting: 10% i.e. # of Questions: 6]
  5. Testing [Weighting: 12% i.e. # of Questions: ~8]
  6. Debug and Deployment Tools [Weighting: 10% i.e. # of Questions: 6]
                                 

  • Important Topics:
    • Apex Controller, Controller Extensions and Custom Controller
      • Custom Controller and Controller Extensions run in System Mode. In order to make sure that Custom Controller and Controller Extensions respects user’s owd, role hierarchy and sharing settings, you need to mark them with with sharing keyword.
      • If a Controller Extension extends a Standard Controller, the logic from Standard Controller will execute in User mode i.e. it will respect OWD, role hierarchy and sharing settings.
      • A Visualforce Page can have one Standard Controller, but more than one Controller Extension classes.
      • Controllers are attached to the page using any of the below three mutually exclusive formats –
        • Standard Controller
        • Standard Set/List Controller
        • Custom Controller
      • You can’t do –
        • DML Operation in Constructor or getter/setter methods
        • @future method call from Constructor or getter/setter methods.
    • Standard Set Controller
      • ApexPages.StandardController encapsulates a single object
      • ApexPages.StandardSetController contains a list of records (one or more), and has additional methods to support pagination and update multiple records at the same time.
      • Instantiate a StandardSetController in two ways –
      • From a list of sObjects:
                  List allAccounts = [SELECT ID, Name FROM Account LIMIT 200];
ApexPages.StandardSetController ctrl = new ApexPages.StandardSetController(allAccounts)

From Query Locator:
ApexPages.StandardSetController ctrl = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT ID, Name FROM Account]));
      • The maximum record limit for SetController is 10,000 records.
      • When Initializing a StandardSetController with Query Locator and if Query Locator is returning more than 10,000 records, LimitException will be thrown.
      • When Initializing a StandardSetController with list of sObjects and if the list contains more than 10,000 records, no exception will be thrown. Rather it will truncate the records to the limit.
    • Page Reference
      • PageReference is a reference to instantiate a page.
      • Use PageReference for –
        • To view and set query String parameters and their values for the page
        • To navigate to a difference page as a rest of an action method
      • You can instantiate a page in below different ways –
        • Page.existingPageName where existingPageName is the VF Page Name
        • PageReference pageRef = new PageReference(‘*** PARTIAL URL ***’); Here PARTIAL URL /apex/HelloWorld refers to https:///apex/HelloWorld.
        • PageReference pageRef = new PageReference(‘*** FULL URL ***’);
        • PageReference pageRef = new PageReference(‘https://www.sudipta-deb.blogspot.com’);
        • PageReference pageRef = ApexPages.currentPage();
      • To navigate to a new page, make setRedirect(true);
    • Components we can’t deploy with Metadata API:
I hope this post will provide you the guidance to clear Platform Developer – I. Provide me your feedbacks and please share with greater audience if you think it is helpful. Please let me know if you have any queries. 

Finally Wishing You BEST OF LUCK. 

All about Git – “Git Stash” Part – II

In this post, I am going to discuss on a very powerful command “git stash“. It is a very powerful command and that is why I want to dedicate a single blogpost discussing only about this important command.

WHAT IS GIT STASH:
This command will temporarily shelve the changes you’ve made to your working copy so that you can work o something else, and then come back and re-apply those changes at later point in time.

HOW TO STASH YOUR WORK:
The command git stash takes the uncommitted changes (both staged and unstaged) and saves them away for later use, thus reverting them from your working copy.
For example, I have two files “test.txt” and “NewOne.txt”. Out of these two files, “test.txt” is staged and ready to be committed whereas the file “NewOne.txt” is yet to be staged.
So if I issue the command git status, below is the result –

Now if I issue the command git stash, let’s see what happens –

So if I open the file, I will notice that all my changes to these two files are gone. But where? How can I get those changes back? So many questions!! :-) I will come into each of these questions slowly.

One important point to tell here is that stash is local to your Git repository; stashes are not transferred to the server when you push.

HOW TO RE-APPLY THE STASHED CHANGES:
One can re-apply the stashed changes by using the command git stash pop.

So basically popping the stash means removes the changes from the stash and re-applying then back to your working directory. That is why you see the two files back again in the status “Ready to be staged” after git stash pop done.

There is another command which will re-apply the stash to the working directory, but now delete the changes from stash, This is useful when you want to re-apply the same stash into multiple branches.
The command is:  git stash apply

Note – There is a very important point about stash. Git will not stash changes that are untracked or marked in the ignored file. By untracked, I wanted to mean if the file is not added by using the command git add before. For that you need to use -u option  to include the untracked files during stashing operation. The command is: git stash -u

AWESOME, BUT HOW I WILL MANAGE MULTIPLE STASHES:
You can run git stash multiple times to create multiple stashes and finally run git stash list will tell you all the stashes you have created.

If see the above picture, I have issued the command git stash twice. After that when I issued the command git stash list, it provided me two stashes – stash@{0} and stash@{1}

To give a more meaningful name of the stash, you can add your comments while doing the stash (The command is: git stash save “YOUR COMMENT”) and then git stash list will show you the comment against the stash. See the screenshot below –

By default git stash pop will always re-apply the most recent created stash i.e. stash@{0}. If you want to stash something else, you need to provide the stash identifier as an argument like –
git stash pop stash@{3}

HOW TO VIEW STASH DIFFS:
You can view the summary of a stash by – git stash show.

To get the full details/diffs pas the parameter -p like below –


OK GREAT, BUT CAN I DO PARTIAL STASH?
Yes, you can do partial stash as well by passing the parameter -p with the command git stash. See the below screenshot –

The options which you can choose for partial stash are –


CREATE A BRANCH FROM STASH:
You can create a branch from a stash by below command –

This is required when your branch changed a lot and re-applying your stashes can bring conflicts. In  this scenario, you will prefer to create a branch from your stash and there apply your changes.

FINALLY, CAN I  CLEAR STASH?
Yes, you can clear stash by issuing the command git stash drop stash@{3}. This command will drop only stash@{3}. But if you want to delete all the stashes, then the command is: git stash clear.

I hope you have idea with git stash now. Please feel free to provide your feedback. Thanks.

To learn more, here are the links –

All about Git – Cheat Sheet – Basic Part – I

WHAT IS GIT?

In today’s world, the most widely used modern version control system is Git. Git is a mature, actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel.
SETTING UP A REPOSITORY:
Git uses the below command to create a new Git repository.
git init
Executing this command will create a .git subdirectory in the project root and transforms the current folder into a git repository.

The below command will create a new folder named directory and initialize the repository by creating .git subdirectory
git init

BARE REPOSITORY:
The below command will create the bare repository.
git init –bare
The –bare flag will create a repository which is having no active working directory. This is very important. You should always consider creating your central directory as a bare directory and from there create all your branches (non-bare directory) where the developers will work. Once the work is done, developers will merge their code from branches (non-bare directory) to central repository(bare directory). Since the central repository is bare directory and does not have any active working directory, there is no chance of editing the files and committing them.

CLONING AN EXISTING REPOSITORY:
The git clone command copies an existing Git Repository. Cloning always creates a remote connection called origin pointing back to the original repository. This makes it very easy to work with the central repository.
The below command will clone the repository “https://github.com/suddeb/TestRepository.git” to the folder TestRepo in my local machine.

git clone https://github.com/suddeb/TestRepository.git TestRepo


GIT CONFIGURE:
The git config command will configure the Git installation from the command line.
Below command will configure the Author name to be used for all commits in the current repository by the current user.
git config –global user.name “Sudipta Deb”
Below command will configure the Author email to be used for all commits in the current repository by the current user.
git config –global user.email “sudipta.deb@gmail.com”

SAVING CHANGES:
The git add command adds a change in the working directory to the staging area. Basically, it will inform git that you want to include this change in your next commit.
Below command will add the file “test.txt” from working directory to staging area making it available for next commit.
git add test.txt
Here is the screenshot of my command prompt:

So if you see once I changed the test.txt file, git status command is telling me that I have changes not staged for commit. After that, I have used the command git add test.txt to add the file to staging area. Once done, issues the command git status is telling me something different that I have now changes ready to be committed.

GIT COMMIT:
The git commit command commits the staged snapshot to the project history. Below is the command which will commit the previously staged file test.txt into local repository. Don’t be confused? I will explain what is local repository very soon.
git commit -m “My First Commit”

So once your commit is done, if you issue git status it will tell you that you have nothing in the staging environment to be committed.

WHAT IS LOCAL REPOSITORY?
In Git, snapshots are always committed to local repository. This is one of the fundamental difference between Git and SVN/CVS. In SVN/CVS, you will always commit against the central repository, whereas in Git you don’t need to interact with central repository until and unless you are ready to do that. All your commits are stored in the local repository. Consider staging area as the buffer between your workspace and project history, similarly each developer’s local repository is the buffer between their contribution and central repository.

There are some other fundamental differences between Git and SVN. Where SVN tracks the differences of a file, Git’s version control mechanism is based on snapshots. Below picture will help you to understand the differences between SVN/CVS(Centralised Version Control System) and GIT(Distributed Version Control System)

In my next post, I will talk about Git Stash. One of my favorite command and you can play with this command. Till then, enjoy version controlling. Provide me your feedback. Thanks.

How to choose between Trigger and Lightning Process Builder

With the introduction of Lightning Process Builder, we can do many things which were kind of limitations of Workflows. Salesforce introduces Lightning Process Builder as successor of Workflow rules, thus allowing more config options through click and reducing amount of apex customization required. Process Builder supports all the features from Workflows with the exception of sending outbound message without apex code. I will not be surprised if Salesforce decides to decommission Workflow in near future.

Previously there were few scenarios (listed below) which were not possible through workflow and we need to write Apex trigger to achieve those. Here are few of them –

  • If we need to perform complex validation
  • Before/After logic for record insert/update/delete/undelete operation.
  • Update/insert any objects or related records.
Problem with workflow is we can’t update child records with workflow. Workflow supports only updation of parent record. So earlier we need to go for Trigger. But with the introduction of Process Builder, now we can update child records as well. Below is one case study –

Case Study:
It’s a library management system – Universal Library. Library is having many books. If the book is not available, user will send the request for the book. The moment book is available, all the request status will change from ‘Hold’ to ‘Ready to Pickup’. To achieve this below is the object model –
Here Book and Book Request are connected through Master-Detail relationship. Previously to achieve this requirement, we need to write Apex classes. But now we can do the same with Process Builder. Below is the screenshot of Process Builder –
With Process Builder you can add conditions to update selected records. For example, if library is having membership types – Gold, Silver, Broze, once a book is available, update only those requests which came from Gold membership holder and make them “ready to pickup”.
There are few situations(sending outbound message) which can’t be handled through config in Process Builder. For that, we need to write Apex class/method. We need to make sure your method is annonated with @InvocableMethod so that it can be used in Process Builder. With Invocable methods, there are few limitations, which we need to keep in mind. Limitations can be found @ https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm
Excited, right!! If you want to convert existing Apex Trigger to Process Builder, please keep in mind the below points –
  •  You need to make sure that in your trigger any field update is not used by subsequent trigger or workflow. The reason behind is that execution order wise Process Builder will execute after workflow rules.
  • With enabling Recursion option in Process Builder, one record can be reevaluated maximum 5 times. So you need to make sure you are not disturbing Salesforce limits here.
Scenarios where Trigger is the best approach:
There are still scenarios where Apex Trigger is the best approach. I am trying to write down few of them. If you have anything in your mind or faced any issues during your development for which you have moved to Apex Trigger, please feel free to let me know. I will be more than happy to include those scenarios.
  • Complex Validation Rules in not possible with Process Builder. You need to got for Apex trigger to achieve that. Here is the Salesforce Idea to add Validation rule capability in Process Builder – Salesforce Idea.
  • Apex Trigger’s context – Delete/Undelete with before/after even is not possible with Process Builder.
I will really appreciate if you provide your feedback. Thanks.