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
Sami ShakithSami Shakith 

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

Hi,

i am getting an Error: Compile Error: Expression cannot be assigned at line -1 column -1 while saving this code. Can anyone please tell me where i made mistakes and what will be solution? 

public class Values
{
   public string rate{get; set;}
   @future(create=true)
   public static void create()
   {
       values val=new values();
       List<Account> Acc = new List<Account>();
   
       Acc = [Select id from Account where Minutes__c!=null];
       if(Account.Minutes__c = 'v1')
       {
          val.rate='$1.00'; 
       }
       if(Account.Minutes__c = 'v2')
       {
           val.rate='$2.00';
       }
       
   }
}
Best Answer chosen by Sami Shakith
surasura
@future (create = true) doesnt exist and comparison should be done with ==
 
public class Values
{
   public string rate{get; set;}
   @future
   public static void create()
   {
       values val=new values();
       List<Account> Acc = new List<Account>();
   
       Acc = [Select id from Account where Minutes__c!=null];
       if(Account.Minutes__c == 'v1')
       {
          val.rate='$1.00'; 
       }
       if(Account.Minutes__c == 'v2')
       {
           val.rate='$2.00';
       }
       
   }
}

 

All Answers

surasura
@future (create = true) doesnt exist and comparison should be done with ==
 
public class Values
{
   public string rate{get; set;}
   @future
   public static void create()
   {
       values val=new values();
       List<Account> Acc = new List<Account>();
   
       Acc = [Select id from Account where Minutes__c!=null];
       if(Account.Minutes__c == 'v1')
       {
          val.rate='$1.00'; 
       }
       if(Account.Minutes__c == 'v2')
       {
           val.rate='$2.00';
       }
       
   }
}

 
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
Hi 

(create=true) is nothing if want to do callout the you can use  (callout=true) 
Please try  below code 
public class Values
{
   public string rate{get; set;}
   @future()
   public static void create()
   {
       values val=new values();
       List<Account> Acc = new List<Account>();
   
       Acc = [Select id,Minutes__c from Account where Minutes__c != null];
	    for(Account accObj : Acc)
	    {
		   if(accObj.Minutes__c == 'v1')
		   {
			  val.rate='$1.00'; 
		   }
		   if(accObj.Minutes__c == 'v2')
		   {
			   val.rate='$2.00';
		   }
        }
   }
}


NOTE :-
1) Methods with the future annotation must be static methods
2) can only return a void type
3) The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types
4) Methods with the future annotation cannot take sObjects or objects as arguments.
5) You can invoke future methods the same way you invoke any other method. However, a future method can’t invoke another future method
6) No more than 50 method calls per Apex invocation
7) Asynchronous calls, such as @future or executeBatch, called in a startTest, stopTest block, do not count against your limits for the number of queued jobs
8) The maximum number of future method invocations per a 24-hour period is 250,000 or the number of user licenses in your organization multiplied by 200, whichever is greater
9) To test methods defined with the future annotation, call the class containing the method in a startTest(), stopTest() code block. All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronously

Please check below blog for more information 
http://amitsalesforce.blogspot.in/2015/02/future-methods-in-salesforce.html

Thanks
Amit Chaudhary
Sami ShakithSami Shakith
Thanks for your reply. Even after changed my class it shows the same.
Sami ShakithSami Shakith
I used callout too. But Still getting that error.
Amit Chaudhary 8Amit Chaudhary 8
Please try below code :-
public class Values
{
   public string rate{get; set;}
   @future
   public static void create()
   {
       values val=new values();
       List<Account> Acc = new List<Account>();
   
       Acc = [Select id,Minutes__c from Account where Minutes__c != null];
	    for(Account accObj : Acc)
	    {
		   if(accObj.Minutes__c == 'v1')
		   {
			  val.rate='$1.00'; 
		   }
		   if(accObj.Minutes__c == 'v2')
		   {
			   val.rate='$2.00';
		   }
        }
   }
}

 
Sami ShakithSami Shakith
thank amit. but now im getting error like this Condition expression must be of type Boolean 
surasura
try below code , but do necessary changes if you need any logic change . here I  set val based on first account returned
 
public class Values
{
   public string rate{get; set;}
   @future
   public static void create()
   {
       values val=new values();
       List<Account> Acc = new List<Account>();
   
       Acc = [Select id,Minutes__c  from Account where Minutes__c!=null];
       
       if(Acc.size() > 0)
       {
           if(Acc[0].Minutes__c == 'v1')
           {
              val.rate='$1.00'; 
           }
           if(Acc[0].Minutes__c == 'v2')
           {
               val.rate='$2.00';
           }
       }
       
   }
}

 
Sami ShakithSami Shakith
Thank you so much Amit and sura. Successfully saved :)