1

I'm quite new in Salesforce and I'm having some difficulties. I'm creating a VF page in order to override the NEW button for CONTACT for certain profiles. I've already done it for the EDIT button and it works (it's allowed by standard controller action).

This is the first part of my code:

<apex:page standardController="Contact" tabStyle="Contact" action="{!if($Setup.OverrideStandardButtons__c.Override__c==true, null, urlFor($Action.Contact.NewContact, Contact.Id, [retURL=URLFOR($Action.Contact.View, Contact.Id)], true))}" >

The second part (from urlFor) in not working. For example, if I'm the System administrator and I try to create a new Contact I get an error.

Is there a way to do this without any controller extension, just modifying the code?

2
  • What error are you getting?
    – Raul
    Jan 19, 2017 at 15:21
  • This is the error: Invalid parameter for function URLFOR Error is in expression '{!if($Setup.OverrideStandardButtons__c.Override__c==true, null, urlFor($Action.Contact.NewContact, Contact.Id, [retURL=URLFOR($Action.Contact.View, Contact.Id)], true))}' in component <apex:page> in page overridenewcontact
    – user40993
    Jan 19, 2017 at 15:27

1 Answer 1

2

retURL- expects a valid URL.

In your example you have retURL=URLFOR($Action.Contact.View, Contact.Id), so at run time the retURL becomes invalid as Contact is not created yet.

Ideally on click of cancel button in new contact page it should take user to Contact list view, but you can customize it:

<apex:page standardController="Contact" tabStyle="Contact" 
    action="{!IF($Setup.OverrideStandardButtons__c.Override__c == true, 
        null, 
        URLFOR($Action.Contact.NewContact, 
            null, 
            [retURL=URLFOR($Action.Contact.Tab, $ObjectType.Contact)], 
            true))}" >
</apex:page>

update: Trick here is again to use $CurrentPage.parameters.retURL to fetch retURL dynamically.

Code:

<apex:page standardController="Contact" tabStyle="Contact" 
    action="{!IF($Setup.OverrideStandardButtons__c.Override__c == true, 
        null, 
        URLFOR($Action.Contact.NewContact, 
            null, 
            [retURL=$CurrentPage.parameters.retURL], 
            true))}" >
</apex:page>
4
  • Thanks for the explanation! Now the problem is that sometimes I have to come back to the Contact related list of its Account and sometimes to the Contact List view (it depends on where I started the action). Can I set some how the previous page in that URLFOR?
    – user40993
    Jan 19, 2017 at 17:05
  • Updated the post, you should use retURL=URLFOR($CurrentPage.parameters.retURL)
    – Raul
    Jan 20, 2017 at 9:56
  • I've just tried, but it returns the error "Invalid Parameter". I've tried also with retURL=URLFOR($CurrentPage.URL), but if I click "Cancel" instead of clicking "Save" it returns me on the same "New" section (like a loop).
    – user40993
    Jan 20, 2017 at 13:55
  • Maybe try- [retURL=$CurrentPage.parameters.retURL]. Have updated answer.
    – Raul
    Jan 20, 2017 at 14:20

You must log in to answer this question.

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