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
navanitachoranavanitachora 

Obscure compiling error

Dear folks,

 

I am making an application in Salesforce where I need to display a SelectList of values based on the selection made in a another SelectList. I have worked with other Web development platforms but have only just started on Salesforce four days ago.  Please bear with me.

 

I am getting a very obsure compiling error and not able to progress any further:

Error: TimesheetEntry Compile Error: The method LIST<System.SelectOption> getProjects() is referenced by Visualforce Page (timesheet) in salesforce.com. Remove the usage and try again. at line 20 column 31

 

All I need to do is direct the id of the parameter to the getProjects method and render the returned SelectList on the page. I believe this is possible in Salesforce but I have not found a solution.

 

My VisualForce code is below:

 

<apex:page controller="TimesheetEntry" sidebar="false">
    <apex:pageBlock title="Timesheet Entry">
    
    <apex:pageBlockSection >
    Resource Name: {!$User.FirstName} {!$User.LastName}
    </apex:pageBlockSection>
    
    <apex:form >
    <apex:pageBlockSection columns="4">
    
    <apex:pageBlockSectionItem >
    <apex:selectList value="{!accountID}" size="1">
        <apex:selectOptions value="{!accounts}">
        </apex:selectOptions>
    </apex:selectList>
    </apex:pageBlockSectionItem>
    <apex:outputPanel>
        <apex:actionSupport event="onchange" action={!projects} rerender="projectSectionItem">
            <apex:param name="accountid" value="{!accountID}" />
        </apex:actionSupport>
    </apex:ouputPanel>
    
    
    <apex:outputPanel id="projectSectionItem" style="display:{!if(showProjects,'block','none')};">
    <apex:selectList value="{!projectID}" size="1">
        <apex:selectOptions value="{!projects}">
        </apex:selectOptions>
    </apex:selectList>
    </apex:outputPanel>
    
    </apex:pageBlockSection>
    </apex:form>
    </apex:pageBlock>
</apex:page>

and this is my controller code:

public with sharing class TimesheetEntry {
    
    public String projectID { get; set; }
    public String accountID { get; set; }
    public Boolean showProjects { get; set; }
    
    public TimesheetEntry() {
        showProjects = false;
    }

    public List<SelectOption> getAccounts() {
        List<SelectOption> accOptions = new List<SelectOption>();
        accOptions.add(new SelectOption('Select Account', '--Select Account--'));
        for (Account account: [SELECT id, Name FROM Account]) {
           accOptions.add(new SelectOption(account.id, account.Name));
        }
        return accOptions;
    }
    
    public List<SelectOption> getProjects(String accountid) {
        showProjects = true;
        List<SelectOption> projOptions = new List<SelectOption>();
        projOptions.add(new SelectOption('Select Project', '--Select Project--'));
        for (Project__c project: [SELECT id, Name FROM Project__c]) {
            projOptions.add(new SelectOption(project.id, project.Name));
        }
        return projOptions;
    }

 

Thanks in advance.

nav

 

MoUsmanMoUsman

Hi navanitachora ,

 

You can use only void or pageReference return type on action of any event in salesforce ,You need to create another fuction to do this functionality,for actionsupport componenet,as shown below.

<apex:page controller="TimesheetEntry" sidebar="false">
    <apex:pageBlock title="Timesheet Entry">
    
    <apex:pageBlockSection >
    Resource Name: {!$User.FirstName} {!$User.LastName}
    </apex:pageBlockSection>
    
    <apex:form >
    <apex:pageBlockSection columns="4">
    
    <apex:pageBlockSectionItem >
    <apex:selectList value="{!accountID}" size="1">
        <apex:selectOptions value="{!accounts}">
        </apex:selectOptions>
    </apex:selectList>
    </apex:pageBlockSectionItem>   
    <apex:outputPanel id="projectSectionItem" style="display:{!if(showProjects,'block','none')};">
    <apex:selectList value="{!projectID}" size="1">
        <apex:selectOptions value="{!projects}"/>
        <apex:actionSupport event="onchange" action={!onChange} rerender="projectSectionItem">
            <apex:param name="accountid" value="{!accountID}" />
        </apex:actionSupport>
    </apex:selectList>
    </apex:outputPanel>
    
    </apex:pageBlockSection>
    </apex:form>
    </apex:pageBlock>
</apex:page>
//Controller 
public with sharing class TimesheetEntry {
    
    public String projectID { get; set; }
    public String accountID { get; set; }
    public Boolean showProjects { get; set; }
    
    public TimesheetEntry() {
        showProjects = false;
    }

    public List<SelectOption> getAccounts() {
        List<SelectOption> accOptions = new List<SelectOption>();
        accOptions.add(new SelectOption('Select Account', '--Select Account--'));
        for (Account account: [SELECT id, Name FROM Account]) {
           accOptions.add(new SelectOption(account.id, account.Name));
        }
        return accOptions;
    }
    
    public List<SelectOption> getProjects(String accountid) {
        showProjects = true;
        List<SelectOption> projOptions = new List<SelectOption>();
        projOptions.add(new SelectOption('Select Project', '--Select Project--'));
        for (Project__c project: [SELECT id, Name FROM Project__c]) {
            projOptions.add(new SelectOption(project.id, project.Name));
        }
        return projOptions;
    }
	public void onChange(){
		//Create your logic here for onchange event of picklist
	}

If you more clarification please post it. 

--

Regards

Usman

 

navanitachoranavanitachora

Thanks MoUsman,

 

After some experimentation I got to your answer. What I am battling with now is how do I give the onChange function the account id parameter the line in question is this:

 

<apex:actionSupport event="onchange" action={!projectsByAccount} rerender="projectSectionItem">
            <apex:param name="accountid" value="{!accountID}" />
        </apex:actionSupport>

 I tried using

ApexPages.CurrentPage.getParameters()

But I now get an error saying:

Compile Error: Method does not exist or incorrect signature: ApexPages.CurrentPage.getParameters() at line 27 column 28

 

My code has been modified a bit but is roughly the same here is the new controller code:

 

public with sharing class TimesheetEntry {
    
    public String projectID { get; set; }
    public String accountID { get; set; }
    public Boolean showProjects { get; set; }
    public List<SelectOption> projOptions { get; set;}
    
    public TimesheetEntry() {
        showProjects = false;
        List<SelectOption> projOptions = new List<SelectOption>();
    }

    public List<SelectOption> getAccounts() {
        List<SelectOption> accOptions = new List<SelectOption>();
        accOptions.add(new SelectOption('Select Account', '--Select Account--'));
        for (Account account: [SELECT id, Name FROM Account]) {
           accOptions.add(new SelectOption(account.id, account.Name));
        }
        return accOptions;
    }
    
    public List<SelectOption> getProjects() {
        return projOptions;
    }
    
    public PageReference projectsByAccount() {
        String accountid = ApexPages.CurrentPage.getParameters().get('accountid');
        projOptions.add(new SelectOption('Select Project', '--Select Project--'));
        for (Project__c project: [SELECT id, Name FROM Project__c WHERE 
                Project__c.Account__r.id =: accountid]) {
                projOptions.add(new SelectOption(project.id, project.Name));
            }
        return null;
    }
}

 Kindly let me know if I should post this up as a new question as it is now getting a bit off topic. :-)

 

Many thanks,

nav

 

 

MoUsmanMoUsman

Yup you  need to pass the name of parameter,like this.

ApexPages.CurrentPage.getParameters('Id')

--

Thanks

Usman

MoUsmanMoUsman

You can use it will work deffniatly i have used several time.

<apex:param name="accountid" assignTo="{!accountID}" value="" />

 

navanitachoranavanitachora

Hi MoUsman tried what you suggested to use the assignTo attribute and did ApexPages.CurrentPage.getParameters().get('accountid');

 

No difference.

 

I also tried:

 

ApexPages.CurrentPage.getParameters('accountid');

 

Still having errors. There must be something I am missing.

 

Thanks for all the help.

 

nav