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.
Recently, I noticed something amazing in Facebook console when I pressed “Ctrl+Shift+J” (Developer tools) as shown in below image.
I was owner of one of Training institute in Nagpur (India) named “Shivasoft” for almost 3 years. This is the reason few of you know me as a “Shivasoft”, some of you know me by my previous twitter handler “@ilovenagpur” as well. I was lucky enough that I had many bright and hard working students. They were kind enough to share lots of stuff happening around and other problems. One of the major issue is getting job after graduation and even harder problem is when students does not get selected in “campus recruitment” drive. Freshers needs job and employer needs experience, if you are not coming from campus, this is catch 22 situation. As fresh graduates doesn’t get a job , they either go with MBA (MBA is prestigious course but CAT ranking plays a huge role), advance programming courses like SAP or Oracle by paying hefty amounts , post graduation in IT itself, BPO jobs or some other profession.
This post is solely my opinion where I think, you could overcome this situation. However please do not consider this as a base, take a judgement of your own.
There are many resources and documents available around how to use Test.loadData to create test records in Apex class. As per best practice of writing Test classes in Apex, Its good idea to store master data (aka Seed, Reference data) in static resource and load it in Test classes using “Test.loadData” method. It will save lots of code around creating test records and at the same time easy to maintain. We can store records of Custom settings, standard or custom object which can be used frequently in our code. One of the best functionality to make writing Test classes more easier, As we don’t need to concentrate on writing code for creating data, time can be used to assert actual functionality.
So the question is, How can we load related records using Test.loaddata() method ? Simply by creating fake Salesforce Ids, that’s right !!! It is possible.
Initially I thought creating Wikipedia Search component will be straight forward. I can simply use AJAX request from Lightning component to get result from Wikipedia using its REST API. Soon, I discovered about “Content Security Policy” in Lightning components developer guide.
If we attempt to use AJAX or REST API in Lightning component then below error will be thrown
Uncaught error in markup://ui:keyup : caught Failed to execute ‘open’ on ‘XMLHttpRequest’: Refused to connect to ‘https://en.wikipedia.org/w/api.php?action=opensearch&search=jitendra&limit=10&namespace=0&format=jsonfm’ because it violates the document’s Content Security Policy.
So, other workaround I came up is by using Apex controller to create HttpRequest and return result as JSON to lightning component. Let’s do it