Last active
June 29, 2016 15:12
-
-
Save scottbcovert/6b2ce8c5de85e8f0735c2c5469ba3bf2 to your computer and use it in GitHub Desktop.
Troubleshooting getPopulatedFieldsAsMap() Apex Method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contact c = [SELECT Name FROM Contact LIMIT 1]; | |
c.Title = 'President'; | |
Map<String,Object> fieldsMap = c.getPopulatedFieldsAsMap(); | |
System.debug(fieldsMap); | |
// DEBUG|{Id=003XXXXXXXXXXXXXXX, Name=Jack Rogers} | |
System.debug('Field Map Size: ' + fieldsMap.size()); | |
// DEBUG|Field Map Size: 2 | |
for (String fieldName : fieldsMap.keySet()) | |
{ | |
System.debug('Field Name: ' + fieldName); | |
} | |
// DEBUG|Field Name: Id | |
// DEBUG|Field Name: Name | |
Object TitleValue = fieldsMap.get('Title'); | |
System.debug('Title Value: ' + TitleValue); | |
// DEBUG|Title Value: null | |
Boolean containsTitle = fieldsMap.containsKey('Title'); | |
System.debug('Does FieldsMap Contain Title? - ' + String.valueOf(containsTitle)); | |
// DEBUG|Does FieldsMap Contain Title? - false | |
c = new Contact(); | |
c.Title = 'President'; | |
fieldsMap = c.getPopulatedFieldsAsMap(); | |
System.debug(fieldsMap); | |
// DEBUG|{Title=President} | |
System.debug('Field Map Size: ' + fieldsMap.size()); | |
// DEBUG|Field Map Size: 1 | |
for (String fieldName : fieldsMap.keySet()) | |
{ | |
System.debug('Field Name: ' + fieldName); | |
} | |
// DEBUG|Field Name: Title | |
TitleValue = fieldsMap.get('Title'); | |
System.debug('Title Value: ' + TitleValue); | |
// DEBUG|Title Value: President | |
containsTitle = fieldsMap.containsKey('Title'); | |
System.debug('Does FieldsMap Contain Title? - ' + String.valueOf(containsTitle)); | |
// DEBUG|Does FieldsMap Contain Title? - true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment