function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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) { = (Contact)controller.getRecord();


public PageReference SendSMS() {


smsTask = new Task (Type='SMS',
WhoID =,
Status = 'Completed',
ActivityDate =,
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');