Wednesday, March 25, 2020

Run - "Time Based Workflow" or "Process Builder" within 60 Minutes or 1 Hour of Record Creation

We mostly get a requirement, to update the field after few minutes of creation of record or send an email after 1 minute of status update of record. 

Salesforce gives only 2 options while creating time based workflow i.e. hours or days. Means if we need that action should be executed within 5 or 10 minutes, it is not possible.




To serve above purpose, we can create a date time formula field "Created Date - 50 Minutes", value = CreatedDate-(50/1440). 

Suppose record was created on 26 March 2020 9:00 AM (03/26/2020 09:00), this formula field will have value 26 March 2020 8:10 AM (03/26/2020 08:10).





Now you can use this field in workflow like below :-





Activate workflow, which will work after 10 minutes from record creation. You can use the same field in process builder as well.

Note : - Time based workflow runs in batch as per salesforce queue, record will be queued after 10 minutes, execution may vary as per salesforce queue execution.

Tuesday, September 25, 2018

Loading Visualforce in Iframe, performance issue?


We usually get a requirement that Visualforce page needs to be loaded either from lightning or from Javascript or from any other Visualforce page in an iframe.

We had the same requirement too! Loading Visualforce page from lightning, but major road blocker was performance, Visualforce page was taking almost 3 seconds to load in an iframe.

When we use Visualforce page, we use relative URL like /apex/PageName, when we call Visualforce page from another Visualforce page, we don’t face performance issue, because it will be in same origin and server i.e. visualforce.com.

But when we call the same form lightning, both the server and origin are different, further if you call page in an iframe, it is even slower.

To avoid loading and performance issue, use absolute URL i.e. https://domain+Namespace.visualforce.com/apex/PageName


You can create absolute URL from below code:-

vfUrl = 'https://'+URL.getSalesforceBaseURL().getHost()+ ‘/apex/PageName’


Or
If your org has domain name and namespace [Suppose my org namespace is Test]:-

string nspace = 'Test__';

nspace = nspace.replace('__','').toLowerCase();

string vfUrl ='https://'+URL.getSalesforceBaseURL().getHost().split('\\.')[0];

vfUrl = vfUrl + (vfUrl.containsIgnoreCase('--'+nspace) ? '' : '--'+nspace) +'.'

                             + '.visualforce.com'+ ‘/apex/PageName’