0

I have to show custom object HCP Depth Tracker in Account's related list.It is having Account reference.It's child of Depth Tracker object which is immediate child of Account.My approach is by creating a vf page and drag it in page section.Please find issue I am facing.I have created below apex class.

global with sharing class poistionController {

     public HCP_Depth_Tracker_OAPI__c pos{get;set;}

     public poistionController() {

         pos = [select Monthly_Call_Attainment_OAPI__c,Name,Account_OAPI__c,Active_HCP_DT_OAPI__c,Id,Territory_OAPI__c,Total_Actual_Calls_Month_OAPI__c from HCP_Depth_Tracker_OAPI__c where HCP_Account_OAPI__c= :ApexPages.currentPage().getParameters().get('id')];

      }

}

Apex page:

<apex:page standardController="HCP_Depth_Tracker_OAPI__c" extensions="poistionController" showHeader="false">
   <div align="center" width="550px">
      <b>
         <apex:outputText value="Your maximum salary could be AT MAXIMUM {!HCP_Depth_Tracker_OAPI__c .name}"/>
      </b>
   </div> 
</apex:page>

Getting error in the page like this.

Error: Unknown constructor 'poistionController.poistionController(ApexPages.StandardController controller)'

Please let me know the way out.

1

I see that you're utilising the standard controller for that object and you don't have a standard controller constructor in your class. Change your constructor to include standard controller as a parameter:

public poistionController(Apexpages.StandardController controller)
{
// your code
}

Now in your controller variable you have the HCP_Depth_Tracker_OAPI__c record with values for all the fields that you've referenced on the VF page + the record ID. If you want to get values for other fields you need either to use the controller.addFields() method or get them by running a SOQL query. Read more around standard controllers

  • Hi Bachovski,I am sorry I can't get it.Can you please explain it in details? – Testing_SFDC Aug 26 '14 at 4:07
  • Which part you don't understand? – Boris Bachovski Aug 26 '14 at 4:11
  • controller.addFields() - this section – Testing_SFDC Aug 26 '14 at 4:30
  • 1
    Here is a good explanation on addFields from @bobbuzzard - bobbuzzard.blogspot.com.au/2011/04/…. Pretty much if you only have account.Name referenced on the page, in the controller you can get the value by controller.getRecord().get('Name'), but if you try to get other field's value for example Phone, the value will be null unless you either run a SOQL query OR use the addFields(new List <String> {'Phone'}) method. – Boris Bachovski Aug 26 '14 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.