0

What we did so far... We created a visual force page that calls a class and added an extension to get the ID. We got some Error :)

(We try to get the ID for the currently displayed Lead, which should be able to get from the standard controller passed to an extension controller, we want to query its date then using this date to query the Leads and Opportunities that have that same date.)

if the page can show the "current lead" how can we present the related leads and opportunities in the same page in some iterated list presentation?

VFP

    <apex:page standardController="Lead" recordSetVar="acts" extensions="e2">
  <apex:pageBlock title="Leads" >
      <apex:PageBlockTable value="{!acts}" var="a">
          <apex:column value="{!a.Name}"/>
          <apex:column value="{!a.Datum_Event__c}"/>
          <apex:column value="{!a.Budget__c}"/>
          <apex:column value="{!a.Eventart__c}"/>
          <apex:column value="{!a.Gaestezahl__c}"/>
      </apex:PageBlockTable>
      <apex:PageBlockTable value="{!eL}" var="e">
          <apex:column value="{!e.Datum_Event__c}"/>// just to check if we can access the extension
      </apex:PageBlockTable>
  </apex:pageBlock>
</apex:page>

Extension

public with sharing class e2 {

public e2(Lead controller) {

}

public e2(ApexPages.StandardSetController controller) {

}

public Id currentId = null;

public e2(ApexPages.StandardController controller) {
    currentId = controller.getRecord().Id;

}

List<Lead> eL = [SELECT Datum_Event__c FROM Lead WHERE Id = :currentId];

List<Lead> geteL(){
return eL;
}
}
0

Your Apex class is very confused. It looks like you have pasted method code outside a method declaration. As a result, when you get to

    public List<Lead> getacts(){

you are still syntactically inside the block that started at

{
if (!currentLeads.isEmpty()) {

which Apex is reading as an instance initialization block, a rarely-used feature that is almost certainly not what you wanted.

Since you cannot declare a method inside such a block, an error results. It's not totally clear from the code you've provided here what your intent was, but you may wish to place all of your code outside of the two public properties you're attempting to define in a constructor.

There are some other issues here too:

  • Your extension controller has duplicated constructors, and you don't need the extension controller anyway because you have a custom primary controller. Alternately, based on your comment, you should declare your Visualforce page to have standardController="Lead" and move all of your logic into the extension controller
  • You're running two queries without filters that you don't appear to need:

    List<Lead> acts = [select Name, Budget__c, Eventart__c, Gaestezahl__c from Lead];
    List<Opportunity> acts2 = [select Name, Amount, EventArtC__c, AnzahlDerGaeste_C__c from Opportunity];
    
| improve this answer | |
  • Thank you for your answer. Yes there may be some code that doesnt belong there. We try to get the ID for the currently displayed Lead, which should be able to get from the standard controller passed to an extension controller, we want to query its date then using this date to query the Leads and Opportunities that have that same date.) if the page can show the "current lead" how can we present the related leads and opportunities in the same page in some iterated list presentation? – Con Apr 30 '19 at 17:26
  • @Con That's a big-picture objective. Your little-picture is broken: you can't even push this Apex to the server to experiment with it. I've added some more suggestions, and I think the best course is to focus on getting your page and extension controller to compile at all. Then you can worry about your logic. – David Reed Apr 30 '19 at 17:38
  • Thank you for your advice. I will change it to a StandardController. To put all the logic into the extension will be very hard for me as I don't exactly know what to do. Can you please give me an example? – Con May 1 '19 at 8:10
  • The Visualforce Basics module on Trailhead includes examples of using standard and custom controllers. – David Reed May 1 '19 at 13:10
  • Can someone please tell me if I am on the right way? – Con May 2 '19 at 12:33

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.