0
for(Account acc : lstAc){
    Account acount =  new Account(); 
    if (acc.Property_Managment_Company__c == 'Independent') {
               acount.ParentId =  THIS FIELD SHOULD BE EMPTY.
            }
        }       
1
  • "null" is your friend.
    – Phil W
    Sep 25, 2020 at 18:46

2 Answers 2

1

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.

0

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;
1
  • 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 F
    Sep 25, 2020 at 21:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .