Table get insert twice in Moralis Cloud function afterSave

I have a table call ā€œTableā€ and I have set the CLP public Read only. The table is mainly called by Moralis Cloud function afterSave that triggered by smart contract sync.

It call ā€œinsertMoralisListingā€ when the confirmed is true. I assumed it just call once. But somehow, the table got inserted with 2 rows. (Sometime it is 1 row). Anything I missed? Please help.

If confirmed is true, then you are again inserting a new row in the same ā€œTableā€ class with insertMoralisListing function. This should cause an infinite loop, not sure why it stopped at 2.

Try logging the confirmed value or use an else loop to test ā€œnot confirmedā€ condition. Maybe something else is causing an error.