This is working code, saying that Telemarketing users are routed to a standard New Event page, while other users are redirected to MyPage:

action="{!if($Profile.Name !='Telemarketing', urlFor($Page.MyPage), urlFor($Action.Event.NewEvent, null, null, true))}"/>

Instead of redirecting to MyPage, I have to call a method inside a controller. How do I do that?

This is what I am trying to do:

action="{!if($Profile.Name !='Telemarketing', {!redirect}, urlFor($Action.Event.NewEvent, null, null, true))}"/>

This code is not working. I am trying to call redirect method inside a controller.

Update1. Full code, not working:

<apex:page standardController="Event" extensions="CTRL_EventRedirect" 
       action="{!if($Profile.Name !='Telemarketing', 
                    urlFor($Action.Event.NewEvent, null, null, true))}"/>

Getting Save error: Unknown property 'EventStandardController.redirect' Also, I get error if I use redirect() instead of redirect

Update2. Controller code:

public with sharing class CTRL_EventRedirect{     
    public PageReference redirect(){
        //method body

Update3. I found a workaround, but instead of finding a solution for Visualforce, I moved a logic to a controller.

Here's the page:

<apex:page standardController="Event" extensions="CTRL_EventRedirect" action="{!redirectByProfile}"/>

And the controller logic:

public PageReference redirectByProfile()
        User currentUser = DAL_User.getCurrentUser();
        Profile telemarketingProfile = DAL_User.getTelemarketingProfile();
        if (currentUser.ProfileId == telemarketingProfile.Id)
            Schema.DescribeSObjectResult dsr = Event.SObjectType.getDescribe();
            PageReference createEventPage = new PageReference('/' + dsr.getKeyPrefix() + '/e');
            createEventPage.getParameters().put('nooverride', '1');
            return createEventPage;
            return redirect();              


  • You don't have to add a new !. Try {redirect} instead. – SF_user Jan 13 '15 at 10:53
  • You do not need braces at all. – Sergej Utko Jan 13 '15 at 11:02
  • I'm getting save error if I don't use braces. Please check the updated post. – justasd Jan 13 '15 at 11:45
  • what is signature of redirect() method in controller? – cropredy Jan 13 '15 at 21:13
  • public, non static – justasd Jan 13 '15 at 21:22

Use below,

   <apex:commandButton action="{!redirect}" rendered="{!$Profile.Name !='Telemarketing'}"/>

 <apex:commandButton action="{!urlFor($Action.Event.NewEvent, null, null, true)}" rendered="{!$Profile.Name =='Telemarketing'}"/>
| improve this answer | |
  • I get "Unknown property 'EventStandardController.redirect'". I then use redirect(), getting save error again. Full code is here: <apex:page standardController="Event" extensions="CTRL_EventRedirect" action="{!if($Profile.Name !='Telemarketing', redirect, urlFor($Action.Event.NewEvent, null, null, true))}"/> – justasd Jan 13 '15 at 11:16
  • How have you defined your recirect method in controller. Can you display that part of code/Method? – snehakem Jan 14 '15 at 5:00
  • Yes. I edited the post. Please check the Update2 part of it. – justasd Jan 14 '15 at 8:58
  • 1
    I found a workaround. Please check the Update3 section of the post. And thanks. – justasd Jan 14 '15 at 11:44
  • 1
    hey @justasd, i too found a easy workaround, Please check and let me know. – snehakem Jan 14 '15 at 11:57

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.