1

When I call the function from a button on a visualforce page using the controller I get

Unknown Property 'ContractDetails.save'

when I am trying to save the vfp.

Controller:

        public class ContractDetails{
            public Opportunity ThisOpportunity{get;set;}  
            public string oppid {get;set;}
            public ContractDetails(){
            oppid = ApexPages.currentPage().getParameters().get('id');
            if(oppid==null){
                            oppid = ApexPages.currentPage().getParameters().get('oppidd');
       }
            ThisOpportunity = [Select Contract_Requested__c FROM Opportunity where ID=:oppid];
       }
       public void save(){
                    ThisOpportunity.Contract_Requested__c = boolean.valueOf('True');
                    system.debug(ThisOpportunity.Contract_Requested__c);
                    update ThisOpportunity;
       }

Button on VFP:

<apex:page controller="ContractDetails"  showHeader="false" standardStylesheets="false" sidebar="false" docType="html-5.0" >
  <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <apex:slds />
  <script type="text/javascript">
            function requested(){
                    requestedoper();
                    }
  </script>
  <apex:form id="wf">
  <button class="slds-badge" style="{!requested}" onclick="requested()">Requested</button>
       <apex:actionfunction action="{!save}" name="requesteoper" rerender="wf"></apex:actionfunction></apex:form>
  </html>
  </apex:page>  
  • What you've shared so far isn't enough to identify the cause of your error with any degree of certainty. It sounds to me like you haven't set the controller or extensions attributes of <apex:page> properly, but I can't say for certain unless you share more of your code & visualforce markup. You don't need to share everything, but, at the minimum, seeing the first line(s) of your controller class (i.e. public class Something{) and the first line (<apex:page ...>) of your visualforce would be helpful. – Derek F Jun 30 '17 at 17:27
2

You cannot use onclick javascript function to call a Controller method. Better from onclick function, call javascript function, which in turn call controller method via actionFunction.

Approach 1

<button style="{!requested}" onclick="clickMe()">Requested</button>

<script>
    function clickMe()
    {
        saveOperation();
    }
</script>

<apex:actionFunction action="{!save}" name="saveOperation" rerender="form1"/>

Approach 2

Directly calling actionFunction also work.

<apex:actionFunction action="{!save}" name="saveOperation" rerender="form1"/>
<button onclick="saveOperation()">Requested</button>
  • 1
    D'oh, I saw that OP was using a plain 'ol HTML button, but glossed over that fact when OP was attempting to call an action method. The error the OP was seeing makes sense because in all but a few places, {!someIdentifier} tries to reference a property (with an automatic getter, or a method whose name is prefixed with 'get') rather than a 'plain' (action) method. +1 for you. – Derek F Jun 30 '17 at 17:33
  • OP is confused with property and method with this type of {!someIdentifier} – Santanu Boral Jun 30 '17 at 17:38
  • thanks that worked but I don't think it is calling the function at all, code is updated – AverageJoeVBA Jun 30 '17 at 17:44
  • are you getting debug messages in save operation? – Santanu Boral Jun 30 '17 at 17:49
  • nothing this is the result 13:50:49.0 (16419829)|METHOD_ENTRY|[1]|01p0S000000Di34|ContractDetails.ContractDetails() 13:50:49.0 (16426869)|STATEMENT_EXECUTE|[1] 13:50:49.0 (16431328)|STATEMENT_EXECUTE|[1] 13:50:49.0 (16436017)|METHOD_EXIT|[1]|ContractDetails 13:50:49.0 (16702261)|SYSTEM_MODE_ENTER|true 13:50:49.0 (16851241)|SYSTEM_MODE_ENTER|true – AverageJoeVBA Jun 30 '17 at 17:51

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.