Frederik Witte
Frederik Witte

Reputation: 1345

Update of multipicklist field not working in SalesForce?

I wrote the following class in salesforce:

global class ChangeImmo implements Schedulable{
 // Execute method
    global void execute(SchedulableContext SC) {
        List<Realty_User__c> rs = [SELECT Buttons__c FROM Realty_User__c WHERE not (Buttons__c INCLUDES ('Terminplaner'))];
       for(Realty_User__c r : rs){
           r.Buttons__c += ';Terminplaner';
           update r;
       }                                                                           
    }
}

Then I sheduled it for a one time run.

It worked on our testbox, but not in the live version. We have 1700 users, of which around 730 don't have the "Terminplaner". Does someone know, why this is not working?

Edit: I adjusted my code with the guide on DML exceptions by SalesForce and it is still not working:

global class ChangeImmo implements Schedulable {

    // Execute method
    global void execute(SchedulableContext SC) {

        for (List < Realty_User__c > lstRu: [SELECT Buttons__c FROM Realty_User__c WHERE not(Buttons__c INCLUDES('Terminplaner'))]) {
            for (Realty_User__c r : lstRu) {
                r.Buttons__c += ';Terminplaner';
            }
            update lstRu;
        }
    }
}

Edit 2: Okay I have found the debug log now and the error says:

17:00:14.574 (10574150113)|FATAL_ERROR|System.ListException: Duplicate id in list: 003b000000ZAhDgAAL

Upvotes: 0

Views: 167

Answers (2)

nickzenko
nickzenko

Reputation: 46

003 - it's a prefix of Contact object. Looks like you have some trigger in your production that work with contacts after you update Realty_User__c object.

Upvotes: 1

naveen
naveen

Reputation: 159

    global class ChangeImmo implements Schedulable{

// Execute method

global void execute(SchedulableContext SC) {
    List<Realty_User__c> rs = [SELECT Buttons__c FROM Realty_User__c WHERE not (Buttons__c INCLUDES ('Terminplaner'))];
   for(Realty_User__c r : rs){
       **r.Buttons__c += ';Terminplaner';**
       update r;
   }                                                                           
}

}

Seems you are not updating values.

ex:r.Buttons__c += 'value1;value2;Terminplaner'; update r;

Upvotes: 0

Related Questions