Hot answers tagged

29

By looking at this article on Lightning Components Performance Best Practices, it looks like the only way to solve the cache problem is to disable the cache during development and keep it on in Production. To disable the cache in the org: 1) Setup > Security > Session Settings > Caching. 2) Uncheck Enable secure and persistent browser caching to improve ...


27

The two types of data stores are used for entirely different things. The platform cache is temporary cache, much like what a web browser uses to look up recently used data, while custom settings are more of a permanent cache, which basically means it won't go away until someone tells it to. Custom settings are great for simple types of data that should ...


14

I'd say it depends on how you are using the Map<String, CustomSetting__c> that getAll()returns and how may list records there are. If you are looping over the map values() searching for a single record based on a field other than the Name then SOQL would probably serve you better as you could just grab the required records. One thing to note with the ...


10

Summary - getAll() is >10x faster, but SOQL is still fast Based on my testing scenario, using custom settings instance methods offer ~40x performance improvement, in addition to the advantages of not consuming a query limit. However, both are still pretty fast so this sort of tuning probably isn't the best focus of optimization. This increase is must less ...


6

Process Builder is bulkified, which means it would only perform one query per 200 records. That said, if you wanted to store data in a static variable, it would persist across the entire transaction, in before triggers, after triggers, and yes, even InvocableMethod calls. I would suggest simply trying the query-then-assign method by using Process Builder + ...


6

What do I need to do to designate a partition as default? Check the "Default Partition" checkbox on the partition to make it the default partition. This is the first checkbox on the Platform Cache Partition Edit page. What would I need to change in the code to make it work with the partition? If you have a default set, no need to do anything. Otherwise, ...


5

Yes, this is the issue with lightning:isUrlAddressable It's not refreshing the view. To resolve this Use change aura:handler of pageReference to call the same init method. Example <aura:handler name="init" value="{!this}" action="{!c.init}" /> <aura:handler name="change" value="{!v.pageReference}" action="{!c.init}" /> or else you can also ...


5

If your Process Builder is doing any record field updates then be aware that each of these is dealt with in a separate invocation of your entire "save procedure", as per point 14 in the order of execution documentation, but as part of the same transaction/session. This can cause you all sorts of trouble if any related triggers are not written to ...


5

Yes, hashCode is reliable, although strictly speaking, unnecessary. You could use the object itself: private static Map<Object, List<Account>> accountCache; public static List<Account> GetAccounts(List<Id> accountIds) { if(accountCache.get(accountIds) == null) { accountCache.put(accountIds, [select Id from Accounts limit ...


4

Storable actions should be idempotent, meaning each time the action is called with the same parameters, it should return the same data. If this is not the case, storable is probably not a good choice for you. You should only set ignoreExisting to true when you know the data has been invalidated because of record changes, as mentioned in the documentation: ...


4

I'm using a storable action (to get some metadata) that is called from multiple components. I see the behaviour mentioned in the Storable Actions documentation that when multiple requests are made for the same key: The responses to idempotent actions can be cached and quickly reused for subsequent identical actions. For storable actions, the key for ...


4

I have also been suffering form this issue. I use a lightning.recordEditForm component with some visible and some hidden lightning:inputField elements inside it, to create a clone Quote record inside a Quote record. My debug findings: This is the JSON that onerror event returns from server for this error: {"error":{"statusCode":400,"errorCode":"...


3

There's no way to know for certain. Caches are designed to last as long as possible, but also to be evicted when they are invalidated (e.g. because a record changed) or when resources are required. There's also the added complexity of hardware and OS-level caches that also improve performance "randomly." These parameters are also tweaked on a fairly regular ...


3

If you cast your mind back to Dreamforce 2016 Josh Kaplan did a talk on the new (at the time) apex compiler. See Peek Under the Hood of the New Apex Compiler. It included details on how compiled apex is cached for use on the app servers. ApexCache and ApexCacheWarmer are almost certainly related to that functionality. I checked with Chris Peterson. ...


3

If you do not specify the partition it simply means default partition will be used. I suggest to create a partition and have it as default. Having a default partition is required for the short hand syntax you are using. The syntax you have currently assumes you have default partition in the org and it short hand syntax. You don’t need the fully qualified ...


3

In the end I was able to get this working with the following 2 changes: I switched to v2.3 of ChartJS (maybe 2.4 would have worked also). Either there is a bug in 2.5 or it is not compatible with the way I am using it. I replaced the code to get the Canvas element as below, previously using getElementById. (This is contrary to a number of other posts that ...


3

I had a similar problem with Accounts that sounds very similar to what you're getting now. Every morning an Account record would not load. Typically, it would time out until you refreshed the record anywhere between 3 or 4 to dozens of times. Then, it would work fine. The whole object, not just that record. You're right in that it's a caching issue, but ...


3

Yes, you'll want to file a bug; this is something happening within the system code (and it shouldn't be). For now, do not attempt to call the cache methods without first checking for a session: if(UserInfo.getSessionId() != null) { // It should be safe to use Cache.Session now.


3

I have had this same sort of thing happen before. Rough description: The root cause had something to do with how transactions are handled behind the scenes and what has been committed to the DB for other transactions to see. In this situation, even though the update is done it is till not fully available in the DB. So, when code from a different ...


2

You can clear your coverage in Setup > Develop > Apex Test Execution > View Test History > Clear Test Data. Afterwards, you can go to Setup > Develop > Apex Classes, and choose Run All Tests to regenerate your coverage.


2

Salesforce will actually perform a real SOQL every time you will do a SOQL ( a fresh retreive from database). Selected Sobjects are not cached, at least not in a way that SOQLs are not performed. You can try following: A - child object B - parent object Create a formula field X on child A that points to any field from parent B. Create and select instances ...


2

I'm going to use my comment then expand on the explanation a little bit. Comment from question: x is a variable in your class. You are instantiating c as a CacheableClass and putting it in your cache, then modifying the same object c. Which is cached. Deeper explanation: The cache holds a reference to where c is held in memory. It doesn't make another ...


2

I finally got a proper response from SFDC support saying that there is a known issue (P1). There must be a set of specific circumstances in order to reproduce this. I've also tried a bunch of other things like time based workflows, process builder etc. This isn't a proper answer, though once I find out the exact steps and a workaround, I'll update it. If ...


2

I had to set Session and Org Cache allocation. Once I did, the code above worked.


2

It sounds like a good use case for Platform Cache, specifically the org-level cache. The challenge is sizing the cache partition(s) versus your data. From the docs: Org Cache Limits Maximum size of a single cached item (for put() methods: 100 KB Maximum local cache size for a partition, per-request: 1,000 KB Best-case scenario: your entire ...


2

Actually, meta-data queries do not impact SOQL limits. You can update meta-data from within APEX using the meta-data API although this is more complicated than the same method in custom settings. And yes, there's a small performance hit but in most cases this is negligible. And if you really need the information cached you can use a combination of custom ...


1

Since v34.0, both getContent and getContentAsPDF are treated as callouts. This means that a separate transaction is spawned, and the original is placed on hold. This is problematic, because it also means that the previous transaction has not committed its changes to the database, so the page being called can't see those changes. This happens no matter how ...


1

As written, your code works just fine and produces the debug output you expect. Is your partition marked as the default partition? Does the behavior change if you do so? First Execution Second Execution Cache Configuration


1

Without seeing the design of your code, it's possible that either the results were not committed to the cache yet, the cache was invalidated for some reason, or the transaction exceeded the per transaction limits for writing to the cache. If the cache missed because it wasn't committed yet, you'll need to probably chain your Queueable until you can confirm ...


1

Your best choice outside of Named Credentials would be to store the token in a Custom Setting. Make sure that the field is encrypted using best practices so that the session can't be hijacked by users with sufficient access to see the token. Session Cache is a poor choice anyways, because it can be invalidated at any time, so you might end up needing to ...


Only top voted, non community-wiki answers of a minimum length are eligible