I have a visualforce page that basically saves a contact object but can be accessed from two different pages. I have this command button:

<apex:commandButton value="Done" id="doneButton" immediate="true" action="{!URLFOR($Action.Account.view, linkedObjectId)}"/>

In my controller I have the following pageReference code:

public PageReference saveAndAssign(){
    check = true;

    try {
        newRelatedContact.Related_Person__c = RS_ContactUtils.create(newContact);
    } catch(DmlException e) {
        check = false;

        insert newRelatedContact;       
        newContact = new Contact();
        newRelatedContact = new RS_Related_Contact__c();
        this.newRelatedContact.put(relatedObjectField, linkedObjectId); 
    return null;

However, when i click the done button, I get the error:

Error is in expression '{!URLFOR($Action.Account.view, linkedObjectId)}' in component in page arcusregserv:rs_relatedcontactsdefine

The record saves but i get the error page first. is there a work around in the URLFOR for this?



URLFOR is normally used in an apex:outputLink; an apex:commandButton is normally bound to a controller method:

<apex:commandButton ... action="{!saveAndAssign}"/>

If your aim is to first invoke the saveAndAssign controller method and then go to the Account view page, then the other change to make is to return the new page reference from that method:

public PageReference saveAndAssign() {
    return new ApexPages.StandardController(linkedObjectId).view();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.