+ Start a Discussion

How to remove reference link (__r field) between objects ?

I am trying to find a way to unlink reference between two objects.

We have an object of Academic_Institution__c and Previous_Academic_Institution__c. If "CEEB_Code__c" exist Academic Institurion is created, and Previous Academic Institution is created with reference assigned to Academic Institution.

If we get a feed whith the same Previous_Academic_Institution__c, but the CEEB_Code__c empty, I want to remove the reference between Previous_Academic_Institution__c and Academic_Institution__c. I thought it is just a matter of assigning NULL to Academic_Institution__r, but it does not work:
Previous_Academic_Institution__c prevAcadInst =  new Previous_Academic_Institution__c(
                                        Name = collegeName,
                                        PAC_ID__c = getField(rows.get(i), headerMap, 'custom_field_usc_id').replace('-', '') + ':' + collegeName,
                                        Application__r = new Opportunity(Application_Client_Id__c = appId),
                                        CEEB_Code__c = ceebCode,
                                        Academic_Institution__r = String.isNotEmpty(ceebCode) ? new Academic_Institution__c(CEEB_Code__c = ceebCode):null

Here are the logs. I can see that when I am assigning NULL to __r field, then it does not get included for the upsert. How should I remove that link?

User-added image

User-added image

SandhyaSandhya (Salesforce Developers) 

Try to assign empty string ' ' and see.

Hope this helps you!

If this helps you please mark it as solved.

Thanks and Regards