You need to sign in to do that
Don't have an account?

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); } }
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
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
I am still getting the same error message.
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