Activity › Forums › Salesforce® Discussions › How To Read The Parameter Value From The Url In Apex?
-
How To Read The Parameter Value From The Url In Apex?
Posted by Aman on September 20, 2018 at 3:08 PMHow To Read The Parameter Value From The Url In Apex?
Parul replied 7 years, 9 months ago 3 Members · 4 Replies -
4 Replies
-
Hi,
Consider that the parameter name is “RecordType”.
String recordType = Apexpages.currentPage().getParameters().get(‘RecordType’);
Thanks
- [adinserter block='9']
-
Here is the code snippet
public Id oppid{get;set;}
Id id = apexpages.currentpage().getparameters().get(‘id’);
<apex:inputField value=”{!$CurrentPage.parameters.Paramtervalue}”/>
Thanks
-
Hi,
We can also encode or decode this parameter so that it can’t be visible to the users.
Hope this helps.
-
Code snippet
public PageReference openSheet(){
if (!strday.isNumeric()){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,’Pleaseenter a correct day value.’));
return null;
}
if (!strmonth.isNumeric()){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,’Please enter a correct month value.’));
return null;
}
if (!stryear.isNumeric()){
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,’Please enter a correct year value.’));
return null;
}PageReference newPage = page.crew_sheet;
strday.leftPad(2,’0′);
strmonth.leftPad(2,’0′);
newPage.getParameters().put(‘day’, strday);
newPage.getParameters().put(‘month’, strmonth);
newPage.getParameters().put(‘year’, stryear);
newPage.setRedirect(true);
return newPage;}
The Visualforce page that opens also has a custom controller and it uses the following code (snippet):Page 2 Controller
public with sharing class CrewSheet {
Public String day;
Public String month;
Public String year;
Public Datetime specificDate;functionalY fy = new functionalYUtilities ();
Public List<Object__c> listAlpha1{get;set;}
Set<String> gwRounds = new Set<String>();
Public List<WorkOrder> listAlpha1Results{get;set;}Public List<Object__c> listAlpha2{get;set;}
Set<String> pcRounds = new Set<String>();
Public List<WorkOrder> listAlpha2Results{get;set;}Public List<Object__c> listAlpha3{get;set;}
Set<String> gbRounds = new Set<String>();
Public List<WorkOrder> listAlpha3Results{get;set;}Public List<Object__c> listAlpha4{get;set;}
Set<String> rRounds = new Set<String>();
Public List<WorkOrder> listAlpha4Results{get;set;}Public CrewSheet(){
//get the parameters from the page
day = apexpages.currentPage().getParameters().get(‘day’);
month = apexpages.currentPage().getParameters().get(‘month’);
year = apexpages.currentPage().getParameters().get(‘year’);
//the following if statements were added in as the test class isn’t passing the parameters
Datetime missingdate = system.now();
if(day == ”){
day = string.valueof(missingdate.day());
}
if(month == ”){
month = string.valueof(missingdate.month());
}
if(year == ”){
year = string.valueof(missingdate.year());
}
String specificDate = day + ‘/’ + month + ‘/’ + year + ‘ 09:00’;
Datetime specificDateformatted = datetime.parse(specificDate);
String nextDayText = specificDateformatted.format(‘EEEE’);// At this point we use the dates/strings in queries ultimately displayed on the vf page…i’ve cut them out for make it easier to read.
}Thanks
Log In to reply.