2

Related to this post, Open a visualforce page from a managed package page: URL No Longer Exists. Has anyone tried to take this a step further? The following button is on a Visualforce page in a Managed Package and is using the URLFOR method and the $Action global variable for delete. In turn, the Delete Button has been overridden by a Visualforce page in the Default Namespace. When you click the Delete Button, Salesforce uses a relative URL and you receive a URL no longer exists error because the host part of the URL is still namespaced for the managed package but the button override is a page in the standard namespace. Seems like a bug in the URLFOR method. It should detect this use case and redirect you to the standard namespace. See the button code below. Any ideas?

<apex:commandButton action="{!URLFOR($Action.Custom_Object__c.Delete, Custom_Object__c.id)}" value="Delete" onclick="return confirm('Are you sure?');" />
0

It is possible to fix this problem with some javascript by manipulating the onclick handler:

function fixExternalButtons() {
    $j('input.btn').each(function(index) {
        var prefix = 'PREFIX';
        var name = $j(this).attr('name');

        if (undefined !== name && name.startsWith(prefix + '__')) {
            return; //continue
        }

        var onclick = $j(this).attr('onclick');

        if (onclick.startsWith('this.form.action = \'https://' + prefix + '.')) {
            $j(this).attr('onclick', onclick.replace('https://' + prefix + '.', 'https://c.'));
        }
    });
}

The function utilizes jquery and should be executed after the buttons have been rendered on the page.

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.