JQuery: How to wait for Salesforce to finish rendering?

349    Asked by ElizabethClark in Salesforce , Asked on Jun 15, 2021

I have a small script that customises certain list views, hiding buttons.

This is done using jQuery $(document).ready()

Because this js is manipulating standard pages it is stored in the left sidebar.

However, I can see that the call to the function is being made when the document is not really ready. I'm guessing that salesforce is fetching list contents (including buttons) dynamically.

So my attempts to show or hide something are in vain because that thing has not yet been inserted into the page.

How can I make sure that this script gets executed when salesforce is done rendering the list completely?

Answered by Drucilla Tutt

Presumably you are aware that Salesforce is making this sort of code harder to add - see End of javascript sidebar hacks?.

If you can detect jquery wait when the rendering is done, then you can poll for that using JavaScript's setTimeout:

      function checkIfThere() { // Check for the element and do whatever you need to if you find it var foundIt = ...; if (!foundIt) { // Do the check again in 500 ms setTimeout(checkIfThere, 500); } else { // All done } } // Call directly to start it checkIfThere();


Your Answer

Interviews

Parent Categories