0

I have a javascript function that alerts the user if fields are not filled in. If they are all filled in then it saves. I am getting an error with using "{!Save}" in my javascript.

Unknown property 'AccountStandardController.Save'

if(status = 'Final'){
                if(GHCountry = '' ||
                  GHCity = '' ||
                  USHState = '' ||
                  USHCity = '' ||
                  OwnershipType = '' ||
                  MaaActivity = '' ||
                  OwnershipStage = '' ||
                  vision = '' ||
                  mission = '' ||
                  values = '' ||
                  marketShare = '' ||
                  marketCap = '' ||
                  sharePrice = '' ||
                  sales = '' ||
                  sharePriceDate = '' ||
                  weekChange = '' ||
                  strategy = '' ||
                  priority1 = '' ||
                  forwardLookingObjective = '' ||
                  pyResults = '' ||
                  priority1 = '' ||
                  priority2 = '' ||
                  plannedActivities = '' ||
                  priority4 = '' ||
                  priority5 = '' ||
                  initiatives = '' ||
                  status = ''){
                    alert('All fields must be filled when Account Plan is Final');
                   }else{
                       //save
                       '{!Save}';
                   }
            }else{
                //save
                '{!Save}';
            }

How can I save the record via javascript?

  • The JavaScript is in a button or a vf page? – manjit5190 Dec 28 '16 at 4:17
1

You have to use <apex:actionFunction to call a method in Apex from javascript. Please find the below example on how to implement it.

<apex:page controller="t">
<script>
    function myJavascriptFunc(){
        alert('Entered Javascript') ;
        CallApexMethod() ;
    }
</script>
<apex:form >
<apex:actionFunction name="CallApexMethod" action="{!myActionInController}" onComplete="alert('After apex method') ;"/>
  <apex:pageBlock >
        <apex:pageBlockButtons>
            <apex:commandButton value="Hit Me" onclick="myJavascriptFunc() ;"/>
        </apex:pageBlockButtons>
  </apex:pageBlock>
</apex:form>
</apex:page>

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.