for(Account acc : lstAc){
Account acount = new Account();
if (acc.Property_Managment_Company__c == 'Independent') {
acount.ParentId = THIS FIELD SHOULD BE EMPTY.
}
}
2 Answers
Since you don't describe the use case here, I'd suggest this as a validation rule on the Account object to prevent the data from being set incorrectly in the first place.
Formula:
AND (
Property_Managment_Company__c = 'Independent',
NOT(ISBLANK(ParentId))
)
Error Message:
This account is independently managed and cannot have a parent account specified
If this field value is being changed in code, as others have suggested, ParentId = null
will do the job of erasing the parent reference.
I am not sure why you are creating new instance of Account object inside for loop. But you can try following code:
for(Account acc : lstAc){
if (acc.Property_Managment_Company__c == 'Independent') {
acc .ParentId = null;
}
}
update lstAc;
-
This is unlikely to be what you want to do if you're updating a record. At the very least, taking this approach will have an effect on the updated records. Setting a field to null would mean that field is overwritten (and blanked out) when you update the record. If you don't set the field at all, then the update would not alter the existing value in the database.– Derek FSep 25, 2020 at 21:38