+ Start a Discussion

Return Task page which is associated with contact

Hi can any one help me on this problem.

In below i have created a task in a specific contact.while i am click the send button in visualforce page the following task will be created and goes to particular contact page whic id we have passed.but i dont want to go my contact page.I want to go my task page which i have previously created in the following code.

here be my sample code.


private final Contact contact;

public Task smsTask;

public SendSMSHttpContact(ApexPages.StandardController controller) {
this.contact = (Contact)controller.getRecord();


public PageReference SendSMS() {


smsTask = new Task (Type='SMS',
WhoID = contact.id,
Status = 'Completed',
ActivityDate = System.today(),
Description = msg.replace('%20',' '),
Subject = 'SMS Sent'
try {
insert smsTask;
} catch (System.Dmlexception e) {
System.debug('Error: Unable to insert task: ' + e);
return new ApexPages.StandardController(contact).view();/*here i am returning to contact page,I want to go task page which i have created*/




Best Answer chosen by Admin (Salesforce Developers) 

return new PageReferecnce('/'+smsTask.Id');