0

We use lightning communities. I am working on building a new LWC component, where I can place it in the page footer. The goal of the component is simple: once the user logs in, visits a page in the community - capture user info and network info and insert the information in a custom object.

I am using createrecord wire service to insert a new record. On research, I found out that I have 2 options for lifecycle hooks. renderedCallback() or connectedCallback(). renderedCallback() does insert the record but it runs multiple times; tried to use initialRender but with no luck. connectedCallback() does not create the record.

What is the recommended approach so that a visit can be captured?

6
  • 1
    Worth noting that Salesforce outlined new analytics abilities, including login, to come ("safe harbor" declared) in Winter '20 release. You may find that you implement a load of custom stuff that becomes OOTB at that point. – Phil W May 31 '19 at 16:23
  • 2
    NB: You may also be facing GDPR issues if you capture user-identifiable details. – Phil W May 31 '19 at 16:24
  • Thank you! Ignoring the analytics and purely to learn LWC, could you let me know on the best way to insert a record when the component is loaded/rendered? – gkolan May 31 '19 at 17:23
  • @gkolan Are you saying that you are not able to utilize a private member to determine if renderedCallback() has already executed as mentioned in the docs? – Jayant Das May 31 '19 at 17:50
  • have you tried making the save call in the component constructor? – Calvin OKeefe Jun 1 '19 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.