Requirement is : Cleaning up all the registry or folders remaining during uninstallation of the products at the end. Since it is making changes to system , I have written a Deferred Custom Action that deletes the folder . Now how do I write a rollback script to this , so that when there is issue and rollback takes place, these deleted folders comes up again ? Is it possible to do so ? Is rollback CA must for all deferred CA?
Yes. It's possible to write rollback custom action which will run in case of failure but it's not mandatory to write for each deferred CA.
You have to do a backup first before the deferred custom action. In case of failure, rollback custom action will copy from backup and delete the backup one. in case of success, deferred CA should delete the backup one on success return code.
You may follow below for how to use rollback CA. https://www.revenera.com/blog/software-installation/i-take-it-all-back-using-windows-installer-msi-rollback-actions/