+ 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