Hot answers tagged

7

You can use the generic sObject: void recordsByFieldToMap(Map<String, sObject> target, SObjectField field, sObject[] source) { for(sObject record: source) { target.put((String)record.get(field), record); } } It would be used like this: Map<String, License_Item__c> items = new Map<String, License_Item__c>(); recordsByFieldToMap(...


6

This is probably because the clas Name contains the definition of another inner class like this: public class name{ public class test{ } } If so, you have to specify the parent class name before referencing the test inner class. So if you want to make a list of records of type name.test, you have to use: List<name.test>


3

An SObject by itself can be cast to EmailTemplate, however, Map cannot, that happens, because you may have not only EmailTemplate as values in Map, but also other SObjects. Example: Map<String, SObject> sobjectMap = new Map<String, SObject>(); sobjectMap.put('red', new Account(Name = '123')); sobjectMap.put('green', new Contact(LastName = '123')...


2

You can use getRelationshipName to determine the name: for(ChildRelationship rel: SobjectType.Opportunity.childRelationships) { System.debug(rel.getRelationshipName()); System.debug(rel.getChildSObject()); System.debug(rel.getField()); } Please note that not all relationships have a name. Note also that you can't get the parent sObject, it's ...


Only top voted, non community-wiki answers of a minimum length are eligible