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',
redirect,
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;
}
else
return redirect();
}
!
. Try{redirect}
instead.