I have got a requirement where i have created 3 custom objects.
Project, Obj2 :
Assignment - This is Junction Object ( Master-Detail relationship to both Project and Employee)
Junction Object has only 2 fields
I have a Visualforce page which shows a dropdown of all Projects and upon selecting any project, I am displaying all the Employees associated to it. Now my many to many works like a charm. No issues so far !!
On the same page, I have a Remove button and on click of this I have to remove the link between Project and Employee. So I thought of deleting the junction object record which links the chosen project and employee. ( Is deleting a good idea ? )
Now the ask is : I am deleting the junction object record, but Project and Employee Records remain as it is. Now I have a requirement which says, I should write a batch which picks up all the employees which don't belong to any of the Projects.
The problem i am facing here is, Since I have deleted the junction object record in previous step but I don't know how I can query the orphan Employee records which don't belong to any of the projects.
Please suggest. Is deleting a junction object record better practice than just un-linking the junction object record by setting the jnObj.employee__c to NULL?