You need to sign in to do that
Don't have an account?
adrissel
Get URL Parameters in Apex Trigger
Hey all. I am trying to write a custom trigger which requires information I have placed as parameters in the referring URL. Here is the code:
Trigger
Class
The result when saving a Case record is "Error: Invalid Data. Review all error messages below to correct your data. Apex trigger AddActivity caused an unexpected exception, contact your administrator: AddActivity: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Class.AddActivity.getUrlInfo: line 5, column 1".
With every debug I do and attempt to pull URL parameters using URL methods, Site methods, whatever...none of them produce what I need. Here is an example of a URL I have:
Is there no way to do this with a Trigger?
Thanks!!
Trigger
trigger AddActivity on Case (before insert) { List<Case> cases = Trigger.new; Case c = cases[0]; AddActivity aa = new AddActivity(); Map<String,Id> urlInfo = aa.getUrlInfo(); system.debug('-------------------> urlInfo: '+urlInfo); }
Class
public class AddActivity{ public Map<String,Id> getUrlInfo(){ String origin = ApexPages.currentPage().getParameters().get('origin'); Id accId = ApexPages.currentPage().getParameters().get('def_account_id'); Map<String,Id> urlInfo = new Map<String,Id>{ 'origin' => origin, 'accId' => accId }; return urlInfo; } }
The result when saving a Case record is "Error: Invalid Data. Review all error messages below to correct your data. Apex trigger AddActivity caused an unexpected exception, contact your administrator: AddActivity: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Class.AddActivity.getUrlInfo: line 5, column 1".
With every debug I do and attempt to pull URL parameters using URL methods, Site methods, whatever...none of them produce what I need. Here is an example of a URL I have:
https://cs24.salesforce.com/500/e?retURL=%2F500%2Fo&RecordType=01230000000n2BN&def_account_id=00130000003zgQYAAY&def_contact_id=003a000001mAJxpAAG&ent=Case&origin=Five9I need to be able to pull the "query" portion of it and parse the data from there (everything after the ?).
Is there no way to do this with a Trigger?
Thanks!!
So you would need to figure out another way to get that info. For example, you could have a lookup field on that triggering object that pointed to the other object.
You can not any VF page or any URL in trigger execution. you have to store this data or need to identify how you can create that URL string and may be then you can use it.
Regards,
Niket