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
Christine F.ax367Christine F.ax367 

Not able to reference the Lookup Field in S-Control where both Lookup fields are related to Account

I have the standard object "Opportunity" having two lookup fields to Account. One is the standard "Account Name" that looks up to Account Object. Then, I have another custom field "Consultant_Firm__c" that lookup to Account also.
 
I wrote a S-Control on Opportunity to override its "New" button and I can reference {!Account.Id} without any problem when I am on an Account that links to the Opportunity through the standard "Account Name' lookup.
 
However, when I am on an Account that links to Opportunity through the "Consultant_Firm__c" lookup field, neither {!Account.Id} nor {!Opportunity.Consultant_Firm__r.Id} would work.
 
I still don't understand what merge fields are, how they are defined and I think this probably has something to do with merge fields. Can this format {!.....} work on a custom lookup field?
 
Thank you!
Christine
CaptainObviousCaptainObvious
Have you tried {!Opportunity.Consultant_Firm__c} ?
Christine F.ax367Christine F.ax367
Yes, unfortunately, this field returns the text instead of the 15 or 18 digit salesforce ID. I was hoping to get the ID out of it so I can do query. But couldn't do much with TEXT. So I am going to try to GetElementIdCS('xxxxxxxxxxxxxxx_lkid').value and see if I an pull the salesforce ID out or not..
CaptainObviousCaptainObvious

To get the actual ID (instead of the text), I'd use a query instead of the merge field:

Select Consultant_Firm__c from Opportunity where id='{!Opportunity.Id}'

It'll add another query to the process but it'll get the job done :smileyhappy:

Christine F.ax367Christine F.ax367
Unfortunately, the code is written from the "override" new button S control, so there is no Opportunity being created at the time of the execution. Opportunity.id doesn't exist yet I suppose?
Christine F.ax367Christine F.ax367
GetElementIdCS('xxxxxxxxxxxxxxx_lkid').value
 failed miserablily too. I am running out of options..
WhyserWhyser

How about  {!Opportunity.Consultant_FirmId__c} ?

That seems to be the standard way of referencing a lookup object's Id from what I've seen.