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
sfdcfoxsfdcfox 

$ObjectType[ObjectName]['Label']

I remember this working previously (or some incarnation thereof), but it's not working now when I'd actually like to use it. Does anyone know what the new method for displaying a dynamic sobject's label is without resorting to a describe call in a controller or extension?

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

There is definitely a bug here with a $objectType dynamic reference. 

 

There is a weird possible workaround.   It appears if you have a reference to fields that precedes it, then the label reference works ok.  

 

e.g.

 

{!$ObjectType[objectname].fields.name}

 

You could maybe embed such a reference in a hidden field. 

 

All Answers

Abhay AroraAbhay Arora

{!$ObjectType.Account.Fields.Name.Label}

$ObjectType.Role_Limit__c.Fields.Limit__c.

Above is what you need?

 

 

sfdcfoxsfdcfox

I have a custom component that works across multiple objects, so I need to be able to display the object's label dynamically; the page won't know what it's displaying until runtime. I think I'm going to just waste a getDescribe() in my controller, as much as I hate to do this. I know it was working before, but it's failing to work now, and I don't really have time to research why.

Abhay AroraAbhay Arora

The describe is the only option i think because i tried in my dev org and didnt got the label

salesforce@reserveadvisors.comsalesforce@reserveadvisors.com

Any news on this? I was trying to do something similar, but I couldn't get it to work. I posted about it here http://boards.developerforce.com/t5/Java-Development/Javascript-GETRECORDIDS-on-Contract-to-Return-Account-Ids/td-p/439347 .

aballardaballard

There is definitely a bug here with a $objectType dynamic reference. 

 

There is a weird possible workaround.   It appears if you have a reference to fields that precedes it, then the label reference works ok.  

 

e.g.

 

{!$ObjectType[objectname].fields.name}

 

You could maybe embed such a reference in a hidden field. 

 

This was selected as the best answer
salesforce@reserveadvisors.comsalesforce@reserveadvisors.com

I am not quite sure that I follow. Are you talking something like this?

 

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} 
var checked = {!GETRECORDIDS($ObjectType[Contract].fields.AccountId)}; 
window.location= "/apex/FN__FindNearbymap?alids="+checked;

 

Or adding a test field that says $ObjectType[Contract].fields.AccounId and referencing that someone?

 

*EDIT* I can probably take out that "REQUIRESCRIPT" portion, right?

sfdcfoxsfdcfox

Thanks for the bug workaround; I just tested it and it works. I'll use this workaround now. It'll be nice when they get it fixed. Your workaround saves me an unnecessary describe call.

sfdcfoxsfdcfox

And yes, that script include is only if you plan on using the API, which you don't (at least, not in the snippet). It doesn't resolve my current problem though, but the other response did fix the problem admirably.

salesforce@reserveadvisors.comsalesforce@reserveadvisors.com

sfdcfox, would you be able to post a code snippet of it? I don't quite follow aballard's explanation.

sfdcfoxsfdcfox

It works something like this:

 

<apex:page ...>
  <apex:outputText rendered="false">{!$ObjectType[entityName].fields.Id.Label}</apex:outputText>
  <apex:sectionHeader title="{!$ObjectType[entityName].Label}" subtitle="{!Object__c['Name']}"/>
  ...
</apex:page>

Basically, by accessing fields at least once, it corrects the object's describe. I believe it has to be "before" the attempt to use the label, but doesn't need to be rendered (but does need to be evaluated).

salesforce@reserveadvisors.comsalesforce@reserveadvisors.com

Oh, I see now. Is this exclusive to apex? I was trying to use this in a javascript button using the getrecordids function. The documentation on this function was pretty minimal so I wasn't aware it was intended for apex.

 

Thanks.

sfdcfoxsfdcfox

As far as I'm aware, $ObjectType has to use a discrete object when you're trying to use GETRECORDIDS (it basically substitutes the object key into the formula).

 

You use GETRECORDIDS as follows:

 

var records = {!GETRECORDIDS($ObjectType.Account)}

This places a JavaScript Array into the variable "records", with each numerical index location being a selected record ID.

salesforce@reserveadvisors.comsalesforce@reserveadvisors.com

Mhmm, that explanation seems to make sense. The issue I have is that the ObjectType field does not determine the actual record ids; rather the type of record selected in the list view determines that. So for example, I have a contract list set up, and my button is to output the "records" variable below. Instead of returning an Account Id, it returns the Contract Id instead. I need the Account Id in my situation...

 

var records = {!GETRECORDIDS($ObjectType.Account)}