0

i Have only one big controller to do my entire task,in one of vf pages after my process is done,iam showing message in vf as as success if i on click success it has to redirect Account or contact home as respective,process can be applied for for both account and a contact,suppose if Accont process it is complete,it hast to redirect to the Account page,if contact has to redirect to contact home page.not:same controller i have used for all the page

1 Answer 1

2

If I understand your question correctly, you've got one controller that might be used on a page that handles Accounts and a page that handles Contacts. If it's on a Contact page, it should redirect to Accounts, if it's on an Account page, it should redirect to Accounts.

There's a number of ways of doing this would be to have two buttons on your Visualforce Pages, rendered depending on the current page it's on:

<apex:commandButton value="Go" action="{!doSomethingAccounty}" rendered="{!isAccount}" />
<apex:commandButton value="Go" action="{!doSomethingContacty}" rendered="{!isContact}" />

You would then need two Booleans that check if the page is an Account record or a Contact record.

public Boolean isAccount {
    get {
        // Check if it's an Account
    }
    set;
}

public Boolean isContact {
    get {
        // Check if it's a Contact
    }
    set;
}

How you check for this really depends on your code, if you have access to the Id parameter you could do something like this:

public Boolean isAccount {
    get {
        if (ApexPages.currentPage().getParameters().get('Id') instanceOf Account)
            isAccount = true;
        else
            isAccount = false;

        return isAccount;
    }
    set;
}

Then, depending on which button is rendered, you can use the methods doSomethingAccounty or doSomethingContacty and put in the proper PageReference.

You could also use a single button:

<apex:commandButton value="Go" action="{!doSomething}" />

Then do the check for what the current page type is in that method:

public PageReference doSomething() {
    if (ApexPages.currentPage().getParameters().get('Id') instanceOf Account) {
        // Return the user to a Contact record
    }
    else {
        // Return the user to an Account record
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .