You need to sign in to do that
Don't have an account?
ERP Team
Pre-populate WhatId in New Task button
Hi All,
I have a Visualforce page on the Account Object
I want to add a button to create a new task for the current account I want to pre-populate the what id field but it's not working
My code :
VF :
Hemdene.
I have a Visualforce page on the Account Object
I want to add a button to create a new task for the current account I want to pre-populate the what id field but it's not working
My code :
VF :
<apex:page standardController="Account" extensions="ContactRelatedListController" sidebar="true" showHeader="false" > <apex:pageblock > <apex:outputLabel value="{!Account.Name}" styleClass="Account"> </apex:outputLabel> <apex:commandLink value="New Task" action="{!newTask}" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;"/></div> </apex:pageblock> </apex:page>Controller :
public class ContactRelatedListController { public Account accounts {get;set;} public Account acc {get;set;} public ContactRelatedListController(ApexPages.StandardController controller) { acc = (account)controller.getRecord(); accounts = [SELECT id FROM account WHERE id=: acc.id LIMIT 1]; } public Pagereference newTask(){ PageReference pageRef = new PageReference('/00T/e?&WhatId=' + accounts.Id+'&retURL='+accounts.Id); pageRef.setRedirect(True); return PageRef; } }Thanks for your help
Hemdene.
Then,you will have to query the Task record and update the record with the Parent Id before update/after Update instead of using before insert/after insert.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
All Answers
Greetings!
Please find the sample code in the below blog which will help you in achieving your requirement.
https://techman97.wordpress.com/2011/10/22/creating-a-new-event-or-task-with-prepopulated-information/
Here,you can replace the custom Object with the Account as you are trying to create the new Task on the Account Object.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
Thank you for you rreply,
This is helpful but what I want is to display the new Task window with the whatId prepopulated with the current account I don't want to actually insert the task I want to be able to add more infos into it
Thanks,
Hemdène.
Then,you will have to query the Task record and update the record with the Parent Id before update/after Update instead of using before insert/after insert.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
Thank you for your help
It worked for me
Best Regards,
Hemdène.