[SalesForce] Pass parameters from URL to SOQL query.

How can i pass parameters from URL to Controller? I want to pass URL parameters to My controller class where i can query to fetch data with the help of these parameters.

Best Answer

You can catch URL parameters by referring them in this way:

Page name = ExamplePage

=======

URL example = https://cs18.salesforce.com/apex/ExamplePage?yourParameter=90483753498hu76

=======

In your controller, catch your parameter:

String yourParameterValue = ApexPages.currentPage().getParameters().get('yourParameter');

So, your String will have as value '90483753498hu76'

Now, you can query your data finding (e.g.) for your record using the parameter you just caught, i.e

Account exampleAccount = [SELECT Id FROM Account WHERE Id = :yourParameterValue ];
Related Topic