• MiaC
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi,

 

I am pretty new to Visualforce... I have the developer guide printed out in front of me trying to get my head wrapped around everything.

 

I currently have a custom controller that pulls a bunch of records from a custom object called Milestone__c based on the Opp ID of the current page.That works fine, I am just trying to get a save button to work so I/whoever can update the milestones quickly. I used the "An Approach to Inline Editting" tutorial and that works fine but now am thinking that a save button on the list would be better. Can anyone help me with this?

 

I really want to make the Status field a drop down where you can edit multiple then save. Right now it is a drop down but I can't figure out the Save function, I've tried a bunch of different approaches based on posts but have been unsuccessful.

 

VF:

 

<apex:page Controller="TestMilestones" showHeader="false" > <apex:form > <apex:pageBlock title="Milestones" > <apex:pageBlockButtons location="top"> <apex:commandButton action="{!save}" value="save" id="saveButton"/> </apex:pageBlockButtons> <apex:outputPanel id="projectList"> <table> <tr> <th style="width:25px; "> </th> <th style="width:25px; "> </th> <th style="width:150px; ">Name</th> <th style="width:68px; ">Status</th> <th style="width:30px; ">Duration</th> </tr> <apex:repeat value="{!projects}" var="p"> <tr style="height:22px"> <apex:outputPanel id="editRow" layout="none" rendered="{!p.Id == editProject.Id}"> <td><apex:commandLink action="{!cancelEdit}" rerender="projectList">Cancel</apex:commandLink></td> <td><apex:commandLink action="{!saveEdit}" rerender="projectList">Save</apex:commandLink></td> <td><apex:inputField rendered="{!p.Id == editProject.Id}" value="{!editProject.Name}"/></td> <td><apex:inputField rendered="{!p.Id == editProject.Id}" value="{!editProject.Status__c}"/></td> <td><apex:inputField rendered="{!p.Id == editProject.Id}" value="{!editProject.Duration__c}"/></td> </apex:outputPanel> <apex:outputPanel id="viewRow" layout="none" rendered="{!p.Id != editProject.Id}"> <td style="font-style:italic; font-size:10px"> <apex:commandLink action="{!del}" onclick="return confirm('Are you sure you want to delete this project?')">Del <apex:param name="delid" value="{!p.Id}"/> </apex:commandLink> </td> <td style="font-style:italic"> <apex:commandLink action="{!edit}" rerender="projectList">Edit <apex:param name="editid" value="{!p.Id}"/> </apex:commandLink> </td> <td>{!p.Name}</td> <td style="background-color:yellow"><apex:inputField id="stat" value="{!p.Status__c}" /></td> <td><CENTER>{!p.Duration__c}</CENTER></td> </apex:outputPanel> </tr> </apex:repeat> </table> <CENTER><STRONG>**Click on status to update it</STRONG></CENTER> </apex:outputPanel> </apex:pageBlock> </apex:page>

 

 Controller:

 

public class TestMilestones { public TestMilestones(ApexPages.StandardController controller) { } public Milestone__c newProject { get; set; } public Milestone__c editProject { get; set; } public TestMilestones() { newProject = new Milestone__c(); } public Milestone__c[] getProjects() { return [SELECT Name, Duration__c, Status__c FROM Milestone__c WHERE Opportunity__c = :ApexPages.currentPage().getParameters().get('id') ORDER BY CreatedDate DESC]; } public String getParam(String name) { return ApexPages.currentPage().getParameters().get(name); } public PageReference add() { try { INSERT newProject; // if successful, reset the new project for the next entry newProject = new Milestone__c(); } catch (Exception e) { ApexPages.addMessages(e); } return null; } public PageReference del() { try { String delid = getParam('delid'); Milestone__c project = [SELECT Id FROM Milestone__c WHERE ID=:delid]; DELETE project; } catch (Exception e) { ApexPages.addMessages(e); } return null; } public PageReference edit() { String editid = getParam('editid'); editProject = [SELECT Name, Duration__c, Status__c FROM Milestone__c WHERE Id=:editid]; return null; } public PageReference cancelEdit() { editProject = null; return null; } public PageReference saveEdit() { try { UPDATE editProject; editProject = null; } catch (Exception e) { ApexPages.addMessages(e); } return null; } }

 

 Any help would be greatly appreciated