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
Pavan RenjalPavan Renjal 

Error: Compile Error: Initial term of field expression must be a concrete SObject: Object

I have a map consisting of Id and Double as Key and Value Pair. I am trying to assign a custom field in Opportunity to the value from Map. I have already added the values to the Map (not shown in the piece of code below) but i am failing to add the values to custom field Total_Price__c in Opportunity. Can anyone please help me in achieveing this? The syntax used below might be wrong, being a newbie i have no clue as how to execute this.

Map<Id,Double> MapTotalPrice = new Map<Id,Double>();

Opportunity Opp = new Opprtunity();
List<Opportunity> OpportunityList = new List<Opportunity>();


for(Id OppId: MapPrice.KeySet())
{
    Opp.get(OppId).Total_Price_c = MapTotalPrice.get(OppId);
    OpportunityList.add(Opp);
}
    
update OpportunityList;
Shailesh DeshpandeShailesh Deshpande
Line 3 needs to be replaced by

List<Opportunity> OpportunityList = new List<Opportunity>();
Pavan RenjalPavan Renjal

Sorry that was just a typo i made while posting this thread, i have used it correctly in my trigger.

Pavan RenjalPavan Renjal

It would be helpful if you can let me know what i need to do in order to add values from Map to Custome Field Total_Price__c  in Opportunity which is of type Currency.

Shailesh DeshpandeShailesh Deshpande
Opp.get(oppId) is not returning an object. Instead, trry the following in your loop:

opp = new Opportunity(Id = oppId)
opp.Total_Price__ = MapPrice.get(OppId);
OpportunityList.add(opp);

No need to initialize the opp outside the loop.
Pavan RenjalPavan Renjal

Thanks a bunch! Worked like a charm!