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
Sumesh ChandranSumesh Chandran 

Incrementing values of a list

I am trying to increment the values inside a list using the ++ operator, but I get the error saying 'Expression cannot be assigned'. On the code below I am trying the increment the values of onBillings & offBillings variable.
Decimal onBillings;
    Integer offBillings;
    List<sumchans__City_Master__c> cityList = new List<sumchans__City_Master__c>();//unique city list
    List<sumchans__City_Stats__c> cityStats = new List<sumchans__City_Stats__c>();//Saving city stats
    Set<String> cities = new Set<String>();
    for(sumchans__Address_Master__c addressMaster: addressList) {
          sumchans__City_Master__c city = new sumchans__City_Master__c();
          city.Name = addressMaster.sumchans__CITY_NAME__c;// Default Name column - storing city name
          city.sumchans__City_Name_Ext_Id__c = addressMaster.sumchans__CITY_NAME__c;//Populating the external id field with city name again to pull related data.
          city.sumchans__Province_Code__c = addressMaster.sumchans__PROVINCE_CODE__c;
          if(!cities.contains(city.Name)) {               
              for(sumchans__ADDRESS_STATS__c addressStatsList: addressStats) {
                  String cityFromAddressList = (addressStatsList.Name).substringBeforeLast(' ');
                  cityFromAddressList = cityFromAddressList.substringBeforeLast(' ');
                  if(cityFromAddressList == city.Name) {
                      onBillings++ = Integer.valueOf(addressStatsList.sumchans__On_Billings__c);
                      offBillings++ = addressStatsList.get('sumchans__Off_Billings__c');
                      sumchans__City_Stats__c cityStat = new sumchans__City_Stats__c();
                        cityStat.sumchans__On_Billings__c = onBillings;
                        cityStat.sumchans__Off_Billings__c = offBillings;
                        cityStats.add(cityStat);                       
                    }
                }
                cities.add(city.Name);
                cityList.add(city);
            } 
        }

 
Best Answer chosen by Sumesh Chandran
Shubham_KumarShubham_Kumar
Hi Sumesh
My bad i didn`t notice the space. the " variablename += anyvariable"
So It will be " onBillings += " and "onBillings += ".

Do let me know if you have any further query.

P.S: Mark this as the best answer if this helped you.

Thanks 
Shubham Kumar

All Answers

Shubham_KumarShubham_Kumar
Hi Sumesh
It will just be " onBillings+ = " and "onBillings+ = ".
The "onBillings++"  statement means "onBillings = onBillings + 1".

Do let me know if you have any further query.

P.S: Mark this as the best answer if this helped you.

Thanks 
Shubham Kumar
Sumesh ChandranSumesh Chandran
Thanks for the speedy reply @Shubham Kumar,

I am still getting the same error message.
 
if(cityFromAddressList == city.Name) {
   onBillings+ = addressStatsList.sumchans__On_Billings__c;
   offBillings+ = addressStatsList.sumchans__Off_Billings__c;                   
   sumchans__City_Stats__c cityStat = new sumchans__City_Stats__c();
   cityStat.Name = city.Name;// City name column in the City_Master table
   cityStat.sumchans__City_Master_Ext_Id__r = new                         sumchans__City_Master__c(sumchans__City_Name_Ext_Id__c = city.Name);
   cityStat.sumchans__On_Billings__c = onBillings;
   cityStat.sumchans__Off_Billings__c = offBillings;
   cityStats.add(cityStat);                       
}

Below is the error I am getting.
User-added image
 
Shubham_KumarShubham_Kumar
Hi Sumesh
My bad i didn`t notice the space. the " variablename += anyvariable"
So It will be " onBillings += " and "onBillings += ".

Do let me know if you have any further query.

P.S: Mark this as the best answer if this helped you.

Thanks 
Shubham Kumar
This was selected as the best answer
Sumesh ChandranSumesh Chandran
Thanks Shubham. That worked. Thanks, Sumesh Chandran