You need to sign in to do that
Don't have an account?
Ben Morch
Shorthand If-Then Statement
Hi all,
I am reveiwing some code in our instance that I did not write. It appears to be a simple if-then statement but I want to make sure I understand the syntax.
I believe this is saying:
If acc.Credit_Quality_Rating__c is null, then set cqr = 0, else set it to acc.Credit_Quality_Rating__c.
I also have this is in the code that is confusing me:
I was having a hard time figuring this one out. I am just looking for an explanation of the syntax.
Thanks for any help
I am reveiwing some code in our instance that I did not write. It appears to be a simple if-then statement but I want to make sure I understand the syntax.
cqr = acc.Credit_Quality_Rating__c == null ? 0 : acc.Credit_Quality_Rating__c;
I believe this is saying:
If acc.Credit_Quality_Rating__c is null, then set cqr = 0, else set it to acc.Credit_Quality_Rating__c.
I also have this is in the code that is confusing me:
ReviewDate = ReviewDate || oldAcc.Credit_Review_Date__c != acc.Credit_Review_Date__c ? true : false;
I was having a hard time figuring this one out. I am just looking for an explanation of the syntax.
Thanks for any help
"ReviewDate " is true OR Old "Credit_Review_Date__c " and New "Credit_Review_Date__c" are not equals then true elase false
if( ReviewDate || oldAcc.Credit_Review_Date__c != acc.Credit_Review_Date__c )
{
ReviewDate = true;
}
else
{
ReviewDate = falsel
}
I hope this will help you. Please mark this as solution if this will help you
All Answers
"ReviewDate " is true OR Old "Credit_Review_Date__c " and New "Credit_Review_Date__c" are not equals then true elase false
if( ReviewDate || oldAcc.Credit_Review_Date__c != acc.Credit_Review_Date__c )
{
ReviewDate = true;
}
else
{
ReviewDate = falsel
}
I hope this will help you. Please mark this as solution if this will help you
Hi Ben,
You are right ,Basically this is called ternary operator . Term before question mark is condition if it will true then value retrun After quesstion mark and before colon else value after colon .
I think you are clear now.
Let me know if it helps !!
Thanks
Manoj