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
bakumbakum 

passing ID as parameter overridden by url ID?

Hi, I am trying to make a VF page to replace something I did pretty easily with s-controls. 

Basically, I have an object, System_Engineer__c which a related object (1:n) Support_Time__c.  The Support_Time__c records have an Approved__c field (checkbox).

What I want to do is display a list of the unapproved support time records on the System_Engineer's detail page, and then provide a link to approve each record.  Eventually, I'd like to have checkboxes next to each unapproved record, one Submit button at the bottom, and then the controller updates the APproved__c field for every checked record, but that's getting ahead of myself.  Right now, clicking an [ approve ] link should simply update the single record in question.  But it doesn't work.  It seems to be passing the ID of the SYstem_Engineer himself, instead of the ID of the Support_Time record.  I don't know why.

Any help?

Thanks! 

-mb


<apex:page controller="MyController" tabStyle="Sales_Engineer__c">
    <apex:detail relatedList="false" />
   <apex:form >
    <apex:pageBlock title="My Unapproved Support Times">
     <apex:dataTable id="timesTable" value="{!myUnapprovedTimes}" var="aTime" width="50%" >
         <apex:column ><apex:facet name="header"><b>Date</b></apex:facet>{!aTime.Date__c}</apex:column>
         <apex:column ><apex:facet name="header"><b>Hours</b></apex:facet>{!aTime.Hours__c}</apex:column>
         <apex:column ><apex:facet name="header"><b>Approve All</b></apex:facet>
             <apex:commandLink action="{!approveMe}" value="[ approve ]" reRender="timesTable">
               <apex:param value="{!aTime.Id}" assignTo="{!myId}"></apex:param>
            </apex:commandLink>
         </apex:column> 
        
      </apex:dataTable> 
    </apex:pageBlock>
  </apex:form>

</apex:page>
~~~~~~~~~~~~~~~~
public class MyController {

    Id myId;

    public void setMyId(Id id)
    {
     myId = id;
    }

  
    public String getMyId() {
      return myId;
    }  


   public List<Support_Time__c> getMyUnapprovedTimes()
    {
        return [SELECT Id, Date__c, Hours__c, Approved__c FROM Support_Time__c
                WHERE Sales_Engineer__c = :System.currentPageReference().getParameters().get('id')
                AND Approved__c = FALSE
                ORDER BY Date__C DESC];
    }
   
   public PageReference approveMe() {
       Support_Time__c st = [SELECT Id, Name FROM Support_Time__C WHERE Id=:myId];
       st.Approved__c = TRUE;
       update st;
       return null;
   }
 
}

Ron HessRon Hess
here is another way to use param, on the page


Code:
 <apex:param name="aid" value="{!atime.id}" />

 
then in your code
Code:
public PageReference approveMe() {
Support_Time__c st = [SELECT Id, Name FROM
Support_Time__C WHERE Id=
:ApexPages.currentPage().getParameters().get('aid') ];
st.Approved__c = TRUE;
update st;
return null;
}



you could also avoid this second query if you stored the list in a map with the id as the key.
 


Message Edited by Ron Hess on 08-07-2008 05:31 PM
bakumbakum
Thanks, Ron!  I'll check it out...