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>();



The above causes the error

Incompatible element type Set for collection of String

How should I populate my set validRecordTypes?

2 Answers 2


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


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

Hope it helps.


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());

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .