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

How to make instance persistenly appear in the whole session ?

Good day,


I would like to create an instance for Schema and if it already instantiated then will not required to instantiate again (Singleton pattern), question is how can i make it persistently ? i did try use static and it couldn't serve me that purpose :(


Thanks in advance!



As per the developer's documentation, this data is considered Transient, meaning it will not be stored in the view state and thus discarded each time the page is done processing a single transaction. You can't keep this alive for the entire session.


But what i want is something allow the data persistently keep in long live and even allow other user manage to share with the data if there reach to same instance and no need to instantiate it anymore.


You can't do that with Salesforce like you would in a language like java I'm afraid - Salesforce statics are instantiated per request rather than at class load time.   Programmatic data is only retained across a request, so while you can retain references to data in a Visualforce session by storing them in the view state, you can't make them available to other users.


You can use custom settings to persist data outside of custom objects, but this is still managed by the database rather than stored in the heap or similar.