0

i have a requirement that i need redirect standard opportunity detail page to a visualforce page when ever they click on save button after make edits on it. I don't see save button in 'opportunity product' button and link section. Can some one suggest me on this?

0
1

Save button cannot be over ridden, basically you cannot place custom button on Edit page also.

You have to go for VF page for editing and place the button there.

1

I'm not saying I think it's a good idea, but it is technically possible. So just for fun...

You could do some hacky routing by examining the Referer header and redirecting based on that. First create this page:

<apex:page standardController="MyObject__c" extensions="MyExtension" action="{!route}">
    <apex:detail subject="{!MyObject__c.Id}" />
</apex:page>

Here's the logic you would need to use to determine if you came from the Edit page (ignoring edits from the New page):

public with sharing class MyExtension
{
    final String editUrl, referer;
    public MyExtension(ApexPages.StandardController controller)
    {
        editUrl = controller.edit().getUrl().toLowerCase();
        referer = ApexPages.currentPage().getHeaders().get('Referer');
        if (referer != null)
            referer = referer.toLowerCase()
                .substringAfter('.com')
                .substringBefore('?');
    }
    public PageReference route()
    {
        return (referer != null && editUrl.contains(referer)) ?
            Page.MyOverride : null;
    }
}

But...this will also pick up situations where you click Edit and then click Cancel. To solve for that, you could also check for recent edits by the running user. Max save time is 10 seconds, plus a little wiggle room for the redirect. You might want to use a 12 second threshold.

public with sharing class MyExtension
{
    final String editUrl, referer;
    final Boolean didSave;
    public MyExtension(ApexPages.StandardController controller)
    {
        Long loadTime = Datetime.now().getTime();
        MyObject__c record = [
            SELECT LastModifiedDate, LastModifiedById
            FROM MyObject__c WHERE Id = :controller.getId()
        ];
        Long msSinceLastSave = loadTime - record.LastModifiedDate.getTime();
        didSave = record.LastModifiedById == UserInfo.getUserId() &&
             < 12 * 1000;

        editUrl = controller.edit().getUrl().toLowerCase();
        referer = ApexPages.currentPage().getHeaders().get('Referer');
        if (referer != null)
            referer = referer.toLowerCase()
                .substringAfter('.com')
                .substringBefore('?');
    }
    public PageReference route()
    {
        return (didSave && referer != null && editUrl.contains(referer)) ?
            Page.MyOverride : null;
    }
}

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.