function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lavan l 5lavan l 5 

Getting query srting of URL in apex trigger

When i click on save button through this below url:

https://ap1.salesforce.com/001/e?retURL=%2F001%2Fo

In trigger i am trying to get the full url including query parameters, even though it has retURL as query parameter i am getting null when i use URL.getCurrentRequestUrl().getQuery().

On click of save button i standard page, I want to get the query string in trigger please reply if any one know how to get it.

Thank you.......
Best Answer chosen by lavan l 5
Shyam BhundiaShyam Bhundia
Don't think there is a way.

Why not create a custom field on the object and put the value of the parameter in there?

All Answers

Shyam BhundiaShyam Bhundia
I don't think you are able to access url parameters at the trigger level, as a trigger is usually associated with operating database functions.  Also a trigger can be called from contexts where there is no page (from data loader or other triggers etc...).

What is your use case?  There might be another solution.

Bhawani SharmaBhawani Sharma
You can't use these(URL and PageReference) functions in trigger and trigger doesn't have anything to do with URL parameters. These are for ApexClasses only.
lavan l 5lavan l 5
Thank you for response, But when i use this URL.getCurrentRequestUrl().toExternalForm() i am getting https://ap1.salesforce.com/001/e in trigger. Thats the reason i want to know how to get query parameter values.
lavan l 5lavan l 5
My use case is if i click on standard save button from any standard salesforce page i want to get the full current request url from which page i am inserting/updating that record.
Shyam BhundiaShyam Bhundia
what do you want to do with that url?
lavan l 5lavan l 5
I want to use the parameter in my trigger code, Is there any way to get it?
Shyam BhundiaShyam Bhundia
Don't think there is a way.

Why not create a custom field on the object and put the value of the parameter in there?
This was selected as the best answer
lavan l 5lavan l 5
Thanq, i think that would work but just i am trying is there any way to get without creating any field. Anyhow thanx @shyam for quick response.
Shyam BhundiaShyam Bhundia
no problem.

If the value is the same all the time or from a related object, then you could use a formula field to get the value.  Then you can remove it from page layout, so its hidden.