.ultrageek. Computers, Music, and Thoughts

6Dec/170

Find the API Name from the Field Label

I recently had a use case where I was going to take a drop down value and use that to pull a value from a separate lookup object. I would have "Hourly" and my logic would return "Hourly__c" which I could then use dynamic SOQL and sObjects to do some magic. I did not want to use hardcoded values or a custom setting lookup table and I thought it would be easy to query the metadata...which turned out to be strangely harder than I thought it would be so here is a working solution:

There are a lot of examples of getting the Label from the API name but not really the other way around.

13Sep/160

Silly Admin Trick: Date Formats without adding Zula Time

Microsoft Excel...it loves to format dates in a crazy way. By default it will do day dash 3 digit month name and 2 digit year like this: 13-Sep-2016. Not helpful. In the U.S. your first instinct would be to change it to 2-digit day dash 2-digit month dash 2 or 4-digit year: 10/13/2016. Salesforce.com does not like either date. Googling 'Date: invalid date' might lead you down the path of adding time to your date...don't do it! Even for Date/Time fields if you don't have a specific time already do the following...

Solution: Take your dates and do a custom format using the following: yyyy-mm-dd