I've created a Lightning component which on load, invoke apex function and brings some data. Depending on that data "Error Toast" getting displayed to the user. This is working as expected.

I've to use the same component in Community. When I drag the component, it appears in the community page template but also showing the "Error Toast". It looks like when the "Lightning Component" dragged on to the page it executes the apex action.

I want to prevent execution of the "init" event of Lightning Component when viewed in the "Community Builder"

1 Answer 1


Though you don't have code posted, it is clear what you should do. You can still use an init function but in the init function you are going to check if you are in a community site. There are two ways to do this—

  1. Add a design attribute that will allow an SFDC admin to configure whether the component is on a community page or not.

  2. Call your Apex class and use the System Site class to check if you currently have an ID for the site, if so you are in a Community page, if not, well you aren't. Apex Site Class

Once you have your boolean flag set from your init you can decide which path to take from there. Although it requires Apex, I would favor the second solution as one of the drawbacks to using design attributes as described is they fail on mobile because you cannot set the attribute for a lightning quick action.

You must log in to answer this question.

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