function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saurabh Kulkarni 84Saurabh Kulkarni 84 

Lightning component method to run only after record is created

Hello Everyone,

I have a lightning component added on the record detail page. This component has a controller method which gets fired on "refreshView" event and I have my login in that method. It works all good for all changes I do to my record.
 

However, I want my component to execute this controller method even when record is created. The refreshView event does not get fired when someone creates a record. Is there a way to identify this event?

Thanks 
Saurabh

AbhishekAbhishek (Salesforce Developers) 
Hi Saurabh,

The below blogs might answer your query,

https://salesforce.stackexchange.com/questions/170542/automatically-refresh-lightning-component

https://www.jitendrazaa.com/blog/salesforce/calling-apex-method-at-regular-interval-from-lightning-component/

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.


Thanks.
ShirishaShirisha (Salesforce Developers) 
Hi Saurabh,

Greetings!

force:refreshView fires whenever you try to access the record and refresh the record page to get the recent data.

So,I would like to refresh the created record then we will have to access the record.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Saurabh Kulkarni 84Saurabh Kulkarni 84
Hi Abhishek,

Thanks for the links and your response.

I see these blogs are taking about streaming API event or periodically calling some method from lightning component.

However, I'm currently only missing with on record create event. Hence, I am bit reluctant to switch to any other way like streaming API or anything else, as it would change whole my component logic. 

Regards,
Saurabh Kulkarni

 
Saurabh Kulkarni 84Saurabh Kulkarni 84
Hi Shirisha,

Thank you for your reply!

Could you please clarify how can I fire refreshView event specifically when record is created.?

Please note that when I say record create, user is is clicking on New button and creating a record from the window and getting automatically navigated to created record page. That's the time I wanna call the method.

Regards,
Saurabh Kulkarni