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
Bharath VikkurthiBharath Vikkurthi 

Remove the relationship among the objects

We have two objects in  a look up realtionship, Object1 has a property called propery1, which is used to link it to master object Object2. In my apex code, I want to remove this relationship based on a condition and I am using the following code. 
Object1 slct = cCon.obj; //We are able to populate values for slct
   slct.propery1 = NULL; 
  update slct;
There is no error, but relationship is not getting terminated aswell. How can we terminate the relationship among the objects?
Thanks,
Bharath V
 
Avishek Nanda 14Avishek Nanda 14
HI Bharath,
List<propery1> propery1List = New List<propery1>();
For(propery1 Plist: [SELECT Id,Name,RelationField From propery1List WHERE Id='SomethingExample']){
    Opp.RelationField = Null;
    propery1List.add(Plist);
}
update propery1List; // This would update the filed to null. 
Try adding the System.Debug and check if anything else which is blocking the processs.
Regards,
Avishek