I have an exhaustive list of custom objects whose API Names and labels does not match. I end up opening each object in order to determine if the label has matching API Name.I want to see the API Name displayed along with label on the result page of custom Objects. Is there a better way to get label for a custom object when its API Name is known?
[SalesForce] Get Label For SObject API Name
Related Solutions
I think developers just become resigned to how painful simple refactoring like changing a name is after a while, either accepting the pain involved or choosing to just leave the bad name. Or choosing to move to a different platform.
(A Java project in an IDE naturally gets broken as you refactor and being able to work through the various changes and then eliminate errors is a natural way to work. Yes consistency checking is good but not when it blocks intermediate work steps.)
My general strategy could be summarised as:
- add
- change references to the new
- migrate data from old to new (if necessary)
- then delete the old
This works for SObjects, SObject fields, and Apex. With a local copy of everything grabbed by an IDE, a copy of an SObject with a different name but the same fields can be made. And at least global search and replace can be used to do the change part consistently.
This approach avoids nasty situations in Apex where there are circular references. I've seen colleagues struggle for hours with compilation errors (often not clearly reported by the platform when the circular reference is indirect) when e.g. changing a constructor or method name. The add/change/delete approach keeps the code compiling (and therefore deploying) through each step.
Internal Server Errors are just that; errors that occur in the runtime environment that are not accounted for. For example, the runtime knows how to express a NullPointerException, but it doesn't know how to handle something like a missing translation. You can observe this in action with the following code (as of the time of this answer, anyways):
System.debug(
Id.valueOf('00Y000000000000').getSObjectType()
.getDescribe().getLabel()
);
Once the system encounters a situation it can't handle, the only thing it can safely do is to abort the current transaction, log the error, and inform the user. The reason why your Apex Code can't handle the exception is because it's occurring in the underlying runtime system.
If you've ever had a Blue Screen of Death on a Windows system, you could consider it to be roughly analogous to what's happening with an Internal Server Error. A BSoD halts the system so that no further damage can occur to the system. Similarly, an Internal Server Error halts the transaction so that the underlying system doesn't crash entirely.
If you want to determine the existence of a label, you're going to have to use an alternative API, such as the Metadata API wrapper. In the future, you should be able to use the Apex Metadata API, but this is not available in the current release (with no known date when CustomLabel will be supported).
Best Answer
You can get the label using the
DescribeSObjectResult
:Another common syntax is:
You can also just one-line it: