How to create a Task with Due Date using URLFOR

I want to code a button on a custom object to generate a task with some precompleted fields. I can do it like this:

/00T/e?what_id={!My_Object__c.Id}&tsk5="This is a Task"&tsk4={!TODAY()+21}&retURL=URLFOR($Action.My_Object__c.View,  My_Object__c.Id)])}

And it works; TODAY() is populated with “14/08/2014”.

But I’m dependant on url structure. Eg suppose /00T/ changes to /00TA/.

It is preferable to use URLFOR().

Eg:

{!URLFOR($Action.Task.NewTask, null, [what_id=My_Object__c.Id, tsk5="This is a Task", tsk4=TODAY()+21, retURL=URLFOR($Action.My_Object__c.View,  My_Object__c.Id)])}

This will not work. In this case TODAY() is populated with “Thu Sep 04 00:00:00 GMT 2014” not “14/8/2014”.

TODAY() returns data in a different format depending on whether its used in a hardcoded URL or within a URLFOR(). So is there a way to pass in a value to “tsk4” that is formatted correctly?

PS. Where is the documentation for generating Tasks through URLs? I can see people do it. I can see it works. I can’t see any Salesforce documentation.

Answer

What you are trying to do is referred to as URL hacking, which is not supported by Salesforce. You are correct that your solution could break should Salesforce make any backend changes. I would propose that rather than trying to use URLFOR() to account for this, you look into using Publisher Actions. Publisher actions all but make URL hacking a thing of the past. It allows you to choose predefined values.

The best part about it is that this IS Salesforce supported so you don’t have to worry about it breaking.

Here are some resources on using publisher actions instead of URL hacking

http://help.salesforce.com/help/pdfs/en/actions_impl_guide.pdf

http://salesforcewizard.wordpress.com/2014/01/08/great-url-hack-meet-the-chatter-publisher-action/

http://bobbuzzard.blogspot.com/2013/07/publisher-actions-not-just-creating.html

https://developer.salesforce.com/forums/ForumsMain?id=906F00000009EToIAM

Attribution
Source : Link , Question Author : powlo , Answer Author : Chris Duncombe

Leave a Comment