This is my code snippet ,
string.isBlank(distributorId) ? gen.writeNullField(DISTRIBUTORID):gen.writeStringField(DISTRIBUTORID,distributorId);
why it is throwing me error Expression cannot be a statement
Thanks & Regards, Ravi
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityThis is my code snippet ,
string.isBlank(distributorId) ? gen.writeNullField(DISTRIBUTORID):gen.writeStringField(DISTRIBUTORID,distributorId);
why it is throwing me error Expression cannot be a statement
Thanks & Regards, Ravi
This is an expression:
string.isBlank(distributorId) ? gen.writeNullField(DISTRIBUTORID):gen.writeStringField(DISTRIBUTORID,distributorId)
whereas this is a statement:
Boolean b = string.isBlank(distributorId) ? gen.writeNullField(DISTRIBUTORID):gen.writeStringField(DISTRIBUTORID,distributorId);
If you don't need the result of string.isBlank(distributorId)
in later code, write this as a normal if
statement:
if (string.isBlank(distributorId)) gen.writeNullField(DISTRIBUTORID);
else gen.writeStringField(DISTRIBUTORID,distributorId);
or if you prefer:
if (string.isBlank(distributorId)) {
gen.writeNullField(DISTRIBUTORID);
} else {
gen.writeStringField(DISTRIBUTORID,distributorId);
}
The below code is an expression
string.isBlank(distributorId) ? gen.writeNullField(DISTRIBUTORID):gen.writeStringField(DISTRIBUTORID,distributorId);
to assign gen implementation can be
if(string.isBlank(distributorId)) gen.writeNullField(DISTRIBUTORID)
else gen.writeStringField(DISTRIBUTORID,distributorId)
writeNullField()
andwriteStringField()
? – TSmith Apr 3 '20 at 9:15