I have a static method and it has this annotation @RemoteAction so it can be called from java script, I query a list in this method and I want to change a field value and update the list, this doesn't work, because the list is static so it doesn't change the field value, I can't make the method non static since it will not be called then from java script, how to update the queried list?

global static void updateSomething(){
    Account acc= [Select name from Account Limit 1];
    acc.customField__c = 'Hi';
    update acc;
  • 2
    Can you tell us more, what is your requirement and what you have tried, your above code looks fine, inside RemoteAction you can perform any DML operation – NITHESH K Oct 4 '18 at 13:28
  • That is correct, however you can not update something once you declare it in a static method, the question is how to solve this dilemma: the method has to be static, I need to query an object and I should modify it and update it, this doesn't work in a static method, it doesn't let me change something once it is declared. – Roody Oct 4 '18 at 14:08
  • @Roody - there's no reason why you cannot perform a DML update within a static method. What are you referring with this -- however you can not update something once you declare it in a static method? – Jayant Das Oct 4 '18 at 15:04
  • I think you may be confusing static with final. Variables that are simply "static" can be updated (provided you are in the scope of visibility when/where you attempt to do so). If you haven't provided the actual code that you're using, then please do so. We've gotten to the point where you haven't included enough detail for people to be able to identify your problem. Also, it'd be good if you could elaborate on what "didn't work" means in your situation. Are you getting an error message? Are you perhaps looking at some account other than the one that has been updated? – Derek F Oct 4 '18 at 15:17
  • Also, if you haven't done so already, I'd suggest capturing a debug log so you can see the nitty-gritty details about what this code is actually doing. – Derek F Oct 4 '18 at 15:19

Figured out there was nothing wrong in the code, static method still update lists, the problem was in a trigger, which doesn't let the list update, since it was a managed package I couldn't access the code of the trigger, but I knew it is coming from the trigger since I checked in the log console, and also tried to update status field manually, and it didn't update.

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.