• Fowkes1985
  • NEWBIE
  • 10 Points
  • Member since 2013
  • Business Administration Manager
  • The Bushcraft Company

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
I have added a VF page, trigger and control and receive Map key a2VD0000000v4AnMAI not found in map.

Any help at all please, new to Apex and using similar development work as a template

VF Page:
<apex:page controller="CampItineraryController" title="Camp Itinerary">
<apex:sectionHeader title="Camp Itinerary"/>
<apex:pageMessages />
<apex:form >    
  <apex:pageBlock title="Sessions">

        <apex:pageBlockButtons >
          <apex:commandButton action="{!saveSessions}" id="saveButton" value="Save" status="sessionsStatus" rerender="elementsTable"/>
          <apex:commandButton action="{!addSessions}"  id="addButton"  value="Add" rerender="sessionTable, elementsTable" status="sessionsStatus"/>
          <apex:commandButton action="{!deleteSessions}"  id="deleteButton"  value="Delete" rerender="sessionTable" status="sessionsStatus"/>
        </apex:pageBlockButtons>
        <apex:actionStatus id="sessionsStatus" stopText="">
            <apex:facet name="start" >
              <apex:outputPanel >
              <apex:outputtext value="Updating...    "/>
              <apex:image url="/img/loading.gif" />                       
              </apex:outputPanel>
            </apex:facet>          
          </apex:actionStatus>         
        <apex:pageBlockTable value="{!sessions}" var="r" id="sessionTable">   
          <apex:column headerValue="Select" style="width: 30px">        
            <apex:inputCheckbox value="{!r.isSelected}"/>
          </apex:column>
          <apex:repeat value="{!$ObjectType.Session__c.FieldSets.Related_List_Fields}" var="f">
            <apex:column headerValue="{!f.label}" >
              <apex:inputField value="{!r.obj[f]}" />
            </apex:column>
          </apex:repeat>
        </apex:pageBlockTable>
  </apex:pageBlock>

  <apex:pageBlock title="Durations">

        <apex:pageBlockButtons >
          <apex:commandButton action="{!saveDurations}" id="saveButton" value="Save" status="durationsStatus"/>
          <apex:commandButton action="{!addDurations}"  id="addButton"  value="Add" rerender="durationTable" status="durationsStatus"/>
          <apex:commandButton action="{!deleteDurations}"  id="deleteButton"  value="Delete" rerender="durationTable" status="durationsStatus"/>
        </apex:pageBlockButtons>
        <apex:actionStatus id="durationsStatus" stopText="">
            <apex:facet name="start" >
              <apex:outputPanel >
              <apex:outputtext value="Updating...    "/>
              <apex:image url="/img/loading.gif" />                       
              </apex:outputPanel>
            </apex:facet>          
          </apex:actionStatus>         
        <apex:pageBlockTable value="{!durations}" var="d" id="durationTable">   
          <apex:column headerValue="Select" style="width: 30px">        
            <apex:inputCheckbox value="{!d.isSelected}"/>
          </apex:column>
          <apex:repeat value="{!$ObjectType.Session_Duration__c.FieldSets.Related_List_Fields}" var="f">
            <apex:column headerValue="{!f.label}" >
              <apex:inputField value="{!d.obj[f]}" />
            </apex:column>
          </apex:repeat>
        </apex:pageBlockTable>
  </apex:pageBlock>

  <apex:pageBlock title="Elements">

        <apex:pageBlockButtons >
          <apex:commandButton action="{!saveElements}" id="saveButton" value="Save" status="elementsStatus"/>
        </apex:pageBlockButtons>
        
<!--        <apex:repeat value="{!sessions}" var="thisSession">
            <apex:repeat value="{!durations}" var="thisDuration">
                {!thisSession.obj.id} {!thisDuration.obj.id} <br/>
                {!elements[thisSession.obj.id][thisDuration.obj.id].Element__c} <br/>
            </apex:repeat>
        </apex:repeat>-->

        <apex:pageBlockTable value="{!sessions}" var="thisSession" id="elementsTable">
                <apex:column headerValue="Session">
                    <apex:outputField value="{!thisSession.obj['name']}"/>
                </apex:column>
            <apex:repeat value="{!durations}" var="thisDuration">
                <apex:column headerValue="{!thisDuration.obj['name']}">
                    <apex:inputField value="{!elements[thisSession.obj.id][thisDuration.obj.id].Element__c}"/>
                </apex:column>
            </apex:repeat>
        </apex:pageBlockTable>
  </apex:pageBlock>  

</apex:form>
</apex:page>

Controller
 
ublic with sharing class CampItineraryController {

    public List<sObject> extractObjs(List<sObjectWithSelect> theList) {
        return extractObjs(theList, false);
    }
    
    public List<sObject> extractObjs(List<sObjectWithSelect> theList, boolean testForSelected) {
        List<sObject> rval = new List<sObject>();
    
        for(sObjectWithSelect thisObj : theList) {
            if(!testForSelected || thisObj.isSelected) {
                rval.add(thisObj.obj);
            }
        }
        
        return rval;
    }

    public class sObjectWithSelect {
        
        public sObject obj {get; set;}
        public boolean isSelected {get; set;}
        
        public sObjectWithSelect(sObject obj) {
            this.obj = obj;
            this.isSelected = false;
        }
        
    }

    public List<sObjectWithSelect> sessions {get; set;}
    public List<sObjectWithSelect> durations {get; set;}
    public Map<String, Map<String, Session_To_Duration__c>> elements {get; set;}
    private List<Session_To_Duration__c> rawelements;
    private String sessionQueryString;
    private String durationQueryString;
    
    public CampItineraryController() {
        Schema.FieldSet fs = Schema.SObjectType.Session__c.fieldSets.Related_List_Fields;
        
        String selectfields = 'id ';
        
        for(Schema.FieldSetMember thisField : fs.getFields()) {
            selectFields = selectFields + ', ' + thisField.getFieldPath();
        }

        sessionQueryString = 'SELECT ' + selectfields
                         + ' FROM Session__c ORDER BY Name ASC';

        
        fs = Schema.SObjectType.Session_Duration__c.fieldSets.Related_List_Fields;
        
        selectfields = 'id ';
        
        for(Schema.FieldSetMember thisField : fs.getFields()) {
            selectFields = selectFields + ', ' + thisField.getFieldPath();
        }

        durationQueryString = 'SELECT ' + selectfields
                         + ' FROM Session_Duration__c ORDER BY Name ASC';        

        initSessions();
        initDurations();
        initElements();        
    }
    
    private void initElements() {
        rawElements = [SELECT id, Element__c, Session__c, Session_Duration__c 
                                               FROM Session_To_Duration__c];
                                               
        elements = new Map<String, Map<String, Session_To_Duration__c>>();
        
        for(Session_To_Duration__c thisSTD : rawElements) {
            Map<String, Session_To_Duration__c> thisMap = elements.get(thisSTD.Session__c);
            
            if(thisMap == null) {
                thisMap = new Map<String, Session_To_Duration__c>();
                elements.put(thisSTD.Session__c, thisMap);
            }
            
            thisMap.put(thisSTD.Session_Duration__c, thisSTD);
        }
    }
    
    private void initSessions() {
        system.debug(sessionQueryString);
        List<Session__c> theSessions = Database.query(sessionQueryString);

        sessions = new List<sObjectWithSelect>();

        for(Session__c thisSession : theSessions) {
            sessions.add(new sObjectWithSelect(thisSession));
        }
    }

    private void initDurations() {
        system.debug(durationQueryString);
        List<Session_Duration__c> theDurations = Database.query(durationQueryString);

        durations = new List<sObjectWithSelect>();

        for(Session_Duration__c thisDuration : theDurations) {
            durations.add(new sObjectWithSelect(thisDuration));
        }
    }
        
    public PageReference addSessions() {
        saveSessions();
        Session__c newSession = new Session__c(Name = 'Enter a session name');
        
        try {
            insert newSession;
        } catch(Exception e) {
            ApexPages.addMessages(e);
        }
        
        sessions.add(new sObjectWithSelect(newSession));
        initElements();
        
        return null;
    }

    public PageReference saveSessions() {
        
        try {
            update extractObjs(sessions);
        } catch(Exception e) {
            ApexPages.addMessages(e);
        }
        
        initElements();
        
        return null;
    }

    public PageReference deleteSessions() {
        
        try {
            delete extractObjs(sessions, true);
        } catch(Exception e) {
            ApexPages.addMessages(e);
        }
        
        initSessions();
        initElements();
        
        return null;
    }
    public PageReference deleteDurations() {
        try {
            delete extractObjs(durations, true);
        } catch(Exception e) {
            ApexPages.addMessages(e);
        }
        
        initDurations();
        initElements();
        
        return null;
    }


    public PageReference addDurations() {
        saveDurations();
        Session_Duration__c newDuration = new Session_Duration__c(Name = 'Enter a duration name');
        
        try {
            insert newDuration;
        } catch(Exception e) {
            ApexPages.addMessages(e);
        }
        
        durations.add(new sObjectWithSelect(newDuration));
        initElements();
       return null;
    }


    public PageReference saveDurations() {
        try {
            update extractObjs(durations);
        } catch(Exception e) {
            ApexPages.addMessages(e);
        }
        
        initDurations();
        initElements();
        
        return null;
    }

    public PageReference saveElements() {
        try {
            update rawElements;
        } catch(Exception e) {
            ApexPages.addMessages(e);
        }
        
        return null;
    }

}

 
I have the following code which totals a column.

<table class="remit">
    <tr>
      <th>Camp Ref</th>
      <th>Start Date</th>
      <th>Duration</th>
      <th>Role</th>
      <th>Pay</th>
      <th>Holiday</th>
      <th>Total</th>
    </tr>
    
    <apex:repeat value="{!ctsList}" var="cts">
    <tr>
      <apex:repeat value="{!$ObjectType.Camp_To_Staff__c.FieldSets.Remittance_Columns}" var="f">
        <td>
          <apex:outputField value="{!cts[f]}"/>
<!--          <apex:outputtext value="{!cts[f]}" rendered="{!f.fieldPath != 'Course_Start_Date__c'}" />
          <apex:outputText value="{0,date,dd/MM/yyyy}" rendered="{!f.fieldPath == 'Course_Start_Date__c'}">
            <apex:param value="{!NOW()}" />
          </apex:outputText>
          -->
        </td>
      </apex:repeat>     
    </tr>
    </apex:repeat>
    <tr class="totals">
      <td colspan="6" class="label" style="text-align: right">
        TOTAL
      </td>
      <td>
        <apex:outputText value="{0, number, '£'##,###.00}">
          <apex:param value="{!total}" />
        </apex:outputText>
      </td>
    </tr>
  </table>
  </body>
</apex:page>

Currently this totals the Pay Rate column (column 5), but I wish to total the Total column (column 7) and am not sure how this i referenced.  Any help please?