1

I have a question regarding populating a field (Field 'fieldtest' whose Id is 00H280000073992) in a custom object (ContactDetail__c). I used the URL hack tip, and it works.

{!URLFOR($Action.ContactDetail__c.New, null, [Name='testname', 00H280000073992='test'])} 

However, I'm wondering if the use of the Id in the formula can be dangerous when the org is deployed to another environment.

When I use the name of the field :

{!URLFOR($Action.ContactDetail__c.New, null, [Name='testname', fieldtest='test'])}

The field 'fieldtest' is not populated.

Update - In Reponse to Tushar's Answer Thanks Tushar, I created a hierarchical CS.

IdLabel__c.ContactId__c = 00H280000073992

However, I'm having trouble including it in my formula.

First, I tried :

{!URLFOR($Action.ContactDetail__c.New, null, ["Name"="testname", "Test"=$Setup.IdLabel__c.ContactId__c])} 

Result :

URL : Name=testname&Test=00H280000073992 (good but I need inversion)

However, when I try :

{!URLFOR($Action.ContactDetail__c.New, null, ["Name"="testname", $Setup.IdLabel__c.ContactId__c="test"])}

Syntax check fails :

Error: Syntax error. Missing Unknown token: 23

Finally, with :

  {!URLFOR($Action.ContactDetail__c.New, null, ["Name"="testname", "$Setup.IdLabel__c.ContactId__c"="test"])}

I got :

URL : Name=testname&%24Setup.IdLabel__c.ContactId__c=test

Thanks for your answer

  • 3
    I'm voting to close this question as off-topic because old question that op has a good answer for but is unlikely to return to accept it – Eric Sep 6 '16 at 7:29
  • You can't use $Label in key/value pairs like that. – Adrian Larson Sep 6 '16 at 11:22
1

Yes it is because when you move your code into another org there are very good chances that Field IDs are changed. Now you have three options left(AFAIK).

  1. Query these field using tooling API and then use but as it is a formula you cannot use this.

  2. Store ID in custom setting and then refer the value from custom setting(Create hierarchical CS). If you want to create Package then it is best approach.

  3. After move your code change the value in another org because SF don't change these Id so you don't have to update them regulary.

  • Four point 2 (custom settings), is it like custom labels ? – yassine Nov 18 '15 at 11:39
  • @yassine update my nswer – Tushar Sharma Nov 18 '15 at 11:53
  • Thanks Tushar, I created a hierarchical CS. IdLabel__c.ContactId__c = 00H280000073992 However, I'm having trouble including it in my formula. First, I tried : {!URLFOR($Action.ContactDetail__c.New, null, ["Name"="testname", "Test"=$Setup.IdLabel__c.ContactId__c])} Result : URL : Name=testname&Test=00H280000073992 (good but I need inversion) However, when I try : {!URLFOR($Action.ContactDetail__c.New, null, ["Name"="testname", $Setup.IdLabel__c.ContactId__c="test"])} Syntax check fails : Error: Syntax error. Missing Unknown token: 23 – yassine Nov 19 '15 at 10:01
1

One workaround would be to merge them all in a string: '/00T/e?'$Setup+'=val' but that doesn't work too well when you want to leverage the built in globals like $Action.Lead.ConvertLead etc. It looks like "missing unknown token: 23" occurs when you combine all these at once:

  1. formula evaluation
  2. the function URLFOR(action, id, [KEY=VAL])
  3. $Label or $Setup in the parameter KEY (note, it does work alright in VAL)

Here is a middle ground that gives you the best of both worlds by nesting two URLFOR functions:

{!URLFOR(
URLFOR($Action.Lead.Convert, Lead.Id)
+ '&' + $Label.CFID_CALLOUTCOME + '_fu=' + 'BOOKED'
+ '&' + $Label.CFID_CALLOUTCOMEREASON + '_fu=' + 'BOOKED_BOOKED'
, null, [
'RecordType_fu' = $Label.RTID_CALL,
'tsk5_fu' = 'Call: ' + TEXT(Lead.Status),
'who_id' = Lead.Id,
'tsk4_fu' = Today,
'close' = '1',
'saveURL' = URLFOR($Action.Lead.View, Lead.Id),
'retURL' = URLFOR($Action.Lead.View, Lead.Id),
'owner_id' = Lead.AppointmentCourseConsultant__c,
'sc'=1
]
)}

When the evaluated $Setup or $Label is a URL key, only append the string:

+ '&' + $Label.CFID_CALLOUTCOME + '_fu=' + 'BOOKED'

When the evaluated $Setup or $Label is a URL value, use the proper mechanism:

'RecordType_fu' = $Label.RTID_CALL

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.