I want to take the state of a source record, clone it, and apply the clone to a target record. But I'm encountering an issue in which a null field on the clone does not nullify the field on the target.
Account account1 = [select id, NumberofLocations__c from Account where NumberofLocations__c != null limit 1]; Account account2 = [select id, NumberofLocations__c from Account where NumberofLocations__c = null limit 1]; // Clone account2 and use it to alter state of account1. Account template = account2.clone(false, true, false, false); template.Id = account1.Id; update template;
In the example above,
- two accounts are queried: the target,
account1, has a defined value for
NumberOfLocations__c, while the source,
account2, has a null value in the same field.
templateand its Id set to
NumberOfLocations__c value to be nullified.
NumberOfLocations__c value remains unchanged.
How do I resolve this?