0

We have a LWC,mycomponent that will fetch custom metadata records, myCustomMetadataList and store them into a List variable within mycomponent. When a user clicks on the Save button on this component, the component will update a Contact record with the data from the input fields on the LWC. There is an after update trigger that calls MyTriggerHandler.myMethod(newContactList, oldContactList). Within the myMethod(), the same custom metadata record list, myCustomMetadataList is needed to do additional processing. The way the process works

Questions:

  1. Can we pass myCustomMetadataList that was fetched from the LWC into the trigger such that myMethod() can access the same myCustomMetadataList variable from the LWC without making a custom metdata query again?
  2. How can we read the myCustomMetadataList variable in the myMethod?
  3. In myMethod if I wanted to get the myCustomMetadata values, would I have to query again?
1
  • When you say it's the same myCustomMetadataList that's needed, is the problem you're trying to solve that you don't have a way to query for the same list? Or are you assuming it's bad to query for the same list and you feel it's better to not have to query for it?
    – Nick C
    Feb 4, 2021 at 0:35

2 Answers 2

1

You will need to write your retrieval process for the custom metadata in such a way it behaves predictably. If you retrieve the data and store it to a static variable, then interact with that variable in the same transaction, you would not pay the cost of retrieval and processing a second time. Generally, with custom metadata structures, these costs are negligible.

4

Can we pass myCustomMetadataList that was fetched from the LWC into the trigger such that myMethod() can access the same myCustomMetadataList variable from the LWC without making a custom metdata query again?

No. One is client-side, the other is server-side. You could do this in Apex (not a trigger), but this is (probably) a waste of bandwidth.

How can we read the myCustomMetadataList variable in the myMethod?

You can't. Again, client-side memory versus server-side memory. You'd have to transfer them over somehow, which wouldn't work for a trigger.

In myMethod if I wanted to get the myCustomMetadata values, would I have to query again?

Yes. And since querying custom metadata records are essentially "free" (as in, does not count against SOQL row or query governor limits), there's no point in worrying about querying them as frequently as you need to.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .