0

I have been stuck on this problem for days. Basically I have a select list populated by all records in the custom object "Sprint__c". When I select a record in that select list, I am trying to list all the records in custom object "User_Story__c" where the lookup relationship field on the user story is the selected sprint in the select list.

So far, this is what I have gotten on the controller:

public class rw_userstorycontroller {

    public User_Story__c theStory {get;set;}
    public Sprint__c theSprint {get;set;}

    public List<SelectOption> getStorysprints() {     
        List<SelectOption> options = new List<SelectOption>();
        List<rw_sprint__c> Sprints =  [Select id, Name, timeframe__c,total_capacity__c From rw_sprint__c WHERE total_capacity__c !=0];
        options.add(new SelectOption('0001', '--Select--'));
        for(rw_sprint__c spr : Sprints ){
            options.add(new  SelectOption(spr.id, spr.timeframe__c));
        }
        return options;
    }

    public String selectedsprint {get; set;}

    public List<RW_User_story__c> getstorysprints1(){
        if(selectedValue == 'sprints'){  
            return [SELECT Id,Name,Status__c, CreatedDate FROM RW_User_story__c WHERE rw_userstory_sprints__c = :'sprints.id'];  
        } else{
            return NULL;
        }
    }
0

Assuming your Visualforce contains something like this (where "sprints" is the ID of the part of the page that displays the list of RW_User_story__c objects and so needs to be re-rendered):

<apex:selectList value="{!selectedsprint}" size="1">
    <apex:selectOptions value="{!storysprints}"/>
    <apex:actionSupport event="onchange" reRender="sprints"/>
</apex:selectList>

then these changes to the controller should make the logic work:

public Id selectedsprint {get; set;}

public List<RW_User_story__c> getstorysprints1(){
    if (selectedsprint != null){  
        return [
                SELECT Id,Name,Status__c, CreatedDate
                FROM RW_User_story__c
                WHERE rw_userstory_sprints__c = :selectedsprint
                ORDER BY Name
                ];  
    } else {
        return new List<RW_User_story__c>();
    }
}

See Using Apex Variables in SOQL and SOSL Queries for information about how to bind variables into SOQL queries.

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.