+ Start a Discussion
F SmoakF Smoak 

DML requires SObject or SObject list type: Set<String>

I have written a beow code where I have a text field on my object which populates duplicate values of territory name. I need to retrieve a set of this field value (in form of string as the field data type is text) but getting following error.- DML requires SObject or SObject list type: Set<String> in below bold line
Please help!
trigger CMS_Insert_MCCP on CMS_Rule_Line_Item__c (after Insert) {
    List<Territory> territoryList = new List<Territory>();
    List<MC_Cycle_Plan_vod__c> mccp =  new List<MC_Cycle_Plan_vod__c>();
    Set<String> teamList = new Set<String>();
        for(CMS_Rule_Line_Item__c crRecord: Trigger.new){
       insert teamList;
AnudeepAnudeep (Salesforce Developers) 
I suggest changing  Set<String> teamList = new Set<String>(); to List<CMS_Team__c> teamList = new List<CMS_Team__c>
AnudeepAnudeep (Salesforce Developers) 
Also, note that set class is not an iterable object type, and cannot participate in several common functions yet, including DML operations which is why it needs to be converted to a List

Let me know if this helps

F SmoakF Smoak
I tried this and when I do that I get error in line teamList.add(crRecord.CMS_Team__c); 
as: Method does not exist or incorrect signature: void add(String) from the type List<CMS_Rule_Line_Item__c>
AnudeepAnudeep (Salesforce Developers) 
If crRecord.CMS_Team__c is a string I recommend changing it to List<String> teamList = List Set<String>();

Let me know if that still gives you an error