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

Unexpected token list in my trigger code

Hi i am getting error while executing the trigger so can any one help me out


ERROR MSG :· Compile Error: unexpected token: 'list' at line 8 column 47


Here is my trigger code


trigger GettingPrice on Bookings__c (before insert , before update)
set<string> BookingModelSet = new set<string>();
for(integer i=0;i<trigger.size;i++)
list<Vehicle_Rental_Price__c> PriceOfVehicles = list<Vehicle_Rental_Price__c>(); error in this line

                                 Vehicle_Rental_Price__c is not an custom object its an Custom setting which has a static values       
PriceOfVehicles = [select name , Rental_Price__c from Vehicle_Rental_Price__c where name in BookingModelSet];
Map<string , string> MappingPriceToModel = new Map<string , string>();
for(integer i=0;i<PriceOfVehicles.size();i++)
MappingPriceToModel.put(Vehicle_Rental_Price__c[i].name , Vehicle_Rental_Price__c[i].Rental_Price__c);
for(integer i=0 ; i<trigger.size ; i++)
if(MappingPriceToModel.containskey([i].Model__c))[i].price_per_day__C = MappingPriceToModel.get([i].model__c);



You need to use "new" before list; it's a constructor.





again i am getting an error so can u help me out 

Compile Error: Incompatible value type Decimal for MAP<String,String> at line 13 column 9

in this the Rental_Price__c is the field of data type currency  with length 5 and ddecimal 0

Yes your map is of type String and String and the value you are trying to put is decimal. Better to convert it into string before putting into map.
MappingPriceToModel.put(Vehicle_Rental_Price__c[i].name , String.valueOf(Vehicle_Rental_Price__c[i].Rental_Price__c));