Sample Code:
- Set < String > listsObjs = new Set < String > {‘Account’, ‘Lead’};
- Map<String, Schema.SObjectType > globalDescription = Schema.getGlobalDescribe();
- for ( String obj : listsObjs ) {
- Schema.sObjectType objType = globalDescription.get( obj );
- Schema.DescribeSObjectResult r1 = objType.getDescribe();
- Map<String , Schema.SObjectField > mapFieldList = r1.fields.getMap();
- for ( Schema.SObjectField field : mapFieldList.values() ) {
- Schema.DescribeFieldResult fieldResult = field.getDescribe();
- String fieldLabel = fieldResult.getLabel().toLowerCase();
- Schema.DisplayType fielddataType = fieldResult.getType();
- if ( fielddataType == Schema.DisplayType.Email ) {
- System.debug( objType + ‘.’ + fieldResult.getName() );
- } else if ( fieldLabel.contains( ’email’ ) && ! fieldResult.isCalculated() ) {
- System.debug ( objType + ‘.’ + fieldResult.getName() );
- }
- }
- }
In the Developer Console, select Debug Only to see the debug logs.