function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Frederik Witte 19Frederik Witte 19 

Update of multipicklist field not working?

Hey guys,

I wrote the following class:

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?

Thank you in advance :)!
Best Answer chosen by Frederik Witte 19
sandeep sankhlasandeep sankhla
Hi Frederik,

To resolve this error, you can use set collect all the data in set and then add that set into list adn then do the DML on that list..

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 

All Answers

sandeep sankhlasandeep sankhla
Hi Frederik,

Are you getting any error ? 
Frederik Witte 19Frederik Witte 19
Where could I see an error? The class was successfully transfered to the live version and the schedule said "started at" + time. So it definetly executed the class.
sandeep sankhlasandeep sankhla
Hi Frederik,

You can check the debug logs or you can go and check the schedule jobs from setup adn check if it was scompleted succesfully for any error came and it failed..

Please go to setup >> then apex jobs>> then check your scheduled job executed properly or not..chck the list there..
Frederik Witte 19Frederik Witte 19
Hey Sandeep,

under apex jobs it says: started at 03.04.2015 19:00. So I think it should have been executed. But I can't see any error logs?  

Thank you for your time!
sandeep sankhlasandeep sankhla
Hi Frederik,

Can you share the screen shot of the same ?
Frederik Witte 19Frederik Witte 19
User-added image
sandeep sankhlasandeep sankhla
Hi Frederik,

If it is working finr in your sandbox then in live environment it is not finding the data to update but as you said there are many user where it will satisfy the condition..

Then you can check if you have update access on this object...check the permission on same object..

Thanks,
Sandeep
sandeep sankhlasandeep sankhla
Hi frederik,

I just noticed, your code is not optmized it can surely hit the limit as you have done the DML inside for loop..please replace your code with this code...

list<Realty_User__c> lstRU = new list<Realty_User__c>();
 for(Realty_User__c r : [SELECT Buttons__c FROM Realty_User__c WHERE not (Buttons__c INCLUDES ('Terminplaner'))])
{
            r.Buttons__c += ';Terminplaner';
            lstRU.add(r);
 }

if(!lstRU.isEmpty())
update lstRU;

Please try with this code and let me know if it works for you..

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 
Frederik Witte 19Frederik Witte 19
I honestly have no clue why... But it worked again for the testbox and failed for the live version. Could there be anything else, which could make this fail?
sandeep sankhlasandeep sankhla
Hi frederik,

Can you replace your code with my code which I have provided, then you can test this first in testbox and then you can port this in your live box..

May be it is hitting the limit of DMl because in your live box there is too much data and this will not be the same in testbox..

My code is optimize and it will do only one DML but in your case with your code it will do 730 DML because you have 730 user which will satisfy the condition..
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 
 
Frederik Witte 19Frederik Witte 19
My answer was the answer on your code change :-P. It still didn't work with the changed class. I scheduled it for 22:00 and it made the change only for the testbox.
Frederik Witte 19Frederik Witte 19
I have found the debug log finally and also found the error:

17:00:14.574 (10574150113)|FATAL_ERROR|System.ListException: Duplicate id in list: 003b000000ZAhDgAAL 
sandeep sankhlasandeep sankhla
Hi Frederik,

To resolve this error, you can use set collect all the data in set and then add that set into list adn then do the DML on that list..

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 
This was selected as the best answer
Frederik Witte 19Frederik Witte 19
You are right, it was about this problem. It was not even inside my class. A trigger caused this error.