Thursday, 3 September 2015

Get Page URL in trigger !

In some use cases we need to know from which page the trigger is fired and design our business logic around it. In such cases we can use URL.getCurrentRequestUrl()  which returns the page URL from request is made (i.e. trigger is fired)

For example: We had a cleint requirement in where we need to change the name of document generated by a third party to a client specific format. It can be done using before insert trigger on attachments but then the renaming will also be done for the documents which user uploaded from standard Salesforce page. In this case, if we know that the request is coming from the standard salesforce attachment upload page - We can skip our trigger logic. There is a very simple way to do that.


You can use URL.getCurrentRequestUrl() in your trigger to get the URL from which the trigger is fired and then use it in our trigger logic. 

No comments:

Post a Comment