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
Nuno REISNuno REIS 

Visualforce Page that Uses an Extension Controller on Opportunity object

Hello all,

I'm trying to create a VFP with Opportunity as the Standard controller and an extension controller.

I'd like to get the fields values from the current Opportunity.
I've tried many codes but I get error messages 

Here is one code:
// Visualforce //
<apex:page standardcontroller="Opportunity" extensions="MyController">
etc ...

// Controller //
public Opportunity opt { get; set; }
public MyController(ApexPages.StandardController sc) {
     theId = ApexPages.currentPage().getParameters().get('id');
     opt = (Opportunity) sc.getRecord(); 
     }

Unfortunately for this line opt = (Opportunity) sc.getRecord();  I get the error message "Incompatible types since an instance of SObject is never an instance of Opportunity" 
From this controller, I want to reach the current fields values and the fields values from the related objects.
Any idea, please?
Many thanks
Nuno.
Best Answer chosen by Nuno REIS
Aman MalikAman Malik
Hi,

Seems you have an Apex class with the name 'Opportunity' in your org. Delete that class if exist and give it one more try.

Thanks

All Answers

Aman MalikAman Malik
Hi,

Seems you have an Apex class with the name 'Opportunity' in your org. Delete that class if exist and give it one more try.

Thanks
This was selected as the best answer
Nuno REISNuno REIS
Hi Aman,

You're right. I had an Apex class with the name 'Opportunity' in my org.
Many thanks