You need to sign in to do that
Don't have an account?
Ludivine
After saving a task how to be redirected the view current task record ?
Hi team,
I am totally new in SFDC Development and I have a big issue .
The previous Developer in my company has gone and I don't manage to resolve the redirection myself.
I would be fully grateful if someone could correct this code.
The problem of my users is the following :
" When I create a New task ,I fill in the datas in the form and I click on the save button on New Event page , I would like to be redirected to the Current view task page (URL + task id)
instead of to be redirected to the Account page ."
I don't know anything about coding in Apex so I really need your help...
I have currently a Visualoforce page nammed : TaskRedirect with this code :
<apex:page standardController="Task" extensions="TaskRedirectController" action="{!redirect}">
</apex:page>
It is display for a New Task, and below you will find the code of the Apex Class that is called, could you tell me what I should write to be redirect to the URL + Task_id after save??
public with sharing class TaskRedirectController {
public final Task task;
public User userData;
public TaskRedirectController(ApexPages.StandardController redirectController)
{
//get the current record
this.task=(Task)redirectController.getRecord();
userData = [SELECT Business_Group__c, Business_Unit__c, User_Division__c, User_Subdivision__c FROM User WHERE Id = :UserInfo.getUserId()];
}
public PageReference redirect(){
String what_id = ApexPages.currentPage().getParameters().get('what_id');
String who_id = ApexPages.currentPage().getParameters().get('who_id');
String Record_Type = ApexPages.currentPage().getParameters().get('RecordType');
String task_Id = ApexPages.currentPage().getParameters().get('Id');
String accid = ApexPages.currentPage().getParameters().get('AccountId');
if(accid == null)
accid ='';
if(what_id == null)
what_id = '';
if (who_id == null)
who_id = '';
if (task_id == null)
task_id = '';
String str='/00T/e?retURL=%2F001%2Fo&nooverride=1&00N20000001kXCH='+replaceStr(userData.Business_Group__c)+'&00N20000001kXCL='+replaceStr(userData.Business_Unit__c)+'&00N20000001kXCR='+replaceStr(userData.User_Subdivision__c)+'&00N20000001kXCQ='+replaceStr(userData.User_Division__c)+'&what_id='+ what_id +'&who_id='+ who_id;
PageReference r= new PageReference(str);
r.setRedirect(true);
return r;
}
public String replaceStr(String s){
if(s==null) s='';
return s.replace('&', '%26');
}
public static testMethod void test()
{
Task t = new Task();
Apexpages.Standardcontroller stdController = new Apexpages.Standardcontroller(t);
TaskRedirectController testClass = new TaskRedirectController(stdController);
System.assert(testClass.redirect() != null);
System.assert(testClass.replaceStr(null) != null);
System.assert(testClass.replaceStr('&') == '%26');
}
}
Many thanks for your help.
Best regards,
Ludivine
I am totally new in SFDC Development and I have a big issue .
The previous Developer in my company has gone and I don't manage to resolve the redirection myself.
I would be fully grateful if someone could correct this code.
The problem of my users is the following :
" When I create a New task ,I fill in the datas in the form and I click on the save button on New Event page , I would like to be redirected to the Current view task page (URL + task id)
instead of to be redirected to the Account page ."
I don't know anything about coding in Apex so I really need your help...
I have currently a Visualoforce page nammed : TaskRedirect with this code :
<apex:page standardController="Task" extensions="TaskRedirectController" action="{!redirect}">
</apex:page>
It is display for a New Task, and below you will find the code of the Apex Class that is called, could you tell me what I should write to be redirect to the URL + Task_id after save??
public with sharing class TaskRedirectController {
public final Task task;
public User userData;
public TaskRedirectController(ApexPages.StandardController redirectController)
{
//get the current record
this.task=(Task)redirectController.getRecord();
userData = [SELECT Business_Group__c, Business_Unit__c, User_Division__c, User_Subdivision__c FROM User WHERE Id = :UserInfo.getUserId()];
}
public PageReference redirect(){
String what_id = ApexPages.currentPage().getParameters().get('what_id');
String who_id = ApexPages.currentPage().getParameters().get('who_id');
String Record_Type = ApexPages.currentPage().getParameters().get('RecordType');
String task_Id = ApexPages.currentPage().getParameters().get('Id');
String accid = ApexPages.currentPage().getParameters().get('AccountId');
if(accid == null)
accid ='';
if(what_id == null)
what_id = '';
if (who_id == null)
who_id = '';
if (task_id == null)
task_id = '';
String str='/00T/e?retURL=%2F001%2Fo&nooverride=1&00N20000001kXCH='+replaceStr(userData.Business_Group__c)+'&00N20000001kXCL='+replaceStr(userData.Business_Unit__c)+'&00N20000001kXCR='+replaceStr(userData.User_Subdivision__c)+'&00N20000001kXCQ='+replaceStr(userData.User_Division__c)+'&what_id='+ what_id +'&who_id='+ who_id;
PageReference r= new PageReference(str);
r.setRedirect(true);
return r;
}
public String replaceStr(String s){
if(s==null) s='';
return s.replace('&', '%26');
}
public static testMethod void test()
{
Task t = new Task();
Apexpages.Standardcontroller stdController = new Apexpages.Standardcontroller(t);
TaskRedirectController testClass = new TaskRedirectController(stdController);
System.assert(testClass.redirect() != null);
System.assert(testClass.replaceStr(null) != null);
System.assert(testClass.replaceStr('&') == '%26');
}
}
Many thanks for your help.
Best regards,
Ludivine
Hi,
Change the code for your redirect method to this
All Answers
return new PageReference('/' + Task.Id);
Hi,
Change the code for your redirect method to this
Thanks a lot for your prompt replies, I think whe are not far :)
I think that I just need to include, the task Id after "Returl" in the String so that when I click on save button on a New Task Page , I would be redirect to the current task record view instead of the home account page (001/o).
Do you know how I could include this parameter in the String ?
String str='/00T/e?retURL=%2F001%2Fo&nooverride=1&00N20000001kXCH='+replaceStr(userData.Business_Group__c)+'&00N20000001kXCL='+replaceStr(userData.Business_Unit__c)+'&00N20000001kXCR='+replaceStr(userData.User_Subdivision__c)+'&00N20000001kXCQ='+replaceStr(userData.User_Division__c)+'&what_id='+ what_id+'&who_id='+ who_id;
Thanks again ;