You need to sign in to do that
Don't have an account?
Jocsan
Accessing sObject Fields Problem
Hi,
I am using the following code and myAcct.Type is returning null. Why? I am able to update the Type field but I can't read it.
for (opportunity o : Trigger.new) {
String accountid = o.AccountId;
Account myAcct = new Account(Id = accountid);
System.debug(myAcct.Type);
if ((o.StageName == 'Closed Won') && (myAcct.Type != 'Customer')) {
myAcct.Type = 'Customer';
update myAcct;
}
}
Any idea?
Thanks, Jocsan
I am using the following code and myAcct.Type is returning null. Why? I am able to update the Type field but I can't read it.
for (opportunity o : Trigger.new) {
String accountid = o.AccountId;
Account myAcct = new Account(Id = accountid);
System.debug(myAcct.Type);
if ((o.StageName == 'Closed Won') && (myAcct.Type != 'Customer')) {
myAcct.Type = 'Customer';
update myAcct;
}
}
Any idea?
Thanks, Jocsan
Account myAcct = new Account(Id = accountid);
System.debug(myAcct.Type);
every field value on myAcct except Id (which you set in the constructor) is going to be null because you haven't given then any values.
So, I can't use the condition, right?
if ((o.StageName == 'Closed Won') && (myAcct.Type != 'Customer')) {...
Is SOQL the only option I have to find out the currect Type value?
Jocsan