+ Start a Discussion
TanDTanD 

My apex class is working as desired, but when I convert it to an extension (as my visualforce page has already a custom controller), it is not working.

My apex class is working as desired, but when I convert it to an extension (as my visualforce page has already a custom controller), it is not working.
I have a RemoteAction written in a Apex class which performs auto complete lookup fields. DId I miss anything in save_custom button of custom controller, or the syntax of Controller Extension for custom controller? Why the same code working good as controller, but not as extension? 
public class ExtensionAutocomplete {
    public General_Ledge_Account__c wildCardForGeneralLedgerAccount {get; set;}
    public General_Ledge_Account__c selected {get; set;}
    public Tax_Code__c wildCardForTaxCode {get; set;}
    public Tax_Code__c selectedTC {get; set;}
    public Journal__c wildCardForJournal {get; set;}
    public Journal__c selectedJ {get; set;}    
    public Dimension__c wildCardForDimension {get; set;}
    public Dimension__c selectedD {get; set;}  
    
	// Constructor for extension of custom controller 
	// 
    public ExtensionAutocomplete(JournalDetail_Controller_2T ctrlParam) {    // JournalDetail_Controller_2T is the controller for the VF page 
    }
    // JavaScript Remoting Action call 
    @RemoteAction
    public static List<General_Ledge_Account__c> lookupSearch(String wildCardForGeneralLedgerAccount) {
        System.debug('lookup: '+wildCardForGeneralLedgerAccount );
        List<General_Ledge_Account__c> master = Database.query('Select Id, Name from General_Ledge_Account__c where Name like \'%' + String.escapeSingleQuotes(wildCardForGeneralLedgerAccount) + '%\'');
        return master;
    }

Custom Controller: 
public with sharing class JournalDetail_Controller_2T  {
    // MVC concept to data binding in VF page & controller
    public Journal__c objectJournal{get; set;}
    public Line_Item__c objectLineItem{get; set;}
        
    //define the constructor 
      public JournalDetail_Controller_2T(ApexPages.StandardController stdController) {}

    public JournalDetail_Controller_2T(){
        // Initiate objects 
        objectJournal = new Journal__c();
        objectLineItem = new Line_Item__c();
    }
    public void save_custom()
    {
        try
        {
            insert objectJournal;
            insert objectLineItem;
        }   
        catch(Exception ex)
        {
            System.debug('\n\nException ='+ex.getMessage()+'\n\n');
        }    
    }
    public void cancel(){}  
    
       }

VF
 
<apex:page id="page" Controller="JournalDetailController_T"  sidebar="false" showHeader="false" standardStylesheets="false" >
    <apex:form id="form" >
        <html id="html">
            <head id="head">
                
                <style>
                    *{
                    <!-- font-size: 1.2vw;           viewport sized typography -->
                    }
                    html{
                    background-color: #E7EDF3;
                    }
                    body{ 
                    margin: 1rem; background-color: white;
                    }    
                    h3{
                    clear:both; background-color: #5B5DFE; width: 95%; padding-left: 1rem; color: white; margin: 2% 2.5% 1% 2.5%;
                    }
                    #div-table-1, #journal-status-left{
                    float: left; width: 45%; margin-left: 5%;
                    }
                    #div-table-2{
                    
                    }
                    #journal-detail-table-1{
                    
                    }
                    #journal-detail-table-2{
                    
                    }
                    #line-item-table{
                    margin-left: 5%;
                    }
                    #accordion3{
                    padding-bottom: 3%;
                    }
                    .lookupInput
                    {
                    display: inline;
                    vertical-align: middle;
                    white-space: nowrap;
                    }
                    .lookupInput img
                    {
                    background-repeat: no-repeat;
                    margin-right: .25em;
                    vertical-align: middle;
                    }
                    .lookupInput .disabled
                    {
                    background-color: #ccc;
                    }
                    .lookupInput .emptyDependentLookup
                    {
                    font-style: italic;
                    }
                    .lookupInput input[readonly]
                    {
                    background-color: #e6e6e6;
                    border: 2px solid #e6e6e6;
                    color: #333;
                    cursor: default;
                    }
                    .lookupInput a.readOnly
                    {
                    float: right;
                    }
                    .lookupInput span.readOnly
                    {
                    display: block;
                    white-space: normal;
                    }
                    .lookupInput span.totalSummary
                    {
                    font-weight: bold;
                    }
                    .inlineEditRequiredDiv .lookupInput img,.inlineEditDiv .lookupInput img
                    {
                    vertical-align: middle;
                    }
                    .quickCreateModule .lookupInput input {
                    max-width: 155px
                    }
                    .lookupIcon {
                    background-image: url(/img/func_icons/util/lookup20.gif);
                    background-position: 0 0;
                    width: 20px;
                    height: 20px;
                    background-position: top left
                    }
                    .lookupIconOn {
                    background-image: url(/img/func_icons/util/lookup20.gif);
                    background-position: 0 0;
                    width: 20px;
                    height: 20px;
                    background-position: top right
                    }
                </style>    
                <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
                <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
                <apex:includeScript value="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular.min.js"/>
                <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
                <script>
                $(function() { $("#accordion1").accordion({ header: "h3", collapsible: true }); });
                $(function() { $("#accordion2").accordion({ header: "h3", collapsible: true }); });
                $(function() { $("#accordion3").accordion({ header: "h3", collapsible: true }); });
                </script>
            </head>
            
            
            <body id="body" >
                <div>
                    <b> <span style="margin: 0 5% 0 5%; font-size:1.5rem">Journal Detail </span> </b>
                    
                    <apex:commandButton action="{!save_custom}" value="Post" style="background-color:#5B5DFE; color:white;font-weight: bold;  padding: .5rem 2rem .5rem 2rem; margin: 3rem 1rem 1rem 0; " />
                    <apex:commandButton action="{!cancel}" value="Cancel" style="background-color:#5B5DFE; color:white;font-weight: bold;  padding: .5rem 2rem .5rem 2rem; margin: 3rem 1rem 1rem 0; " />
                </div>
                <div class="journal-detail" id="accordion1" >
                    <h3>
                        Journal Detail
                    </h3>
                    <div>
                        <div id="div-table-1">
                            <table id="journal-detail-table-1" border="1" >
                                <apex:pageBlock >
                                    <apex:pageBlockSection >
                                        <tr>  
                                            <apex:inputField value="{!objectJournal.Type__c}"  /> </tr> <tr>
                                        <apex:inputField value="{!objectJournal.Journal_Date__c}" /> </tr><tr>
                                        <apex:inputField value="{!objectJournal.Journal_Currency__c}" /> </tr> <tr>
                                        <apex:inputField value="{!objectJournal.Reference__c}" /> </tr> <tr>
                                        <apex:inputField value="{!objectJournal.Journal_Description__c}"  /> </tr><tr>
                                        <apex:inputField value="{!objectJournal.Transaction__c}"  /> </tr> <tr>
                                        </tr>
                                    </apex:pageBlockSection>
                                </apex:pageBlock>
                            </table>
                        </div>
                        <div id="div-table-2">
                            <table  id="journal-detail-table-2" >
                                <apex:pageBlock >
                                    <apex:pageBlockSection >
                                        <tr><apex:outputField value="{!objectJournal.Name}" /> </tr> <tr> 
                                        <apex:inputField value="{!objectJournal.Period__c}"  /> </tr> <tr>
                                        <apex:inputField value="{!objectJournal.Debits__c}" /> </tr><tr>
                                        <apex:inputField value="{!objectJournal.Credits__c}"  />  </tr> <tr>
                                        <apex:inputField value="{!objectJournal.Invoice_Number__c}" /></tr><tr>
                                        <apex:inputField value="{!objectJournal.Total__c}" /> </tr>
                                    </apex:pageBlockSection>
                                </apex:pageBlock>
                            </table>
                        </div>
                    </div>
                </div>
                
                <div id="accordion2">
                    <h3 >
                        Journal Line Item
                    </h3>    
                   
				<div id="room-and-adding-room">
                	    <div id="field_wrapper_header_id" class="field_wrapper_header">
                                Line Type   	Line Description 		Journal			General Ledger Account	 	Amount 
                                Tax Code		Tax Amount 				Total Amount 	Dimension 

                    </div>
                    <div class="field_wrapper" style="border: dotted;" >
                        <div>      <apex:inputField value="{!objectLineItem.Line_Type__c}" style="width:3rem; float:left;"/> </div><div>
                        <apex:inputField value="{!objectLineItem.Line_Description__c}" style="width:5rem; float:left;"/> </div><div>
                        <apex:inputField value="{!objectLineItem.Journal__c}" style="width:3rem; float:left;"/> </div><div>
                        <apex:inputField value="{!objectLineItem.General_Ledge_Account__c}" style="width:4rem; float:left;"/> </div><div>
                        <apex:inputField value="{!objectLineItem.Amount__c}" style="width:5rem;  float:left;"/> </div><div>
                        <apex:inputField value="{!objectLineItem.Tax_Code__c}" style="width:5rem; float:left;"/> </div><div>
                        <apex:outputText value="{!objectLineItem.Tax_Amount__c}" style="width:3rem; float:left;"/> </div><div>
                        <apex:outputText value="{!objectLineItem.Total_Amount__c}" style="width:3rem; float:left;"/> </div><div>
                        <apex:inputField value="{!objectLineItem.Dimension_1__c}" style="width:6rem; float:left;"/> </div> <br/>
                </div> 
                    
                </div> <!-- End of room-and-adding-room div -->
                    <a href="javascript:void(0);" class="add_button"  title="Add field" style="background-color: red; display:inline-block;" > Add Room </a>
                    
                <div id="accordion3">
                    <h3 >
                        Journal Status
                    </h3>    
                    <div>
                    <div id="journal-status-left">
                        Journal Status <apex:inputField value="{!objectJournal.Journal_Status__c}" />
                    </div>
                    <div>
                        Discard Reason <apex:inputField value="{!objectJournal.Discard_Reason__c}" />
                    </div>
                    </div>
                </div>
                <!-- Script to enable autocomplete functionality -->

                    <apex:pageBlock id="searchBlock" >
                 <apex:outputLabel value="Search General Ledger Account" for="Box" />
                 <apex:outputPanel >
                     <apex:inputText id="TextBox" value="{!wildCardForGeneralLedgerAccount}" styleClass="General Ledger Account"/>
                     <apex:inputHidden id="searchId" value="{!selected}" /> <br/>
                 </apex:outputPanel>
                    
            <apex:outputLabel value="Search Tax Code" for="BoxTC" />
            <apex:outputPanel >
                     <apex:inputText id="TextBoxTC" value="{!wildCardForTaxCode}" styleClass="Tax code"/>
                <apex:inputHidden id="searchIdTC" value="{!selectedTC}" /> <br/>
            </apex:outputPanel>
           <apex:outputLabel value="Search Journal" for="BoxJ" />
            <apex:outputPanel >
                     <apex:inputText id="TextBoxJ" value="{!wildCardForJournal}" styleClass="wild card for Journal"/>
                <apex:inputHidden id="searchIdJ" value="{!selectedJ}" />  <br/>
                </apex:outputPanel>                                       
              <apex:outputLabel value="Search Dimension" for="BoxD" />
            <apex:outputPanel >
                     <apex:inputText id="TextBoxD" value="{!wildCardForDimension}" styleClass="wild card for Dimension"/>
                     <apex:inputHidden id="searchIdD" value="{!selectedD}" />    
                    </apex:outputPanel>
        </apex:pageBlock>
                </div>

    
                   	<!-- Script to add room -->
           <script type="text/javascript">
$(document).ready(function(){
    var maxField = 10; //Input fields increment limitation
    var addButton = $('.add_button'); //Add button selector
    var wrapper = $('.field_wrapper'); //Input field wrapper
    var fieldHTML = '<div><apex:inputField value="{!objectLineItem.Line_Type__c}" style="width:3rem; float:left;"/><apex:inputField value="{!objectLineItem.Line_Description__c}" style="width:5rem; float:left;"/><apex:inputField value="{!objectLineItem.Journal__c}" style="width:3rem; float:left;"/><apex:inputField value="{!objectLineItem.General_Ledge_Account__c}" style="width:4rem; float:left;"/><apex:inputField value="{!objectLineItem.Amount__c}" style="width:5rem;  float:left;"/><apex:inputField value="{!objectLineItem.Tax_Code__c}" style="width:5rem; float:left;"/><apex:outputText value="{!objectLineItem.Tax_Amount__c}" style="width:3rem; float:left;"/><apex:outputText value="{!objectLineItem.Total_Amount__c}" style="width:3rem; float:left;"/><apex:inputField value="{!objectLineItem.Dimension_1__c}" style="width:6rem; float:left;"/><a href="javascript:void(0);" class="remove_button" title="Remove field">Remove</a></div>';
    var x = 1; //Initial field counter is 1
    $(addButton).click(function(){ //Once add button is clicked
        if(x < maxField){ //Check maximum number of input fields
            x++; //Increment field counter
            $(wrapper).append(fieldHTML); // Add field html
        }
    });
    $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
        e.preventDefault();
        $(this).parent('div').remove(); //Remove field html
        x--; //Decrement field counter
    });
});
</script>
    
    <script type="text/javascript">
    // A FOR LOOP will be added soon to optimize the length of the code
    // for id = [TextBox, TextBoxTC, TextBoxJ, TextBoxD]   searchID  $('[id$=id]')
    //------------------------------------GLA--------------------------
        var PLACEHOLDER = ''; 
        var masterObjects;
        var queryTerm;
        
        $('[id$=TextBox]').autocomplete({
            minLength: 0,
            source: function(request, response) {
                        queryTerm = request.term;
                        AutoCompleteLookupField.lookupSearch(request.term, function(result, event)  {
                            if(event.type == 'exception') {
                                  alert(event.message);
                            } else {
                                 masterObjects = result;
                                 response(masterObjects);
                            }
                        });
                   },
            focus: function( event, ui ) {
                    $('[id$=TextBox]').val( ui.item.Name );
                    return false;
                    },
            select: function( event, ui ) {
                        $('[id$=TextBox]').val( ui.item.Name );
                        $('[id$=searchId]').val( ui.item.Id );
                        return false;
                    },
         })
         .data( "autocomplete" )._renderItem = function( ul, item ) {
            var entry = "<a>" + item.Name;
           
            entry = entry + "</a>";
            entry = entry.replace(queryTerm, "<b>" + queryTerm + "</b>");
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( entry )
                .appendTo( ul );
        };
            
        // Add or remove placeholder values
        $('[id$=TextBox]').val(PLACEHOLDER);
        $('[id$=TextBox]').on("focus",  function(event){
            $tgt = $(event.target);
            if($tgt.val() === PLACEHOLDER ){
                $tgt.val('');
                $tgt.removeClass('placeHolder');
            }
        });
        $('[id$=TextBox]').on( "blur",  function(event){
            $tgt = $(event.target);
            if($tgt.val() === '' ){
                $tgt.val(PLACEHOLDER);
                $tgt.addClass('placeHolder');
            }
        });

    // ----------------------------------TC-----------------------
            var PLACEHOLDER = ''; 
        var masterObjectsTC;
        var queryTerm;
        $('[id$=TextBoxTC]').autocomplete({
            minLength: 0,
            source: function(request, response) {
                        queryTerm = request.term;
                        AutoCompleteLookupField.lookupSearchTC(request.term, function(result, event)  {
                            if(event.type == 'exception') {
                                  alert(event.message);
                            } else {
                                 masterObjectsTC = result;
                                 response(masterObjectsTC);
                            }
                        });
                   },
            focus: function( event, ui ) {
                    $('[id$=TextBoxTC]').val( ui.item.Name );
                    return false;
                    },
            select: function( event, ui ) {
                        $('[id$=TextBoxTC]').val( ui.item.Name );
                        $('[id$=searchIdTC]').val( ui.item.Id );
                        return false;
                    },
         })
         .data( "autocomplete" )._renderItem = function( ul, item ) {
            var entry = "<a>" + item.Name;
           
            entry = entry + "</a>";
            entry = entry.replace(queryTerm, "<b>" + queryTerm + "</b>");
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( entry )
                .appendTo( ul );
        };
            
        // Add or remove placeholder values
        $('[id$=TextBoxTC]').val(PLACEHOLDER);
        $('[id$=TextBoxTC]').on("focus",  function(event){
            $tgt = $(event.target);
            if($tgt.val() === PLACEHOLDER ){
                $tgt.val('');
                $tgt.removeClass('placeHolder');
            }
        });
        $('[id$=TextBoxTC]').on( "blur",  function(event){
            $tgt = $(event.target);
            if($tgt.val() === '' ){
                $tgt.val(PLACEHOLDER);
                $tgt.addClass('placeHolder');
            }
        });

    // -----------------------------------------------------====================Journal
       var PLACEHOLDER = ''; 
        var masterObjectsJ;
        var queryTerm;
        $('[id$=TextBoxJ]').autocomplete({
            minLength: 0,
            source: function(request, response) {
                        queryTerm = request.term;
                        AutoCompleteLookupField.lookupSearchJ(request.term, function(result, event)  {
                            if(event.type == 'exception') {
                                  alert(event.message);
                            } else {
                                 masterObjectsJ = result;
                                 response(masterObjectsJ);
                            }
                        });
                   },
            focus: function( event, ui ) {
                    $('[id$=TextBoxJ]').val( ui.item.Name );
                    return false;
                    },
            select: function( event, ui ) {
                        $('[id$=TextBoxJ]').val( ui.item.Name );
                        $('[id$=searchIdJ]').val( ui.item.Id );
                        return false;
                    },
         })
         .data( "autocomplete" )._renderItem = function( ul, item ) {
            var entry = "<a>" + item.Name;
           
            entry = entry + "</a>";
            entry = entry.replace(queryTerm, "<b>" + queryTerm + "</b>");
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( entry )
                .appendTo( ul );
        };
            
        // Add or remove placeholder values
        $('[id$=TextBoxJ]').val(PLACEHOLDER);
        $('[id$=TextBoxJ]').on("focus",  function(event){
            $tgt = $(event.target);
            if($tgt.val() === PLACEHOLDER ){
                $tgt.val('');
                $tgt.removeClass('placeHolder');
            }
        });
        $('[id$=TextBoxJ]').on( "blur",  function(event){
            $tgt = $(event.target);
            if($tgt.val() === '' ){
                $tgt.val(PLACEHOLDER);
                $tgt.addClass('placeHolder');
            }
        });

    // -----------------=============================---------------________________ Dimension
       var PLACEHOLDER = ''; 
        var masterObjectsD;
        var queryTerm;
        $('[id$=TextBoxD]').autocomplete({
            minLength: 0,
            source: function(request, response) {
                        queryTerm = request.term;
                        AutoCompleteLookupField.lookupSearchD(request.term, function(result, event)  {
                            if(event.type == 'exception') {
                                  alert(event.message);
                            } else {
                                 masterObjectsD = result;
                                 response(masterObjectsD);
                            }
                        });
                   },
            focus: function( event, ui ) {
                    $('[id$=TextBoxD]').val( ui.item.Name );
                    return false;
                    },
            select: function( event, ui ) {
                        $('[id$=TextBoxD]').val( ui.item.Name );
                        $('[id$=searchIdD]').val( ui.item.Id );
                        return false;
                    },
         })
         .data( "autocomplete" )._renderItem = function( ul, item ) {
            var entry = "<a>" + item.Name;
           
            entry = entry + "</a>";
            entry = entry.replace(queryTerm, "<b>" + queryTerm + "</b>");
            return $( "<li></li>" )
                .data( "item.autocomplete", item )
                .append( entry )
                .appendTo( ul );
        };
            
        // Add or remove placeholder values
        $('[id$=TextBoxD]').val(PLACEHOLDER);
        $('[id$=TextBoxD]').on("focus",  function(event){
            $tgt = $(event.target);
            if($tgt.val() === PLACEHOLDER ){
                $tgt.val('');
                $tgt.removeClass('placeHolder');
            }
        });
        $('[id$=TextBoxD]').on( "blur",  function(event){
            $tgt = $(event.target);
            if($tgt.val() === '' ){
                $tgt.val(PLACEHOLDER);
                $tgt.addClass('placeHolder');
            }
        });

    </script>
                            </body>
        </html>
    </apex:form>
</apex:page>

 
Jim JamJim Jam
On your vf page the controller name is missing an underscore...JournalDetail_Controller, also where have you got extensions=ExtensionAutocomplete ?
 
TanDTanD

I have written the ExtensionAutocomplete extension to add few fields from other objects. 

My SF org VF page has correct controller name (no typo), still not working.