You need to sign in to do that
Don't have an account?
Nidhi Sharma 17
Redirection to particular 'Order' record
I have an action 'hello1' on an apex command button 'Cancel'. On clicking Cancel I want to navigate back to the particular Order record whose survey record I am capturing at present. URL of the current survey page is
VF Code
Apex Class
But
'https://c.ap2.visual.force.com/801/o?{!Order.Id}=orderId'
is not navigating me back to particular record, rather to the whole list of Order Records. Kindly help.
https://c.ap2.visual.force.com/apex/TakeSurvey?id=a0R28000000ChcAEAS&cId=801280000004CYc
VF Code
<apex:page standardcontroller="Survey__c" extensions="ViewSurveyController" cache="false" sidebar="false" showheader="false"> <apex:commandButton action="{!hello1}" value="Cancel"/> </apex:page>
Apex Class
public PageReference hello1() { orderId = Apexpages.currentPage().getParameters().get('cId'); PageReference reference=new PageReference('https://c.ap2.visual.force.com/801/o?{!Order.Id}=orderId'); reference.setRedirect(true); return reference; }
But
'https://c.ap2.visual.force.com/801/o?{!Order.Id}=orderId'
is not navigating me back to particular record, rather to the whole list of Order Records. Kindly help.
I think you can just use the /<<Id>> to redirect to the particular record detail page.
public PageReference hello1() {
orderId = Apexpages.currentPage().getParameters().get('cId');
PageReference reference=new PageReference('/'+orderId);
reference.setRedirect(true);
return reference;
}
All Answers
I think you can just use the /<<Id>> to redirect to the particular record detail page.
public PageReference hello1() {
orderId = Apexpages.currentPage().getParameters().get('cId');
PageReference reference=new PageReference('/'+orderId);
reference.setRedirect(true);
return reference;
}
Hi Puru Annamalai,
It worked well.
I am facing another problem. This is a VF page linked to Surveys. And somewhere in the code I want to change field of the specific order record which it is related to.
Like, after clicking on submit button I get redirected back to the page with an updated picklist value there 'Survey taken'. Action on button is 'submitResults'.
So you want to redirect from this vf page to its order page with a updated picklist field value in the order record right ?
so you can do something like below
//Constructor
public ViewSurveyController() {
orderId = Apexpages.currentPage().getParameters().get('cId');
}
//SubmitResults method - changed return type from void to pageReference
public pageReference submitResults() {
Order__c order = new Order__c(Id = orderId, picklistField = 'SomeValue');
update order;
pageReference pRef = new PageReference('/'+orderId);
return pRef;
}
if it answers your question, kindly mark it as best answer
I got the code working. But approach was just a bit different. Instead of creating a new record on order I looked for existing record based on a condition and updated it.
Thank you for all the help :)