1

I need to pass a property that I will write (I think it can be called custom) from js-meta.xml a file in the Apex handler class. The question is how to read/receive it in the Apex using page layout (this is a prerequisite and means Layout Class : https://developer.salesforce.com/docs/atlas.en-us.232.0.apexref.meta/apexref/apex_class_Metadata_Layout.htm#apex_Metadata_Layout_summaryLayout or something related to it). There is a question on a similar topic : Programmatically set parameter on LWC?, but it doesn't help me.

Let me clarify again: I need to somehow get the values of these properties in the Apex handler class (after installing LWC on the page) using page layout (if possible). Need detailed advice

I edited the question, posted the entire file.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordPage</target>
        <target>lightning__AppPage</target>
        <target>lightning__HomePage</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordPage,lightning__AppPage,lightning__HomePage">
            <property label="LabelName" name="name" type="String" required="true" datasource="value1,value2,value3" default="value1"/>
            <property label="LabelName2" name="name2" type="String" required="true"/>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>
2
  • Can you clarify the use case a bit here? Do you want to surface the names of existing Layouts as options for the admin when they are setting the Property of the component? Which context (ie Targets) will this component be used?
    – Jeff Kranz
    Commented Dec 21, 2021 at 12:11
  • I edited the question Commented Dec 21, 2021 at 16:53

1 Answer 1

1

If I understand correctly, you've got an LWC that you're exposing properties for in the xml so that whoever is filling that sets variables in the LWC, and then you're looking to pass those variables back to Apex and handle them in some way. If this is the case, the Layout Class is not what you're looking for; you're going to want to use the Wire Service or call your Apex methods imperatively. Full root documentation of calling Apex from LWC is here.

Basically, when you open up a property in the xml like that, you need a corresponding JavaScript variable annotated with @api, which you can then use in your LWC. From there, you can pass that variable to an Apex method and handle it accordingly. Here's more info on the XML Configuration File. An example of how to do this is shown on the Salesforce Diaries site (not official Salesforce). I would also have another look at that second link you gave because this is what that question is addressing - it may make sense now that you know this is only part of what you want to do and not the full picture.

3
  • thanks for the example in Salesforce Diaries, it looks like this (passing to apex, properties as a regular variable via @wire or imperative) is exactly what I need, but I can't say for sure yet. I'll try to use this example, maybe I misunderstood the task Commented Dec 21, 2021 at 16:14
  • You are welcome! Of note, the Salesforce Diaries example does not call Apex, but I provided it as an example of how you use the XML to open up your properties. Examples for calling Apex can be found in the documentation I linked in the first paragraph however. Commented Dec 22, 2021 at 12:52
  • That's right, the problem was that I misunderstood the task, and was looking for some magical way to get these properties in the apex. I will pass properties to the apex as in a normal apex call from LWC (imperative or not it doesn't matter). An example and documentation on this topic is enough. This corresponds to the conditions of my assignment. Thanks again. Commented Dec 22, 2021 at 13:03

You must log in to answer this question.

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