I am building an Apex Web Service which will be called from an external mobile application. Because the nature of this application is to go in and out of Salesforce1 (to the other external mobile app), I'd like to retain a "state variable" each time the application calls the Apex code. Can I use a global static variable to retain the state information or is there a better way to handle this in Apex? I'm happy to provide more details about the process if that helps clarify the question.

  • 1
    Apex is transactional based. As such you cannot maintain states in apex between transactions without storing the information somewhere either in the local application or within a salesforce customer object/setting. – Eric Nov 24 '16 at 15:29

In Apex, you can not hold a variable between different transactions programatically. But there is another way which we call Custom Settings.

So you can save that value in custom setting which can be queried in any transaction and can be modified if required. since this is stored in database, it won't get affected.

There are two types of custom settings, List and Hierarchy. Custom Settings.

| improve this answer | |

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.