0

I've a requirement, where I want to edit a task. Task are displaying as a VF Page in Pageblock Table. I've used action="{!URLFOR($Action.Task.edit,items.id)} on commandlink.

Can anyone please let me know, how I can get back to account after saving event.

VF:

<apex:page standardController="Account" extensions="myControllerExtension">
<apex:form>
<apex:pageBlock>
    <apex:pageBlockSection columns="1">
        <apex:pageBlockTable value="{!tasklist}" var="items" > 
            <apex:column headerValue="Action">
                <apex:commandLink target="_blank" action="{!URLFOR($Action.Task.edit,items.id)}">Edit</apex:commandLink>
                &nbsp; | &nbsp;
                <apex:commandLink target="_self" action="{!URLFOR($Action.Task.edit,items.id)}">Cls</apex:commandLink>
            </apex:column>  
            <apex:column value="{!items.Subject}"/>
            <apex:column value="{!items.WhoId}"/>
            <apex:column value="{!items.WhatId}"/>
            <apex:column value="{!items.TaskSubtype}"/>
            <apex:column value="{!items.ActivityDate}"/>
            <apex:column value="{!items.Status}"/>
            <apex:column value="{!items.Priority}"/>
            <apex:column value="{!items.OwnerId}"/>
        </apex:pageBlockTable>
    </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

Extension

public class myControllerExtension {
public Account acct {get;set;}
public List<Task> tasklist  {get;set;}
public List<Account> accList {get;set;}

public myControllerExtension(ApexPages.StandardController stdController) {
    acct = (Account)stdController.getRecord();
    tasklist = [Select Id,WhoId,WhatId,ActivityDate, Subject,Status,Priority, OwnerId,TaskSubtype from Task where Account__c=:acct.ID];  
}   

}

I was trying to use retURL in action but its showing error. Could you please help me out?

Thanks, Ashish Singh

  • How are you accessing the custom visualforce page? Through the Account related list or somewhere else? – TSmith Mar 31 at 13:42
0

From apex you can look at this documentation to help you redirect back to the account page https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_system_pagereference.htm.

From the visualforce if you want to use URLFOR Function you have the accountid already you have account as your standard controller. Just make sure you use this param to you page ?id={AccountId}

{! URLFOR($Action.Account.View, account.Id)}

If you want to redirect from a standard edit page please see this question it has an answer that will solve this problem How to give return url for a Standard Edit Page.

Make sure that when you do a URLFOR function you include it though something like this

{!URLFOR($Action.Task.edit,items.id,[retURL=account.Id])}

| improve this answer | |
  • Hi Zach, Thanks for the answer. However while clicking on edit button on Task from VF embedded on my account, I'm redirected to standard edit page of task. After saving there, I want to get back to same account. Is there a way I can use retURL while navigating to standard edit page of task?? If you want I can add some screenshot? – Ashish Singh Mar 31 at 13:52
  • If this solved your answer it helps if you up vote and mark it as correct solution. If this does not solve your answer please ask questions here and maybe I can edit my answer to be more sufficient. Thanks! – Zach Hutchins Mar 31 at 13:54
  • @AshishSingh I have changed my answer to include what i believe you are talking about – Zach Hutchins Mar 31 at 14:07
  • Hi Zach, This is what I'm trying to write but I get syntax error. <apex:commandLink target="_self" action="{!URLFOR($Action.Task.edit,items.id,[retURL=account.Id])}">Cls</apex:commandLink> . whenever I add [retURL=account.Id] I get the error Syntax error. Extra ')'. – Ashish Singh Mar 31 at 14:15
  • Thanks a lot Zach, you saved my day. It working perfectly. – Ashish Singh Mar 31 at 14:24

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.