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
Debasish Paul 11Debasish Paul 11 

Can anybody please explain the query caching in salesforce with example?

Please explain query caching with example.
You can use a static variable in a helper class to cache the result while running a single transaction.
public class UserProfileHelper {
private static Profile userProfile;
            public static Profile getProfile() {
                       if (userProfile == null)
                             userProfile = [select Id, Name from Profile where Id = :userInfo.getProfileId()];
                             return userProfile;
Reference :
Shruti khodaboleShruti khodabole
1) You can use the global variable "Useinfo.getProfileId()" if you only need profile id.
2) You can use static variable to cache profile you query. see code:
public static Profile CachingProfile;
 public constructor method(){ 
CachingProfile = [Select id, name From Profile Where id=:userInfo.getProfileId()]; 

Shruti Khodabole
Salesforce Developer