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
alex.gan1.3933003770315437E12alex.gan1.3933003770315437E12 

Problem in update lookup field

2 standard Object: Account and User

1. there's a customer field in Account : Public_Owner__c, it's a lookup field(User) 
2. there's a customer field in Account : isPublic(bool)
3. there's a rule in field Public_Owner : ((Public_Owner_r.LastName != null) && (isPublic=true) )
     error message is : "it's not allowed to check isPublic when Public_Owner is not null"
means: if Public_Owner == null then isPublic = true else isPublic = false;

my program(C#):
......
accounts[0].Id = id;
accounts[0].Public_Owner__c = userId
accounts[0].isPublic = (userId == null) ? true : false;

LimitInfo[] li;
SaveResult[] sr;
DebuggingInfo di = client.update(header, null, null, null, null, null, null, null, null, null, null, accounts, out li, out sr);
if (sr[0].success == false)
 {
      foreach (Error error in sr[0].errors)
            {
                returnValue += "errormessage:" + error.statusCode + error.message + "\t";
            }
}

here's the problem:
when I call update() to update the account,  if field isPublic is false,update() is OK,else there's always a error: FIELD_CUSTOM_VALIDATION_EXCEPTION and the rule error:"it's not allowed to check isPublic when Public_Owner is not null"

sorry for my poor english,could anybody help me?
Thanx!
Best Answer chosen by alex.gan1.3933003770315437E12
Vamsi KrishnaVamsi Krishna
Hi,

Can you change the validation rule in Account to below and see if it resolves your issue

AND(
ISBLANK(Public_Owner__c),
isPublic
)

All Answers

Vamsi KrishnaVamsi Krishna
Hi,

Can you change the validation rule in Account to below and see if it resolves your issue

AND(
ISBLANK(Public_Owner__c),
isPublic
)
This was selected as the best answer
alex.gan1.3933003770315437E12alex.gan1.3933003770315437E12
Hi, Vamsi, thanks for your reply. I found the reason. the checkbox field isPublic can't be updated successfully, but I don't know why does it can't be updated, there's no error message when I update the record (I disabled the rule of field Public_Owner)
alex.gan1.3933003770315437E12alex.gan1.3933003770315437E12
Problem solved,Thanks