• Peter Thompson 21
  • NEWBIE
  • 335 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Building an application in VF that simulates creating and delivering exams. Having issue with a page that is supposed to add a custom grouping of questions to the Exam. Before I implemented the standard controller, it was working perfectly as intended. After converting from just simple controller to an extension, I've been having issues.

User-added image
I am able to click one checkbox, and it will populate the Summary correctly. If I uncheck it, check any other box, or modify Questions to Pull, I get Map key a051I000002oO6OQAU not found in map. 
That key is the Exam record from where I started the VF page. No other information is given to me.

VF:
<apex:page title="Add Banks to Exam" standardController="Exam__c" extensions="AddBanksToExamController" docType="html-5.0" >
    <apex:variable var="finalTotal" value="{!0}" />

    <apex:form >
        <apex:pageBlock title="Search Banks" >
            <apex:pageBlockSection columns="2">
                <apex:pageBlockSectionItem ><apex:inputText id="bankSearch" value="{!bankSearchText}" html-placeholder="Search banks by Name" /></apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem ><apex:commandButton value="Search" action="{!searchBanks}"/></apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem ><apex:commandButton value="Search All" action="{!searchAll}"/></apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection id="bankSearchResults">
                <apex:pageBlockTable id="bankSearchResultsTable" value="{!banksSearchResult}" var="oneBank" columns="3">
                    <apex:column>
                        <apex:pageblocksection id="individualQs" title="{!oneBank.bank.Name}" showheader="true" collapsible="true" columns="1">
                            <apex:pageBlockTable id="bankSubTable" value="{!oneBank.questionsForThisBank}" var="oneQuestion" width="100%">
                                <apex:column headerValue="Question Name" value="{!oneQuestion.Name}" width="75%" />
                            </apex:pageBlockTable>
                        </apex:pageblocksection>
                    </apex:column>
                    
                    <apex:column headervalue="Add">
                        <apex:inputCheckbox value="{!oneBank.selected}">
                            <apex:actionSupport event="onclick" action="{!collectAllSelected}"  rerender="debug, amounts" >
                                <apex:param name="bankCheckbox_Id" value="{!oneBank.bank.Id}" />
                            </apex:actionSupport>
                        </apex:inputCheckbox>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>

        <apex:pageBlock title="Summary" id="amounts" >
            <apex:pageBlockTable value="{!selectedBanks}" var="key">
                <apex:column headerValue="Bank" value="{!selectedBanks[key].bank.Name}"></apex:column>
                <apex:column headerValue="Questions in Bank" value="{!selectedBanks[key].questionCount}"></apex:column>
                <apex:column headerValue="Questions to Pull"> 
                    <apex:input type="auto" value="{!selectedBanks[key].questionsToPull}" html-min="0" html-max="{!selectedBanks[key].questionCount}" html-oninput="validity.valid||(value='');" >
                        <apex:actionSupport event="onchange" rerender="debug, amounts"/>
                    </apex:input>
                    <apex:variable var="finalTotal" value="{!selectedBanks[key].questionsToPull + finalTotal }" />
                    <apex:facet name="footer">
                        Total Questions: {!finalTotal}
                    </apex:facet>
                </apex:column>
            </apex:pageBlockTable>
            <apex:commandButton value="Save"/>
        </apex:pageBlock>
        
        <apex:pageBlock title="Debug" id="debug">
            <apex:outputText value="{!Exam.Id}"> Exam ID: </apex:outputText> <br /> <br />
            <!-- <apex:outputText value="{!selectedBanksIds}">Banks Keyset: </apex:outputText> <br /> <br />
             <apex:outputText value="{!selectedBanksValues}">Banks (look at QtoPull): </apex:outputText>
            
            <!-- <apex:outputText value="{!selectedQuestions}">Questions Selected: </apex:outputText> -->
        </apex:pageBlock>
        
    </apex:form>
    
    
</apex:page>

Apex:
public class AddBanksToExamController {
    public Exam__c exam {get; set;}
    public String bankSearchText {get; set;}
    public List<wBanks> banksSearchResult {get; set;}
    
    public Map<id, wBanks> selectedBanks {get; set;}
    public Set<id> selectedBanksIds {get; set;}
    //Debugging
    //public List<wBanks> selectedBanksValues {get; set;}
    //public Map<id, Question__c> selectedQuestions {get; set;} 
    
    public AddBanksToExamController(ApexPages.StandardController examCon) {
        this.exam = (Exam__c)examCon.getRecord();
        searchAll();
        //selectedBanks = new Map<id, wBanks>();
        //selectedQuestions = new Map<id, Question__c>();
    }
    
    public class wBanks {
        public Question_Bank__c bank {get; set;}
        public Boolean selected {get; set;}
        public List<Question__c> questionsForThisBank {get; set;}
        public Integer questionCount {get; set;}
        public Integer questionsToPull {get; set;}
        
        public wBanks (Question_Bank__c bank) {
            questionsToPull = 0;
            this.bank = bank;
            this.selected = false;
            if (questionsForThisBank == null) { questionsForThisBank = new List<Question__c>(); }
            
            questionsForThisBank = QuestionService.getAllQuestionsInBank(bank);
            questionCount = questionsForThisBank.size();
        } //end constructor
    } //end Bank Wrapper

    
    public PageReference searchAll() {
        if (banksSearchResult == null) { banksSearchResult = new List<wBanks>();}
        else { banksSearchResult.clear(); }
        
        List<Question_Bank__c> allBanks = [Select Id, Name from Question_Bank__c];
        
        for(Question_Bank__c oneBank : allBanks) {
            banksSearchResult.add(new wBanks(oneBank));
            System.debug('Search Added: ' +oneBank.Name);
        }
        return null;
    }
    
    public void collectAllSelected() {
        if (selectedBanks == null) {
            selectedBanks = new Map<id, wBanks>();
        }
        for(wBanks thisBank : banksSearchResult) {
            if (thisBank.selected == TRUE) { 
                selectedBanks.put(thisBank.bank.Id, thisBank); 
                System.debug('Collect added ' +thisBank.bank.Name);
                System.debug('So far: ' +selectedBanks);
            }
            else {
                selectedBanks.remove(thisBank.bank.id);
            }
        }
        //Get List of Keys for debugging
        selectedBanksIds = selectedBanks.keySet();
        //selectedBanksValues = selectedBanks.values();
    } //end collectAllSelected()
    
    
    
}

 
I'm trying to complete the "Set Up Single Sign-On for Your Internal Users" Trailhead challenge, and was able to execute the description of the challenge successfully. However, I'm getting the following error when checking the challenge on Trailhead:
 
Challenge Not yet complete... here's what's wrong: 
Could not find SAML Enabled in your org's setup audit trail. Make sure that you have 'SAML Enabled' checked under 'Federated Single Sign-On Using SAML' in your org's 'Single Sign-On Settings'.

I've reviewed the settings, and "SAML Enabled" is true, and I'm connected to the right org when doing the challenge. Has anyone else encountered this?