2

I need to retrieve a set of Record Type Names from a list Custom Setting WEID__c so that I can check that the list includes an Opportunity's Record Type Name, before updating the Opportunity in my Class.

My Custom Setting record's name is the name of the Record Type, while the value is the Record Type Id, which is not needed in this instance so I'm trying to use keyset() to retrieve the record's names.

global void updOpportunityCloseDates() {

    Map<String, Schema.RecordTypeInfo> RT = Opportunity.SObjectType.getDescribe().getRecordTypeInfosByName();
    Map<String, WEID__c> weRTs = WEID__c.getall();
    Set<String> validRecordTypes = new Set<String>();

    validRecordTypes.add(weRTs.keyset());

}

The above causes the error

Incompatible element type Set for collection of String

How should I populate my set validRecordTypes?

4

The add() method in Set collection is used to add a single element to the Set collection.

But keyset() method on a Map return a Set of element which is more than one.

So you should be using

validRecordTypes.addAll(weRTs.keyset());

where addAll() method takes a collection of elements(List or Set) and add all the elements.

Hope it helps.

| improve this answer | |
3

You have to use addAll() method like validRecordTypes.addAll(weRTs.keyset()). add() method is used when you want to add a single element and addAll() method is used when you want to add a set or list elements to the set.

You can also define and initialize your set like shown below -

Set<String> validRecordTypes = new Set<String>(weRTs.keyset());
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.