Month: October 2016

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 validationBefore/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...

Read More

How to choose correct Process Automation tool || Process Builder vs. Visual Workflow vs. Workflow vs. Approval Process

With process automation, we now have multiple solutions available which we can use to implement the requirements. The solutions that we have are -Lightning Process BuilderVisual WorkflowWorkflowApprovalsWith so many options, it brings responsibilities as well to the developer to decide which tool to use. In this post, I will try to provide a comparative study on which tool is best based on some situations. But at the end, it is upto you as a developer to decide and select the best tool available. I hope this post will help you to take the decision.Let’s start with the easy one -Approval Process ::As the same suggests, whenever you need to take approval actions, you need to go for Approval process. This is an automated solution which will work based on the record creation or record value change. Below are few important points about approval process -Complexity of Approval process is very simple. It can support only one if/then statement.It doesn’t support time-based approval process i.e. trigger the approval after 24 hours or something like that. It is a complete real-time solution.Approval process can’t call Apex code or delete any records.But Approval process can create only Tasks (nothing else).Approval Process can update the same record or it’s parent.Workflow :;Workflow is the automation tool which should be used when you need to take action based record creation or record’s value change. Below are few important points...

Read More

Dynamic Apex – Build Dynamic SOQL and SOSL

In this post, I will explain another very powerful feature of Dynamic Apex i.e. Dynamic SOQL and SOSL.   Dynamic SOQL: Dynamic SOQL refers to the ability of creating SOQL statement in runtime with Apex code i.e. you can select which fields you want to query based on situation or user input and then prepare the SOQL statement and finally perform the query to fetch the data from the organisation. You can execute the below statement to perform the query: Dynamic SOQL can return concrete sObjects i.e. Account, Lead or MyCustomObject__c or the generic sObject data type. At runtime, system will match the return type with the variable’s declared type. If the types are not matching, then runtime will be thrown. So it is the responsibility of the developer to cast from generic sObject data type to a concrete sObject. In terms of governor limits, Dynamic SOQL queries have the same governor limits as static queries. Below example is going to fetch the fields from Account sObject, prepare the SOQL statement and then finally query Account sObject to fetch the data. Dynamic SOQL Consideration: In Dynamic SOQL, you cannot use bind variable strings in a query string. For example, the below section of code will not work and will throw an error that Variable doesn’t exist. To solve that you need to resolve the variable into a String variable and...

Read More

Dynamic Apex – Playing with CRUD and FLS

Security is one of the important things in today’s world. And when we talk about cloud, Security is the top most priority items. No doubt. Salesforce is not an exception and they are also considering Security really seriously.In Salesforce, we have different types of Security controls – starting from org level security to object level, followed by record level and field level. This post focuses on methods for controlling data at the object and field level.As always I always believe explaining concept with examples is the best and effective way. Today also I will do the same thing.For this post, I have prepared a small object called Book and below is the detail -Important Note -In Visualforce, when you use any sObject or sObject field, the platform will enforce CRUD and FLS automatically. If the user is not having FLS to a field, Salesforce will automatically remove the field from the Visualforce page. For example, apex:inputField tag will be rendered as read-only for those fields having FLS set as read-only. But the exception here are the tags apex:inputText, apex:inputTextArea. Using these tags tells Visualforce to not treat them as sObject field, thus platform will not automatically enforce FLS for those  fields. Apex Code to check CRUD manually:Requirement:Write a Visualforce page with controller behind which should display all Books present in the org in the form of Picklist. When we will execute...

Read More

Archives