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
manjunath vivekmanjunath vivek 

Error: Compile Error: Invalid field I_am_Awesome__c for SObject Opportunity at line 13 column 7

trigger Winning on Opportunity (before update) {
  for (Opportunity opp : Trigger.new) {
    // Access the "old" record by its ID in Trigger.oldMap
    Opportunity oldOpp = Trigger.oldMap.get(opp.Id);

    // Trigger.new records are conveniently the "new" versions!
    Boolean oldOppIsWon = oldOpp.StageName.equals('Closed Won');
    Boolean newOppIsWon = opp.StageName.equals('Closed Won');
   
    // Check that the field was changed to the correct value
    if (!oldOppIsWon && newOppIsWon) {
      opp.I_am_Awesome__c = true;
    }
  }
}

when I try to save the above code, iam getting error message Error Error: Compile Error: Invalid field I_am_Awesome__c for SObject Opportunity at line 13 column 7
 I have I_am_Awesome__c custom field in the oppurtunity object still I am getting the message, can some one help me on this?
Best Answer chosen by manjunath vivek
Vatsal KothariVatsal Kothari
You are assigning boolean value to string, that is why it is giving an error.
If you want to give true value to Awesome__c, than give it as,

opp.Awesome__c= 'true';

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal

All Answers

Vatsal KothariVatsal Kothari
Hi Manjunath,

Have you check API name of the field I_am_Awesome__c?
It may contain some spelling mistake.
manjunath vivekmanjunath vivek
Hi Vatsal,
I hav changed the name to Awesome and tried the code 
opp.Awesome__c= true;
Now Iam getting the different error message.
Error Error: Compile Error: Illegal assignment from Boolean to String at line 13 column 7

Vatsal KothariVatsal Kothari
What is the data type of Awesome__c?
manjunath vivekmanjunath vivek
Text(15)
Vatsal KothariVatsal Kothari
You are assigning boolean value to string, that is why it is giving an error.
If you want to give true value to Awesome__c, than give it as,

opp.Awesome__c= 'true';

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal
This was selected as the best answer
manjunath vivekmanjunath vivek
Thank you sir,

It worked.I have changed the data type to check box.