1

How could we allow User to use only one LWC instance in salesforce?

I'm a newbie in salesforce lightning web components so wanted to set a permission or a code could be useful.

The expected results should be: only one LWC instance should appear, should be visible or user should be allowed to only drag and drop once that would suffice the requirement.

2
  • How is the user employing your LWC in this scenario? Lightning components generally are not directly manipulable by the end user. Commented May 20, 2019 at 23:31
  • User will just Drag and Drop the LWC, as an admin i was able to drag and drop multiple instances per page which is confusing, I wanted to set some sort of permission so that User should be able to drag and drop a particular LWC only once. Is that possible? Commented May 21, 2019 at 6:31

2 Answers 2

1

As David said, it is not recommended to limit the instances of a component on a page. However, there is a way to do it. In your LWC (say, 'LWC1'), import a method from the controller of another LWC (say 'LWC2'). In this method, maintain a counter to keep track of the number of times the method was invoked and return the value. In LWC1, invoke this method and decide whether to render the UI based on the returned value. You can, thus, control how many instances of the component you want rendered on the page at one time. However, note that you won't be able to control which instance is rendered i.e the any of the instances of the component could be rendered at random. This principle of a shared back-end controller is what the pubsub recipe is based on

Sign up to request clarification or add additional context in comments.

Comments

0

You seem to be asking about permissioning your component while using the Lightning App Builder to create Lightning pages as a Salesforce administrator.

Your component can control the contexts within which it is available by modifying your Component Configuration File, where your targets element defines the types of page for which it can be used. However, you cannot limit the count of components that can be placed on a single page, nor should you - it's often necessary, for example, to place multiple components within different containers that are conditionally rendered based upon the viewing user or record attributes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.