Map<String, Schema.SObjectType> globalDescrideMap = Schema.getGlobalDescribe();
List<Schema.SObjectType> objectsForConnectionList = new List<Schema.SObjectType>();
for( Schema.SObjectType objectItem : globalDescrideMap.values() ){
if( objectItem.getDescribe().fields.getMap().get('ConnectionSentId') ) != null ){
objectsForConnectionList.add( objectItem );
}
}
But in our case we have more than 100 objects that are available for sharing and this code gets an error:
System.LimitException: Too many fields describes: 101Thus we can create one example of the object and try to add these fields. If the object can be shared we will have the error that this field is not writeable:
System.SObjectException: Field ConnectionSentId is not editableIn case this object is not shareable the error will be:
System.SObjectException: Invalid field ConnectionSentId for Training_Class_Attendee__HistoryThis is the code sample:
Map<String, Schema.SObjectType> globalDescrideMap = Schema.getGlobalDescribe();
List<Schema.SObjectType> objectsForConnectionList = new List<Schema.SObjectType>();
for( Schema.SObjectType objectItem : globalDescrideMap.values() ){
try{
SObject currentObject = objectItem.newSObject();
currentObject.put( 'ConnectionSentId', null);
}catch( SObjectException soExpt ){
if( soExpt.getMessage() == 'Field ConnectionSentId is not editable' )
objectsForConnectionList.add( objectItem );
}
}
If you have any better solution for this issue, please comment.
Enjoy.
No comments:
Post a Comment