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
Travis WrightTravis Wright 

SObject row was retrieved via SOQL without querying the requested field:

Not sure why I am getting this looking at the SOQL statement I have the name in the Query, Here is the full error. 

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ProjectrollupOLi: execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.Communications_Team__c Trigger.ProjectrollupOLi: line 65, column 1: []
Error is in expression '{!doSaveOLI}' in component <apex:commandButton> in page productsearch: Class.ProductSearch.doSaveOLI: line 1016, column 1

Here is the Trigger,

trigger ProjectrollupOLi on OpportunityLineItem (after insert, after update, before delete)

    Set <String> oppIdSet = new Set <String>();

    if(Trigger.isAfter)
        for(OpportunityLineItem oli : Trigger.new)
            oppIdSet.add(oli.OpportunityId);
    if(Trigger.isBefore)
        for(OpportunityLineItem oli : Trigger.old)
            oppIdSet.add(oli.OpportunityId);
    
    Map<Id,Opportunity> oppOldMap = new Map<Id,Opportunity>([Select Id, Implementation_Team__c, Training_Team__c From Opportunity Where Id IN :oppIdSet]);

    Set<String> oppImplementationTeamList = new Set<String>();
    Set<String> oppTrainingTeamList = new Set<String>();
    Set<String> oppCommunicationTeamList = new Set<String>();
        
    List <OpportunityLineItem> oliList = [Select UnitPrice, Quantity, PricebookEntry.Product2Id, TotalPrice,PricebookEntry.Product2.Name, Description,
        Converted_to_Asset__c,Asset__c,PricebookEntry.Product2.Create_Asset__c, PricebookEntry.Product2.Sales_Order_Group__c, OpportunityId From OpportunityLineItem where 
        OpportunityId IN : oppIdSet And (PricebookEntry.Product2.Product_Reporting_Category__c = 'Services' or PricebookEntry.Product2.Name LIKE '%Communications%')];

    for(OpportunityLineItem oli : oliList)
    {
        if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Hotline Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Policy Management Services' || oli.PricebookEntry.Product2.Sales_Order_Group__c == 'Incident Management Services')
        {
            oppImplementationTeamList.add(oli.OpportunityId);
        }
        if(oli.PricebookEntry.Product2.Sales_Order_Group__c == 'ReadyTraining Services')
        {
            oppTrainingTeamList.add(oli.OpportunityId);
        }
        if(oli.pricebookEntry.Product2.Name.Contains('Communications'))
        {
            oppCommunicationTeamList.add(oli.OpportunityId);
        }
    }
    
    Map<Id,Opportunity> updateMap = new Map<Id,Opportunity>();
    
    for(Id oppId : oppIdSet)
    {
        Opportunity opp = new Opportunity(Id = oppId, Implementation_Team__c = false, Training_Team__c = false, Communications_Team__c = false);
        updateMap.put(oppId, opp);
    }
    
    for(Id oppId : oppImplementationTeamList)
    {
        Opportunity opp = updateMap.get(oppId);
        opp.Implementation_Team__c = true;
    }
    
    for(Id oppId : oppTrainingTeamList)
    {
        Opportunity opp = updateMap.get(oppId);
        opp.Training_Team__c = true;
    }
    for(Id oppId : oppCommunicationTeamList)
        {
            Opportunity opp = updateMap.get(oppId);
            opp.Communications_Team__c = true;
        }
    for(Opportunity oppOld : oppOldMap.values())
    {
        Opportunity oppNew = updateMap.get(oppOld.Id);
        if(oppNew.Implementation_Team__c == oppOld.Implementation_Team__c && oppNew.Training_Team__c == oppOld.Training_Team__c && oppNew.Communications_Team__c == oppOld.Communications_Team__c)
            updateMap.remove(oppOld.Id);
    }
    
    List<Opportunity> updateList = updateMap.values();
    
    if(updateList.size()>0)
        update updateList;
}
Best Answer chosen by Travis Wright
Travis WrightTravis Wright
Fixed the issue it seems that I missed adding the field to the MAP.