Why to avoid using Workflow rule and Process Builder field update with Trigger

Consideration before using Trigger, Workflow and Process builder field update at same time in Salesforce

Workflow rule and Process builder are the tools because of which Salesforce Admins can perform so many tasks, which were only possible by writing Triggers. Before release of Process builder, if we wanted to perform field update on child records or post chatter messages or auto execute Visual Flow, Triggers were used by developers.

As a best practice in Salesforce, it is always suggested that we should prefer “point and clicks” over code. Indirectly, prefer Workflow rule or Process builder over Triggers.

Trigger Workflow and Process Builder in Salesforce
Trigger, Workflow and Process Builder in Salesforce

In this post, I will explain a scenario where above statement will not stand true. Continue reading “Why to avoid using Workflow rule and Process Builder field update with Trigger”

Using Selenium to test workflow field update action – Salesforce automated testing – Video tutorial – Part 2

We have already discussed basics of selenium and how we can use this tool for automated testing. Here we will see how we can take advantage of Selenium to test workflow field update. in this article we will create a simple workflow rule on Lead object and update “Description” field by adding fields “Number of Employees” and “Number of Locations”. We can use selenium to test if workflow is working or not ?

Salesforce Workflow rule - field update on Lead
Salesforce Workflow rule – field update on Lead

Continue reading “Using Selenium to test workflow field update action – Salesforce automated testing – Video tutorial – Part 2”

Salesforce interview questions – Part 19

Salesforce interview questions for developers and admins around Apex, Visualforce, getting Salesforce object name on basis of Id, Apex API limits

181. Lets consider your custom Object named “Training__c” has field “Trainer__c”. You have set some default value in that field. Will that default value apply to new record created by apex code ?
OR
How to make sure that record created from apex code should respect default value of fields ?
OR
Default value in field from Apex code.
Ans :

After API 20, it should automatically populate However there is known issue for same here, click here if it impacts you.
Workaround :
If Default value of field is not getting populated by Apex then we have to use “Dynamic Apex”.  Create instance of object from sObjectType like shown below:

Training__c tr= (Training__c) Training__c.sObjectType.newSObject(null, true);

//Check if Value in field "Trainer__c" is default value
System.assertEquals('Jitendra', tr.Trainer__c);

182. What is best practice to refer dynamic custom messages in Visualforce with multi-language support ?
Ans :
Using Custom Label or OutputField or InputField tag, Platform itself will take care of internationalization. However in some cases, Message needs to be dynamic at the same time it should also support muti-language. In Custom Label, we cannot save dynamic String.

Let’s assume we want to show message something like “DEVELOPERNAME is not authorized to access this page”.
Here, Developername should be dynamically changed in visualforce which supports multilanguage. For each developername, it is not feasible to create custom labels. So below workaround can be used :

Step 1 : Create a Custom Label with text “{0} is not authorized to access this page“. In every language, dynamic value should represented by {0}.

Step 2 : In Controller of Visualforce write something like this :

String developerName = 'Some DeveloperName';
String message = String.format(Label.DEVELOPERNA, new String[] { developerName });

Continue reading “Salesforce interview questions – Part 19”