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
Melissa Driscoll 14Melissa Driscoll 14 

help with APEX Class - Trying to pull opportunity Line Items on to a custom object

Custom Object is Account Executive Handoff - This is my Error

Error: Compile Error:
PricebookEntry.Name, TotalPrice, Quantity, On_Support__c from OpportunityLineItem
^
ERROR at Row:1:Column:71
No such column 'On_Support__c' on entity 'OpportunityLineItem'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 11 column 21
 

public class HandoffProducts
{
    public List<OpportunityLineItem> lineItems { get; set; }
    
    Public HandoffProducts( ApexPages.StandardController std )
    {
        if( std.getRecord().Id != null )
        {
           Account_Executive_Handoff__c con = [ Select Id, Opportunity__c from Account_Executive_Handoff__c where Id =: std.getRecord().Id ];
            
        lineItems = [ Select Id, Opportunityid, PricebookEntry.Name, TotalPrice, Quantity, On_Support__c from OpportunityLineItem where Opportunityid =: con.Opportunity__c ];
        }
        else
        {
            lineItems = new List<OpportunityLineItem>();
        }
    }

    public void save()
    {
        if( lineItems.size() > 0 )
            update lineItems;
    }
}

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Melissa,

The Error says that you don't have On_Support__c field on OpportunityLineItem object. Can you check if the API name of the field is correct and if the field exists on the object.

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
mukesh guptamukesh gupta
Hi Mellisa,

Below points will help to get resolve your issue:-
  • Make sure that this field is actually visible to your user via Field Level Security.
  • Click the field name in your Setup UI to view the field definition detail.
  • On this detail view, there will be a Set Field-Level Security button.
  • Make sure Visible is selected for your Profile.

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh