• #54150
    Forcetalks

    How Can I Insert, Update the Account Records from Vf page using Remote actions..??

    How Can I Insert, Update the Account Records(using  custom controller class) from Vf page using Remote actions..??

     

    Thanks in advance

     

    #56118
    Salesforce | Jade Jade #10
    Forcetalks

    Hi Mallesh,

    Definitely you can Update and Insert Account or any object Record using JavaScript Remoting.

    check the below code:

    //This is a javaScript Remoting function, you can use it to update/Insert Account
    <script type="text/javascript">
    function getRemoteAccount() {
        var account = {!accRec}; //Initialize an account in your controller like, Account accRec{get;set;}
        //Then set the values of this from your page
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.MyController.updateAccount}', 
            accRec, 
            function(result, event){
                if (event.status) {
                    //Even account get updated, you will get the values in "result"
                } else if (event.type === 'exception') {
                    document.getElementById("responseErrors").innerHTML = event.message;
                } else {
                    document.getElementById("responseErrors").innerHTML = event.message;
                }
            }, 
            {escape: true}
        );
    }
    </script>
    
    Apex:
    
    In apex you can have this method.
    
    @RemoteAction
    Public Static void updateAccount(Account acc){
        if(acc != null){
           try{
               update acc;
           }catch(DMLException de){
               System.debug('DML Exception');
           }
        }
    }
    
    Hope this will be helpful!!!
    
    Thanks
Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?