function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepika Gupta 26Deepika Gupta 26 

Getting Error : Expression cannot be assigned at line -1 column -1

Could any suggest that why i am getting this error :

Expression cannot be assigned at line -1 column -1

After saving this method 

 public static void TempAcc()
    {
       if( Account.RecordTypeId ='ParticularId')
        { 
          
               // system.debug('Account category needs to be blank when parent account is selected');
          
       }
     }




 
Amit Chaudhary 8Amit Chaudhary 8
Please add == sign try your code like below :-
public static void TempAcc()
{
       if( Account.RecordTypeId == 'ParticularId' )
        { 
          // system.debug('Account category needs to be blank when parent account is selected');
        }
}


let us know if this will help you
DebasisDebasis
Hi Deepika,

In you code you have used     if( Account.RecordTypeId =='ParticularId')  whic is wrong as in if condition you need to compare two value using == (Equality) operator. whihc will return boolena value true or false. if condition is true then it will execute the code inside the of condition.

Use the below code and let me know if it works for you.
 
public static void TempAcc()
    {
       if( Account.RecordTypeId =='ParticularId')
        { 
          
               // system.debug('Account category needs to be blank when parent account is selected');
          
       }
     }

Thanks,
Debasis
 
Deepika Gupta 26Deepika Gupta 26
Hi Debasis,
First i have used == operator too but on that time its giving error like this :

Compile Error: Comparison arguments must be compatible types: Schema.SObjectField, String.
Amit Chaudhary 8Amit Chaudhary 8
Can you please post your full code. Also please check you have any Apex class with Account Name ??
DebasisDebasis
HI Deepika,

here you are comparing recordtype id with a string value.

please change this below code as per your objcet name and record type name.'
Here instead of  Account.RecordTypeI, please referc to a particular account record's recordtype.  

in this below  line 
id RecTypeId= schema.SobjectType.YourObjectName.getRecordTypeInfosByName().get('Your reordtypename').getrecordtypeId();
replace your object name and record type name to get the id of that record type to check in if condition
public static void TempAcc()
    {
id RecTypeId= schema.SobjectType.YourObjectName.getRecordTypeInfosByName().get('Your reordtypename').getrecordtypeId();

       if( Account.RecordTypeId == RecTypeId)
        { 
          
               // system.debug('Account category needs to be blank when parent account is selected');
          
       }
     }

It will be more helpful if you can share your complete code to help you out.

Thanks,
Debasis
Deepika Gupta 26Deepika Gupta 26
Still i am getting the error like :

Comparison arguments must be compatible types: Schema.SObjectField, Id at line 170 column 12

Code : Because of security reasons i cant share the code but this is the only method which i am going to create which is giving error.
Amit Chaudhary 8Amit Chaudhary 8
Please try like below code.
public static void TempAcc(Account acc)
    {
        id RecTypeId= schema.SobjectType.Account.getRecordTypeInfosByName().get('Temporary Account').getrecordtypeId();
        if( acc.RecordTypeId == RecTypeId)
        {
               // system.debug('Account category needs to be blank when parent account is selected');
        }
    }
Let us know if this will help you

Thanks
AMit Chaudhary

 
DebasisDebasis
HI Deepika,

please update your method defination to pass the account record and try this below code.
 
public static void TempAcc(Acccount acc)
    {
id RecTypeId= schema.SobjectType.Account.getRecordTypeInfosByName().get('Temporary Account').getrecordtypeId();

       if( acc.RecordTypeId == RecTypeId)
        { 
          
               // system.debug('Account category needs to be blank when parent account is selected');
          
       }
     }

Thanks,
Debasis