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
sdetweilsdetweil 

problems with reference field using URLFor()

we are building out our Serice Cloud implementation, and need to create a custom object while viewing a case.

we created a button on the case, which uses URLFor to open the 'new' page of our custom object.  this works fine..  the page appears and the cancel button returns back to the case.

 

now we want to pre-populate some of the cusotm object fields.

 

so we reviewed the new page filed labels, and used them as the parameters.  and the data appears in the new() object form as expected, except for one.

 

on the object is an Account Lookup field.

 

in the URLFor() we pass CF00NQ0000000ld3l = Case.Accountid as the parameter.  the 18 char account ID string appears in the new() form, but we had expected it would show the 'account Name' instead of the ID field. it reports an error (not found).. if we export the accounts, this IS the id of the account object referenced in the case object.  we cannot manually 'search' using the ID successfuly either.

 

Using the Object field names doesn't work either. 

 

so, what did we miss?

 

we've spent about 12 person hours trying to debug this.. to no avail.

URLFOR($Action.Newobj__c.New,null,[
CF00NQ0000000ld3l_lkid=Case.Account],false);

 

 

sam

bob_buzzardbob_buzzard

Lookup fields are a combination of a hidden field containing the id and a visible field containing the name.  You'll need to populate both of these.

 

ed_hilperted_hilpert

We have loaded both the hidden Id and Name into the Newobj.  Problem is it doesn't appear as though Case.Account has the name in there.  Also, when we try and load literals into the Newobj (Title, Description), the literal strings don't get loaded into the Newobj.  So the result we get is the AccountId is loaded into the LOOKUP field instead of the name, and actioning the search with that Id doesn't find the actual Account entry.

 

 

{!URLFOR($Action.Newobj__c.New,null,[
CF00NQ0000000ld3l_lkid=Case.AccountId,
CF00NQ0000000ld3l=Case.Account,
TF00NQ0000000lYxK='this is a test',
CF00NQ0000000lYxj='description',
retURL=URLFOR($Action.Case.View,Case.Id)])}

 

 

 

 

bob_buzzardbob_buzzard

For this parameter:

 

CF00NQ0000000ld3l=Case.Account,

 Case.Account is a reference to an account, not the account name itself, so it may be that resolves back to an id when used.  I think you'll need something like:

 

CF00NQ0000000ld3l=Case.Account.Name,

 

ed_hilperted_hilpert

Post script to previous post: A literal placed into CF00NQ0000000ld3l='ABC' (the name of the entity we're actually trying to manipulate) *does* show in the Newobj new() panel, and works when you press 'save'.  But case.account.name which should have the same value in it does not operate correctly.

bob_buzzardbob_buzzard

What does the URL look like when you use case.account.name?

ed_hilperted_hilpert

Actually, Case.Account.Name doesn't exist... gets a 'field does not exist' error.

ed_hilperted_hilpert
https://cs3.salesforce.com/a2X/e?retURL=%2F500Q0000003LQYQ%2Fd%3FretURL%
3D%252Fservlet%252Fservlet.Integration%253FscontrolCaching%253D1%2526lid%
253D00bQ0000000MTrh%2526eid%253D500Q0000003LQYQ%2526ic%
253D1&nooverride=1&CF00NQ0000000ld3l_lkid=001Q000000LEhDq&CF00NQ0000000ld3
l=001Q000000LEhDq

  

this was generated with the URL code posted earlier

bob_buzzardbob_buzzard

Hmm.  It looks like buttons only access fields on the object itself, rather than follow references.  The field is labelled account name but its actually an account lookup, which I would imagine is why it translates to an id.

 

While its not the most elegant solution, you could try adding a formula field to the case which actually pulls in the account name.  Then use that formula field as the value in the URL.

ed_hilperted_hilpert

Inelegant or not, creating a hidden field with a formula assigning the Account.Name worked!  Thanks Bob!

 

For others following this thread, here is the final code.

 

{!URLFOR($Action.Newobj__c.New, null,  [
CF00NQ0000000ld3l_lkid= Case.AccountId ,
CF00NQ0000000ld3l= Case.Account_Name_String__c ,
retURL=URLFOR($Action.Case.View, Case.Id)
], true) }

// where I created custom field Account_Name_String and created
// a simple formula: Account_Name_String = Account.Name
// also make the field not visible, read only, and not in any views