0

Getting an error in apex code and quite new to apex code.

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

Following is the code:

public class TotalAmountUpdate {
   public static void TotalAmountUpdate (Construction_Linked_Schedule__c[] TAPNEW) {
      for (Construction_Linked_Schedule__c C :TAPNEW) {
          List<C.Contruction_Linked_Schedule__c> allFlatids =  [SELECT C.Flat_Id__c , C.Total_Amount_Paid__c FROM Construction_Linked_Schedule__c ];

          for (C.Construction_Linked_Schedule__c.FLAT_ID__C currentFlat_id : allFlatids) {

              Decimal FFSPayment = (Decimal)[Select SUM(C.Total_Amount_Paid__c)FFSTOT from C.Construction_Linked_Schedule__c where C.Milestone_number__c < = 2][0].get('FFSTOT'); 

                  If ( C.Milestone_number__c = 2)  { C.Total_Amount_Paid__c = FFSPayment ; }
                  Update C.Total_Amount_Paid__c ;
          } 
      }
   }
}
3

You have a couple of code syntax issues. Lets see if we can explain those to you:

public class TotalAmountUpdate { 
    public static void TotalAmountUpdate (Construction_Linked_Schedule__c[] TAPNEW) { 
       for (Construction_Linked_Schedule__c C :TAPNEW) {

            List allFlatids = [SELECT **Flat_Id__c**,**Total_Amount_Paid__c** FROM Construction_Linked_Schedule__c ];
            for (Construction_Linked_Schedule__c currentFlat_id: allFlatids) {
                 //Decimal FFSPayment = (Decimal)[Select SUM(C.Total_Amount_Paid__c)FFSTOT from C.Construction_Linked_Schedule__c where C.Milestone_number__c < = 2] [0].get('FFSTOT');

                //If ( C.Milestone_number__c = 2) { 
                      //C.Total_Amount_Paid__c = FFSPayment ; 
               // }

               //Update C.Total_Amount_Paid__c ; 
           }
        } 
     }     
 } 

You do not need to use the dot notation to access the fields in a select statement. running:

[SELECT Id,Name,Address FROM Account]

is a valid query.

When creating a list of a certain type you need to denote the Object it is a list of:

list<Construction_Linked_Schedule__c> constructionLinkedSchedule = new list<Contruction_Linked_Schedule__c>();

Looking at the number of syntactically incorrect statements - it maybe worthwhile for you to review the documentation for syntax in apex.

Link: http://www.salesforce.com/us/developer/docs/apexcode/salesforce_apex_language_reference.pdf

| improve this answer | |
  • 1
    This is also an incorrect boolean expression: if( C.Milestone_number__c = 2) It should be: if(C.Milestone_number__c == 2) – akarnid Apr 7 '15 at 13:42

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.