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
JoshH10JoshH10 

Error: Invalid field Opportunity for SObject Opportunity

I'm trying to get Apex to pull a field I created which auto-generates an ID number for every opportunity, but I can't quite get it to work. This is the code I have currently, which is returning this error to me "Error: Invalid field Opportunity for SObject Opportunity "

 

<apex:repeat var="oppx" value="{!relatedTo.Opportunity}">
    <apex:outputText value="{!oppx.Opportunity_ID__c}" />
</apex:repeat>

Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you share the entire code so can check based on it.

Thanks,
 
Shri RajShri Raj
<apex:outputText value="{!relatedTo.Opportunity.Opportunity_ID__c}" />

 
Juber kimberJuber kimber
Based on the error message you're seeing, it sounds like the Opportunity_ID__c field may not exist on the Opportunity object in your Salesforce org. Here are a few things you could try to troubleshoot this issue:
Check the API name of the custom field: Make sure that the API name of the custom field you created is "Opportunity_ID__c". You can check this by navigating to the object manager in Salesforce, selecting the Opportunity object, and then viewing the field details for the custom field.
Verify that the field is a custom field: Make sure that the Opportunity_ID__c field is a custom field and not a standard field. If it is a standard field, you don't need to use the "__c" suffix when referencing it in your code.
Check the field-level security settings: Make sure that the field-level security settings for the Opportunity_ID__c field allow the user viewing the Visualforce page to see the field. You can check this by navigating to the field in the object manager and reviewing the field-level security settings.
Verify that the Visualforce page is associated with the correct object: Make sure that the Visualforce page you're working on is associated with the Opportunity object. You can check this by reviewing the "standardController" attribute of the apex:page tag at the top of the page.
I hope this helps you resolve the issue and retrieve the Opportunity_ID__c field in your Visualforce page. https://www.runyourpool.net/