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?

  • What error are you getting? – Raul Jan 19 '17 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 – Paz Jan 19 '17 at 15:27
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>
  • 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? – Paz Jan 19 '17 at 17:05
  • Updated the post, you should use retURL=URLFOR($CurrentPage.parameters.retURL) – Raul Jan 20 '17 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). – Paz Jan 20 '17 at 13:55
  • Maybe try- [retURL=$CurrentPage.parameters.retURL]. Have updated answer. – Raul Jan 20 '17 at 14:20

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.