+ Start a Discussion

Use an operator inside a Ternary Opeartor?

I am trying to increment a field based on if/else logic. I'm just starting to get the hang of the ternary operator. So, I wrote the following, but it won't compile. Does anybody know if it's possible to do this, or does it have to go in an if else statement?


conCD.CourseRoleCount__c = source == 'Course' ? +=1 : 0; 

I just figured it out:


conCD.CourseRoleCount__c += source == 'Course' ? 1 : 0;