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
JJJenkinsJJJenkins 

Render Related Object Fields in VF page layout

Hey Everyone -

 

I have a custom object that I want to display within the opportunity page layout as it's own section.  The VF page will render certain fields/sections based on how other fields are filled in.  I have the object/ fields and VF page built but I cannot get the controller to work so I can place it in the Opportunity layout.

 

I attempted to build a list type of controller

public class Questionnaire {
    public Questionnaire(ApexPages.StandardController controller){}
        List<Questionnaire>Questions;
        publicList<Questionnaire>getQuestions(){
            Questions=[select *FIELDS* from Questionnaire__c];
            return Questions;
    }  
}

 

 

But kept receiving a compile errore for invalid public list.  I just need to be able to display the fields so I'm unsure if list is even the way to go.

 

Obviously I'm really new to all this.  Any help would be appreciated.

 

Thanks,

Michael_JohnsonMichael_Johnson

How is this object related to Opportunity, is there a lookup from the Questionaire__c object? If so, are you trying to display fields of all Questinaire__c records related to this particular Opportunity?

JJJenkinsJJJenkins

Exactly.  There is a look up field on the questionnaire object.

 

Then I have a VF page that will render certain fields from the questionnaire on the oppty layout.

 

Thanks,

Michael_JohnsonMichael_Johnson

Try this

 

public class Questionnaire {
    public Opportunity o;
    public Questionnaire(ApexPages.StandardController controller){}
 this.o = (Opportunity)controller.getRecord();
    }  
        
    public List<Questionnaire> getQuestions(){
 List<Questionnaire__c> Questions = new List<Questionnaire__c>();        
 for(Questionaire__c q:[select *FIELDS* from Questionnaire__c where Opportunity__c =: o.id]){
 Questions.add(q);
 }
        return Questions;
    }
}

 

JJJenkinsJJJenkins

Michael - thank for the help on this.  It makes a lot more sense now.

 

I do keep getting a compile error kicked back at lin4 column 6.

it is saying the "=" is an unexpected token in the line

this.o=(Opportunity)controller.getRecord();

 

any guidance you can give on that error?

 

Thanks,

JJJenkinsJJJenkins

This is what I have now:

 

public class Questionnaire{
    public Opportunity o;
    public Questionnaire(ApexPages.StandardController controller){}
   {
this.o=(Opportunity)controller.getRecord();
}

publicList<Questionnaire>getQuestions(){
   List<Questionnaire__c>Questions=newList<Questionnaire__c>();
    for(Questionnaire__c q:[select Each_Customer_Can_Redeem__c,Number_per_Table__c from Questionnaire__c where Opportunity=:o.id]){
    Questions.add(q);
}
        return Questions;
}    
}

 

 

But I'm receiving this error:

Compile Error: unexpected token: '(' at line 9 column 60

 

Thoughts?

hgarghgarg

I think there is a syntax mistake, try putting a space between new and List<Questionnaire__c> at line no.9

like:

List<Questionnaire__c> Questions = new List<Questionnaire__c>();

JJJenkinsJJJenkins

Thanks!

 

That fixed it and I had a few others that I found now that I understood this part. But now I'm getting this error:

Compile Error: Method does not exist or incorrect signature: controller.getRecord()

 

for this line:

this.o=(Opportunity)controller.getRecord();

 

After I get this up and running I'm going back to the workbook/cookbook and try to learn a lot more.