0

This is my use case

1) I have a read only visualforce page and on which there is a button "Clone"enter image description here

2) Upon clicking "Clone" you will be shown an edit page (editable version of the same record) as shown belowenter image description here

3) When I click on "Save" a new FactFind__c record will be created with the changes (eg :First Name changed from "434ds" to "XGXG") from the previous step enter image description here

4) For some reason it is not happening for me. I digged around and found that new record creation is indeed happening (a new FactFind__c) record is getting created but with the old values of "ff".enter image description here

I confirmed with the debug log.

enter image description here

As seen from the debug log below the first name is still being retained in the controller variable (ff.First_Name__c) as "434ds" instead of "XGXG"

Can someone tell me whats going wrong ?

This is my Visualforce code

<apex:page docType="html-5.0" standardController="FactFind__c" extensions="FactFindPageController" tabStyle="FactFind__c">


    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <apex:stylesheet value="{!URLFOR($Resource.LightningDesignSystemMin)}"/>
    <apex:includeScript value="{!$Resource.cbpFWTabs}"/>
    <apex:includeScript value="{!$Resource.modernizr}"/>  

     <style type="text/css"> 
         .factfind{
            font-size:13px;
        }

        .factfind td{
            width:50%;
            text-align:right;
            position:relative;
            right:28%;
            padding-top:1%;
        }
        p.groove 
        {
        border-style: groove;
        color : red;
        }
    </style>



  <div class="slds-page-header">
        <div class="slds-col slds-has-flexi-truncate">
            <p class="slds-text-heading--label">Fact Find</p>
            <div class="slds-grid">
                <div class="slds-grid slds-type-focus slds-no-space">
                    <h1 class="slds-text-heading--medium slds-truncate" title="Service Enquiry">{!ff.Name}</h1>
                </div>
            </div>
        </div>
    </div><br/>  
<apex:messages />
    <apex:form id="form">
     <apex:actionFunction id="addRow" name="addRow" action="{!addNewRow}" rerender="income_expense_section" immediate="true"/>
        <apex:actionFunction id="invoke_edit" name="invoke_edit" action="{!invoke_edit_mode}" rerender="form" immediate="true"/>
    <apex:actionFunction id="customcancel" name="custom_cancel" action="{!customcancel}" rerender="form" immediate="true"/>
        <apex:actionFunction id="customsave" name="saveFactFind" action="{!saveFactFind}" rerender="form" immediate="true"/>



<apex:outputPanel id="read_only_section" rendered="{!NOT(is_edit)}">
    <apex:panelGrid id="factfind_section1" columns="2" styleClass="factfind">
                                    <apex:panelGroup >
                                        <apex:outputText value="First Name:" styleClass="label"/>
                                        <apex:outputField id="ff_firstname" value="{!ff.First_Name__c}" styleClass="input"/>                                    
                                    </apex:panelGroup>
                                    <apex:panelGroup >
                                        <apex:outputText value="Last Name:" styleClass="label"/>
                                        <apex:outputField id="ff_lastname" value="{!ff.Last_Name__c}" styleClass="input"/>                                    
                                    </apex:panelGroup>
                                    <apex:panelGroup >
                                        <apex:outputText value="Title:" styleClass="label"/>
                                        <apex:outputField id="ff_title" value="{!ff.Title__c}" styleClass="input"/>                                    
                                    </apex:panelGroup>
                                    <apex:panelGroup >
                                        <apex:outputText value="Dependents:" styleClass="label"/>
                                        <apex:outputField id="ff_dependents" value="{!ff.Dependents__c}" styleClass="input"/>                                    
                                    </apex:panelGroup>                                                                        
                                </apex:panelGrid><br/>


          <apex:outputPanel id="income_expense_section1">
                                    <table id="tbl_id" border="0" class="table">
                                        <tr>

                                            <td><span class="title">Income/Expense</span></td>
                                            <td><span class="title">Type</span></td>
                                            <td><span class="title">Frequency</span></td>
                                            <td><span class="title">Amount</span></td>
                                        </tr>                                    
                                        <apex:variable value="{!0}" var="rowNum" />
                                        <apex:repeat id="income_expense1" value="{!IncExpList}" var="er">
                                            <tr>

                                                <td><apex:outputField id="i_ie" value="{!er.record.Income_Expense__c}" rendered="{! (!er.to_del) }"  /></td>
                                                <td><apex:outputField id="i_t" value="{!er.record.Type__c}" rendered="{! (!er.to_del) }" /></td>
                                                <td><apex:outputField id="i_f" value="{!er.record.Frequency__c}" rendered="{! (!er.to_del) }"  /></td>
                                                <td><apex:outputField id="i_a" value="{!er.record.Amount__c}" rendered="{! (!er.to_del) }"  /></td>
                                            </tr>
                                        </apex:repeat>


                                    </table>
                                </apex:outputPanel>
                                                                                           <input type="button" id="clone_ff" onclick="invoke_edit()" value="Clone"  class="slds-button slds-button--neutral" style="color:#333333; font-family:Arial; font-size:15px; width:200px; position:relative; left:30%;" rendered="{!NOT(is_edit)}"/>



</apex:outputPanel>



<apex:outputPanel id="edit_section"  rendered="{!is_edit}">

<apex:panelGrid id="factfind_section2" columns="2" styleClass="factfind">
                                    <apex:panelGroup >
                                        <apex:outputText value="First Name:" styleClass="label"/>
                                        <apex:inputField id="ff_firstname1" value="{!ff.First_Name__c}" styleClass="input"/>                                    
                                    </apex:panelGroup>
                                    <apex:panelGroup >
                                        <apex:outputText value="Last Name:" styleClass="label"/>
                                        <apex:inputField id="ff_lastname1" value="{!ff.Last_Name__c}" styleClass="input"/>                                    
                                    </apex:panelGroup>
                                    <apex:panelGroup >
                                        <apex:outputText value="Title:" styleClass="label"/>
                                        <apex:inputField id="ff_title1" value="{!ff.Title__c}" styleClass="input"/>                                    
                                    </apex:panelGroup>
                                    <apex:panelGroup >
                                        <apex:outputText value="Dependents:" styleClass="label"/>
                                        <apex:inputField id="ff_dependents1" value="{!ff.Dependents__c}" styleClass="input"/>                                    
                                    </apex:panelGroup>                                                                        
                                </apex:panelGrid><br/>


          <apex:outputPanel id="income_expense_section2">
                                    <table id="tbl_id" border="0" class="table">
                                        <tr>
                                            <td><span class="title">Action</span></td>
                                            <td><span class="title">Income/Expense</span></td>
                                            <td><span class="title">Type</span></td>
                                            <td><span class="title">Frequency</span></td>
                                            <td><span class="title">Amount</span></td>
                                        </tr>                                    
                                        <apex:variable value="{!0}" var="rowNum" />
                                        <apex:repeat id="income_expense" value="{!IncExpList}" var="er">
                                            <tr>
                                                <td>
                                                    <apex:commandLink id="id_cl" value="Remove" style="color:#A72727" action="{!removeRow}" rendered="{! (!er.to_del) }" rerender="income_expense_section" immediate="true">
                                                        <apex:param value="{!rowNum}" name="rowToRemove" assignTo="{!rowToRemove}"/>
                                                    </apex:commandLink>
                                                    <apex:variable var="rowNum" value="{!rowNum +1}"/>
                                                </td>
                                                <td><apex:inputField id="i_ie1" value="{!er.record.Income_Expense__c}" rendered="{! (!er.to_del) }" required="true" /></td>
                                                <td><apex:inputField id="i_t1" value="{!er.record.Type__c}" rendered="{! (!er.to_del) }" required="true" /></td>
                                                <td><apex:inputField id="i_f1" value="{!er.record.Frequency__c}" rendered="{! (!er.to_del) }" required="true" /></td>
                                                <td><apex:inputField id="i_a1" value="{!er.record.Amount__c}" rendered="{! (!er.to_del) }" required="true" /></td>
                                            </tr>
                                        </apex:repeat>

                                        <tr>
                                            <td colspan="5">
                                                <input type="button" id="add_row" value="Add Row" onclick="addRow()" class="slds-button slds-button--neutral" style="color:#333333; font-family:Arial; font-size:15px; width:200px; position:relative; left:30%;"/>
                                                <input type="button" id="btn_save" value="Save" onclick="saveFactFind()" class="slds-button slds-button--neutral" style="color:#333333; font-family:Arial; font-size:15px; width:200px; position:relative; left:30%;"/>                                            
<input type="button" id="btn_cancel" value="Cancel" onclick="custom_cancel()"  class="slds-button slds-button--neutral" style="color:#333333; font-family:Arial; font-size:15px; width:200px; position:relative; left:30%;"/> 
                                            </td>
                                        </tr>                                       
                                    </table>
                                </apex:outputPanel>



</apex:outputPanel>            



        </apex:form>


<script>

$(document).ready(function(){


//reset_state();

    function reset_state()
    {

       $("input[id*='ff_firstname']").prop('readonly', true);
        $("input[id*='ff_lastname']").prop('readonly', true);
        $("input[id*='ff_title']").prop('readonly', true);
        $("input[id*='ff_dependents']").prop('readonly', true);



        document.getElementById('j_id0:form:income_expense:0:i_ie').disabled = true;
        document.getElementById('j_id0:form:income_expense:0:i_f').disabled = true;



        $("input[id*='i_t']").prop('readonly', true);

        $("input[id*='i_a']").prop('readonly', true);



        $("#btn_save").hide();
        $("#btn_cancel").hide();
        $("#add_row").hide();
        $("#clone_ff").show();

        document.getElementById('j_id0:form:income_expense:0:id_cl').hidden = true;


    }

    function edit_state()
    {
        $("input[id*='ff_firstname']").prop('readonly', false);
        $("input[id*='ff_lastname']").prop('readonly', false);
        $("input[id*='ff_title']").prop('readonly', false);
        $("input[id*='ff_dependents']").prop('readonly', false);
        //$("#tbl_id").find("input").removeAttr("disabled");
        $("#clone_ff").hide();
        $("#btn_save").show();
        $("#btn_cancel").show();
        $("#add_row").show();

        document.getElementById('j_id0:form:income_expense:0:i_ie').disabled = false;
        document.getElementById('j_id0:form:income_expense:0:i_f').disabled = false;
        document.getElementById('j_id0:form:income_expense:0:id_cl').disabled = false;

        document.getElementById('j_id0:form:income_expense:0:id_cl').hidden = false;


        $("input[id*='i_t']").prop('readonly', false);

        $("input[id*='i_a']").prop('readonly', false);


    }

    $("#clone_ff").click(function(){

         // $("#clone_ff").hide();
    });

    $("#btn_cancel").click(function(){

          // reset_state();

    });
    $("#btn_save").click(function(){

          // reset_state();b

    });







});
</script>

</apex:page>

This is my controller code

public class FactFindPageController {

    public Boolean is_edit{get;set;}
    public FactFind__c ff{get;set;}
    public FactFind__c ffc{get;set;}
    public Boolean can_show{get;set;}
    public Boolean clone_action_buttons{get;set;}
    public List<WrapperIncomesExpensesList> IncExpList{get;set;}
     public Integer rowToRemove{get;set;}   
     public Boolean is_ies_empty{get;set;}

     public class WrapperIncomesExpensesList{
        public Integer index{get;set;}
        public IncomeExpenses__c record{get;set;}
        public Boolean to_del{get;set;}
    }

    public void init(String ffid)
    {
            //this.ff = (FactFind__c)stdController.getRecord(); 
        is_edit = false;

        IncExpList = new List<WrapperIncomesExpensesList>();
        can_show = true;
        clone_action_buttons = false;
        is_ies_empty = true;

         List<IncomeExpenses__c> ielist = [SELECT Id, Type__c,Income_Expense__c,Amount__c,Frequency__c FROM IncomeExpenses__c WHERE FactFind__c = :ffid];
          if(!ielist.isEmpty())
                            {
                               is_ies_empty = false;
                               Integer cnt = 0;
                               for(IncomeExpenses__c iet : ielist)
                               {
                                  WrapperIncomesExpensesList wi = new WrapperIncomesExpensesList();
                                  wi.record = iet;
                                  wi.index = cnt;
                                  wi.to_del = false;
                                  IncExpList.add(wi);
                                  cnt++;
                               }
                            }

    }

     public void addNewRow()
    {
       IncExpList = FactFindUIHelper.addNewRowsFF(IncExpList);

    }

    public void invoke_edit_mode()
    {
       System.debug('~~~ Method called');
       is_edit = true;
       System.debug('~~~ Value ='+is_edit);

    }

    public void revoke_edit_mode()
    {

      is_edit = false;
    }


    public void removeRow()
    {
       IncExpList = FactFindUIHelper.removeRowFF(rowToRemove,IncExpList);
    }

    public PageReference saveFactFind()
    {

        FactFind__c ffcl = new FactFind__c();
        ffcl.RecordTypeId = '01290000000ufb3AAA';
        System.debug('~~~ First Name '+ff.First_Name__c);
        ffcl.First_Name__c = ff.First_Name__c;
        ffcl.Last_Name__c = ff.Last_Name__c;
        ffcl.New_Tax_Deduct__c = ff.New_Tax_Deduct__c;
        ffcl.Existing_Tax_Deduct__c = ff.Existing_Tax_Deduct__c;
        ffcl.Title__c = ff.Title__c;
        ffcl.Dependents__c = ff.Dependents__c;
        ffcl.Account__c = ff.Account__c;

        insert ffcl;

        List<IncomeExpenses__c> lst = new List<IncomeExpenses__c>();
        List<IncomeExpenses__c> to_del_lst = new List<IncomeExpenses__c>();
        for(WrapperIncomesExpensesList w : IncExpList)
        {
           if(!w.to_del)
           {
               w.record.FactFind__c = ffcl.Id;
               lst.add(w.record);
           }
           else
           {
               if(w.record.Id != null)
               {
                   to_del_lst.add(w.record);
               }
           }
        }
        upsert lst;
        delete to_del_lst;

        //init(ffcl.Id);
        revoke_edit_mode();

        System.debug('~~~~ ffcl '+ffcl.Id);
        PageReference pr = new PageReference('/apex/FactFindBSPage?id='+ffcl.Id);
        pr.setRedirect(true);


        return pr;

    }


    public FactFind__c getFactFindData(String ffId)
    {

        FactFind__c ff1 = new FactFind__c();
        String queryStr = 'Select ' + CommonUsedClass.sObjectGetAllFields(ff1).trim() + ', Owner.FirstName, Owner.LastName From FactFind__c Where Id = : ffId';
        try{
           ff1 = Database.query(queryStr);     
        }
        catch(Exception e){
            system.debug('****** Querying Service Enquiry Exception: ' + e.getMessage()); 
        }
        return ff1;

    }



    public FactFindPageController (ApexPages.StandardController stdController)
    {
        ff = getFactFindData(stdController.getId());
        init(ff.Id);

    }

    public PageReference customClone()
    {

        //PageReference pr = new PageReference('/'+ff.Id+'/e?clone=1');
        //https://annestreetpartners--aspdev.cs5.my.salesforce.com/a2lO00000006Ut5/e?clone=1

        can_show = false;
        clone_action_buttons = true;
        return null;


    }



     public PageReference customcancel()
    {

        //PageReference pr = new PageReference('/'+ff.Id+'/e?clone=1');
        //https://annestreetpartners--aspdev.cs5.my.salesforce.com/a2lO00000006Ut5/e?clone=1
        System.debug('~~~ Cancel clicked');
        //can_show = true;
        //clone_action_buttons = false;
        init(ff.Id);
        revoke_edit_mode();
        PageReference pr = new PageReference('/apex/FactFindBSPage?id='+ff.Id);
        pr.setRedirect(true);
        return pr;


    }
}

Basically the "first name" changes are getting ignored.

I am aware that in my controller code I am referencing "ff" object (while saving the record) but I am making the changes in the UI which should have been now part of the "ff" object right ?.

Why my UI changes are not getting set at "ff" object ?

Hope I am clear.

Would appreciate any inputs on this.

0

One of 2 things can be happening there:

Either the Name field of the object is AutoNumber (change it to text if that's the case), or there is a trigger/workflow running on that object that changes the Name of the record (find it and disable it).

Also consider data integrity issue that may arise due to this change.

Edit:

After close look at the code I can see that in your header you're outputting the record Name and not First Name:

<h1 class="slds-text-heading--medium slds-truncate" title="Service Enquiry">{!ff.Name}</h1>

Given the format of the name, it suggests it's of type Auto Number.

| improve this answer | |
  • I should have been more clear...when I mentioned "Name"..I mean the "First Name" data and not the FactFind__c.Name..I am talking about "FactFind__c.First_Name__c"..I will update the question for clarity now. – Aaron Wilfred Jun 5 '17 at 0:59
  • Are there any triggers or workflows on FactFind__c? – Boris Bachovski Jun 5 '17 at 1:13
  • There are no triggers and workflows on FactFind__c – Aaron Wilfred Jun 5 '17 at 1:21
  • And what is the type of the First Name field on the object? (Setup -> Create Objects -> Fact Find -> First Name) – Boris Bachovski Jun 5 '17 at 1:23
  • It is a custom field (not a formula field) with data type text 100 – Aaron Wilfred Jun 5 '17 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.