You need to sign in to do that
Don't have an account?
arasu
Visualforce page edit button override and page redirect not working?
Hi,
I need to override the standard edit page for a custom object. If the status of the custom object record is "Approved", then I do not want users to edit the record, else I need to redirect the users to the standard edit page for this record.
I have the following code in VF and controller. I can see the the URL is changed to the edit page URL when I click the edit button after overiding the button with the VF page, but the standard edit page is not getting displayed. Insatead the word Hello is getting displayed.
VF Code:
<apex:page standardController="Fixture_Order__c" extensions="conSEditOverrideFixtureOrder" id="mypage"> Hello </apex:page>
Controller Code:
public class conSEditOverrideFixtureOrder { Fixture_Order__c fixordobj; private String vid; public conSEditOverrideFixtureOrder(ApexPages.StandardController controller) { this.vid = ApexPages.currentPage().getParameters().get('id'); reset(); } public PageReference reset() { if(fixordobj.Approval_Status__c=='Approved'){ PageReference editPage = new PageReference('/'+this.vid+'/e—retURL=' + this.vid); editPage.setRedirect(true); return editPage; }else{ PageReference errPage = new PageReference('/apex/editFixtureOrderError'); errPage.setRedirect(true); return errPage; } return null; } public String getApprovalStatus(){ return this.fixordobj.Approval_Status__c; } public Fixture_Order__c getFixtureOrder() { if(fixordobj == null) reset(); return fixordobj; } public void setLead(Fixture_Order__c leaddet) { fixordobj = leaddet; } }
Can anyone please help to understand the cause? Appreciate all your valuable feedbacks.
Thanks and regards,
Ambili
Ambili
Depending on your page you may need to add a non displaying reference into your markup to let the standard controller know about the reference to contact.recordTypeId in your action method - something like this anywhere in your page should work:
and for a totally apex code free solution:
Message Edited by dchasman on 09-19-2008 04:52 PM
Message Edited by dchasman on 09-19-2008 05:44 PM
All Answers
Hi,
Thanks a lot for your reponse. Initially I started with using the action attribute in the apex:page tag. But when I had the following code inthe VF page, it was throwing "Syntax Error" for the line {!Fixture_Order__c.Approval_Status__c}. So it appeared that at the apex:page level, probably it does not understand the syntax {!Fixture_Order__c.Approval_Status__c}. Is that true or am I doing something wrong here?
Thanks for all your feedbacks.
Regards,
Ambili
Hi,
Thanks again for your prompt response.
I tried the above by calling the reset in action. I think its trying to work, but its going in an endless loop by refreshing the page endlessly. Is this becasue the edit button is overriden and hence everytime it is trying to load the standard edit page, the VFpage code gets executed? If so, how can I get this to work without going in an endless loop.
Our requirement is basically to not allow the users to go to the edit page, if the status of the record is "Approved", else it should allow to go to the standard edit page for this custom object.
Appreciate all help. Thanks.
Message Edited by arasu on 09-02-2008 04:59 PM
This keeps you on the same page if you're not a sysadmin, but redirects you to the regular account overview page if you are.
Was wondering if anyone has solved this issue and could post some solution code? I'm having the same problem with an infinite loop for the standard edit pages.
I have a Visualforce page which loads a controller that inspects the recordtype and forwards the user to specific Visualforce page based upon the value. If the record doesn't match the specific criteria they are redirected to the standard edit page. However, the user never makes it there as they are stuck in an infinite loop.
Any help would be greatly appreciated.
Thanks... Jeff
Message Edited by dchasman on 09-17-2008 07:37 PM
Thanks for the help but how do you call URLFOR from Apex? Don't think that is allowed?
<apex:page standardController="Contact"
extensions="dispatcherContactEditController"
action="{!redir}"/>
public class dispatcherContactEditController {
private ApexPages.StandardController controller;
public dispatcherContactEditController(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference redir() {
PageReference newPage;
Contact c = [Select id, recordtypeid From Contact Where Id = :ApexPages.currentPage().getParameters().get('id')];
// visualforce page 1
if (c.recordtypeid == '00000000') {
newPage = new PageReference('/apex/Contact_Edit1?id='+ApexPages.currentPage().getParameters().get('id'));
newPage.setRedirect(true);
return newPage;
// visualforce page 2
} else if (c.recordtypeid == '11111111') {
newPage = new PageReference('/apex/Contact_Edit2?id='+ApexPages.currentPage().getParameters().get('id'));
newPage.setRedirect(true);
return newPage;
// go to the standard edit page
} else {
newPage = new PageReference(URLFOR($Action.Contact.Edit, ApexPages.currentPage().getParameters().get('id'), null, true));
newPage.setRedirect(true);
return newPage;
}
}
}
Depending on your page you may need to add a non displaying reference into your markup to let the standard controller know about the reference to contact.recordTypeId in your action method - something like this anywhere in your page should work:
and for a totally apex code free solution:
Message Edited by dchasman on 09-19-2008 04:52 PM
Message Edited by dchasman on 09-19-2008 05:44 PM
Thanks for the help. The controller seems fine but I get the following error when trying to save the Visualforce page.
Save error: Unknown property 'ContactStandardController.routeTo'. I tried to google routeTo.url but found nothing.
Thanks
Jeff Douglas
We are getting closer. Contacts that do not match the recordtypes are sent correctly to the standard edit page. However, the other two recordtypes are returning a blank pages.
I put a debug statement in each of the branches and they are reaching those points properly but it looks like it is not being redirected to the correct VF page. I tried adding newPage.setRedirect(true) but that didn't help.
The Page Editor clearly shows that the blank page being displayed is the Dispatcher_Contact_Edit page.
Here is the log:
17:27:12 DEBUG - ***Begining Page Log for /apex/Dispatcher_Contact_Edit
Element j_id0 called method {!nullValue(redir.url, urlFor($Action.Contact.Edit, contact.id, null, true))} returned type String:/apex/contact_edit1?id=XXXXXXXXXXXXXXXXXX20080919212712.069:External entry point: returning from end of method public dispatcherContactEditController<Constructor>(ApexPages.StandardController) in 1 ms
20080919212712.069:Class.dispatcherContactEditController.getRedir: line 10, column 21: SOQL query with 1 row finished in 5 ms
20080919212712.069:Class.dispatcherContactEditController.getRedir: line 16, column 13: ====> Redirecting to Contact_Edit1
20080919212712.069:External entry point: returning System.PageReference from method public System.PageReference getRedir() in 6 ms
Thanks!
Jeff Douglas
Message Edited by dchasman on 09-19-2008 07:12 PM
Message Edited by dchasman on 09-26-2008 07:41 AM
Error: Incorrect parameter for function nullValue(). Expected Object, received Text
I can't find the documentation for the nullValue function, so I'm not quite sure what I've got wrong here, as I think I've been following along with the discussion.
And my VisualForce page is this...
<apex:page standardController="MPR__c" extensions="MPRControllerExtension" tabStyle="MPR__c"
action="{!nullValue(redir.url, urlFor($Action.MPR__c.Edit, MPR__c.id, null, true))}">
<apex:outputText value="{!MPR__c.recordTypeId}" rendered="false"/>
</apex:page>
What am I missing?
My getredir fuction has the same signature as above...
Besides obviously not catching for smileys when I cut and paste text...
the controller on VFPage1 determines which new record type we're using.
It redirects to VFPage2 if we want to use the standard "new record" page, and passes along all of the the parameters.
It redirects to VFPage3 if we want to use the record type that we want the custom Visual Force Edit Page.
And VFPage2 is the one that immediately redirects to the standard screen using URLFOR as described above.
Thanks for the thread here...
Controller
Visualforce Page
You can then override the Edit button with this Visualforce page and everyone will be happy.
Jeff Douglas
Informa plc
As I described earlier, I'd like to have one record type go to a custom new page, but all of the other record types go to their standard record types.
My problem right now is that it successfully goes to the correct page when it's the custom record type, but I'm having problems getting the standard page to work right.
Right now, the flow for a "standard" new page is this:
Record Type Selection Screen -> PAGE2 -> Record Type Selection Screen -> Standard Edit Screen
So basically, what I'm seeing is that it's going back to the record type selection screen a second time.
My PAGE2 has this:
<apex:page standardController="MPR__c" extensions="MPRFulfillmentController" tabStyle="MPR__c"
action="{!urlFor($Action.MPR__c.New, MPR__c.id, NULL, true)}">
And it looks like that's redirecting it to the record type selection screen -- but I want to have it redirect to the entry screen for that record type.
I'm not quite sure what I'm missing here, and I'm open to suggestions.
It's the "else" branch that I don't have right yet....
In the meantime, you might tweak your controller to simply return null when all of the condition are not met and you want to return the user to the standard new page. This is working for me.
Good luck.
Jeff Douglas
Informa Plc
I tried to return 'null' on the 'else' path, and all that does for me is bring up a blank page.
http://ideas.salesforce.com/article/show/10093972/Assign_Visual_Force_Pages_like_a_Page_Layout
I'm also desperate with yhis issue, using s-controls is not a good idea for VF pages, and using the extension makes the code in the custom controller just not work. I'll be following this thread and also looking for solutions.
Voted for the idea!
thanks,
I've got this almost working, except when you choose the record type that directs to the standard page, it returns you to the record selection page, and you have to select the same record type a second time (and sometimes even a third) to get it to finally direct to the standard page.
Any thoughts?
Thanks.