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(...


3

At that point in your code, Apex only knows that Obj is an Object, because you told the compiler that Obj is an Object, but not a List. You'll need to do some casting to get this to work: for(Object Obj: ValuesLists){ List<Object> parts = (List<Object>)Obj; ServerHostToUsers.put(parts[0], parts[1]); }


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')...


1

With what you have right now, there isn't a way for you to directly put data into lookerByIds. You're forced to accept whatever class.MethodCall() returns. If you can modify classTwo.callList in your unit test, then you have some degree of control, but then your "unit"1 test (for the newContacts() method) has a dependency on another class (alternatively, it ...


1

The primary lever you have to control behavior in a unit test is data. Unit tests execute in an isolated data context. You seed that context with records whose values are designed to force your code down specific execution paths. Here, two things to look at. One, you can't do this: testCon.add(new Contact(AccountId = '0014F00000UtgwqQAB', LastName ='...


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