0

Error

Error: Compile Error: Condition expression must be of type Boolean at line 8 column 9

Class

public class DataenteringVF2 {
    public string name      {set;get;}
    public string lastName  {set;get;}
    public string firstName {set;get;}
    public decimal salary   {set;get;}
    public integer age      {set;get;}
    public void EmployeeDetails(){
        if (name='bhargav'){
            salary=20000;
            age=20;
        }
   }
}
3

You need to use double equals (==) for comparison:

Works

if (name == 'some value')

Fails

if (name = 'some value')

Have a look at Understanding Expression Operators:

Operator
==

Syntax
x == y

Description
Equality operator. If the value of x equals the value of y, the expression evaluates to true. Otherwise, the expression evaluates to false.

Note:

  • Unlike Java, == in Apex compares object value equality, not reference equality, except for user-defined types. Consequently:
    • String comparison using == is case-insensitive
    • ID comparison using == is case-sensitive, and does not distinguish between 15-character and 18-character formats
    • User-defined types are compared by reference, which means that two objects are equal only if they reference the same location in memory. You can override this default comparison behavior by providing equals and hashCode methods in your class to compare object values instead.
  • For sObjects and sObject arrays, == performs a deep check of all sObject field values before returning its result. Likewise for collections and built-in Apex objects.
  • For records, every field must have the same value for == to evaluate to true. x or y can be the literal null.
  • The comparison of any two values can never result in null.
  • SOQL and SOSL use = for their equality operator, and not ==. Although Apex and - SOQL and SOSL are strongly linked, this unfortunate syntax discrepancy exists because most modern languages use = for assignment and == for equality. The designers of Apex deemed it more valuable to maintain this paradigm than to force developers to learn a new assignment operator. The result is that Apex developers must use == for equality tests in the main body of the Apex code, and = for equality in SOQL and SOSL queries.
0

Condition expression must be of type Boolean. In this code, you used single equal Assignment Operator = expression on line 8. This expression not type of Boolean only for assign values from right side Operands to left side Operands. You should use == condition expression (Relational Operator) of type Boolean. It is use for compare two objects based on memory reference.

If(name=='bhargav'){
    Salary=20000;
    age=20;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.