+ Start a Discussion
Peter CowenPeter Cowen 

visualforce page saving wrong field

I am currently trying to create a buton on the ticket that will allow a level 1 support engineer to place a ticket in the level 2 queue. 

I have a vf page that contains several fields on case that they need to complete and the case comment.

I have created a extension for the case comment which is:
public class Caselinktocomment
    public CaseComment comment { get; set; }

    public Caselinktocomment(ApexPages.StandardController stdController) 
        this.comment = new CaseComment(ParentId = stdController.getId());

    public PageReference saveComment()
        insert comment;
        return null;
my visualforce page is:
<apex:page standardController="Case" extensions="Caselinktocomment" >
var returnurl;
window.onload = function(){
    returnURL = gup('retURL');
    alert('set retURL = ' + returnURL);
    function gup(name) { //this function just grabs http params by name
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
    var regex5 = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS ); 
    var results = regex.exec( window.location.href );
    if( results == null )    return ""; 
    else    return results[1];}
    function redirectBack(){
//alert('Sending you back to ' + returnURL);
window.location.href = '/' + returnURL;

    <apex:form >
    <apex:actionFunction name="saveActionFunc" action="{!Save}" oncomplete="redirectBack()" rerender="theBlock" />
        <apex:pageblock title="2nd Line Escalation" >
            <apex:pageBlockSection >
                <apex:inputField value="{!Case.troubleshooting_completed__c}" required="true" />
             <apex:pageBlockSection rendered="true" >
                <apex:inputCheckbox value="{!Case.X2nd_Line_Support__c}" selected="true" />
                <apex:pageBlockSection >
                <apex:inputField value="{!Case.Reason_for_Escalation__c}" required="true" />
                <apex:pageBlockSection >
                <apex:inputTextarea value="{!Case.further_information__c}" cols="60" rows="10" />
            <apex:pageBlockSection rendered="true">
                <apex:inputTextarea value="{!Comment.CommentBody}"/>                
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="save" onClick="saveActionFunc();" />
                <apex:commandButton action="{!cancel}" value="cancel" onClick="saveActionFunc();" />
                <apex:commandButton action="{!saveComment}" value="Save Comment"/>
I have noticed that when I press Save comment it saves what is set in the field "Reason_for_Escalation__c" and when it is updated the comment is also updated. 

Ideally I would like to just have one save button that will add the comment and update the case fields.

I am unable to see why the save comment button is saving the wrong field and allowing the comment to be updated if the picklist is updated. If you know a way to set the vf save button to save all fields in one that would be great.

Any assistance would be appreciated. My knowledge isn't 100% with apex code. 
Peter CowenPeter Cowen
The issue with the ticket comments updating has been sorted. I had a flow running. The question now has anyone created a button that can save the ticket comment and the case fields in one go in the visualforce page?