+ Start a Discussion
John T.John T. 

Perform Insert in Jquery Mobile

Hi Guys,

 

Just want to know how to perform an Insert action in the Vf page using Jquery Mobile or how can you pass a parameter to the methods in your controller. What I did is a copy a text input value and use it as a parameter to pass into my method in which it uses the passed value to perform insert operation.

Best Answer chosen by Admin (Salesforce Developers) 
cwall_sfdccwall_sfdc

Right.  Visualforce Remoting is the way to go for execution on a mobile device.  JQ or JQM are not needed to perform back-end calls.

 

Example (untested):

--- controller ---

 

global class MyConroller {
    @RemoteAction
    global static Database.SaveResult insertMe(String toBeSaved) {
        Account newAcct = new Account();
        newAcct.name = toBeSaved;
        Database.SaveResult lsr = Database.insert(newAcct, false);    
        return lsr;
    }
}

 

 

 

--- page ---

 

<script>
    // bound this to an event, say onclick or onsubmit
    function insertMe() {
        // get params from DOM or pass via params
        MyConroller.insertMe(param, function(result, event) { /* handle result */})
    }
</script>

 

See http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm.

All Answers

joshbirkjoshbirk

Are you using JavaScript Remoting or ActionFunction?

cwall_sfdccwall_sfdc

Right.  Visualforce Remoting is the way to go for execution on a mobile device.  JQ or JQM are not needed to perform back-end calls.

 

Example (untested):

--- controller ---

 

global class MyConroller {
    @RemoteAction
    global static Database.SaveResult insertMe(String toBeSaved) {
        Account newAcct = new Account();
        newAcct.name = toBeSaved;
        Database.SaveResult lsr = Database.insert(newAcct, false);    
        return lsr;
    }
}

 

 

 

--- page ---

 

<script>
    // bound this to an event, say onclick or onsubmit
    function insertMe() {
        // get params from DOM or pass via params
        MyConroller.insertMe(param, function(result, event) { /* handle result */})
    }
</script>

 

See http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm.

This was selected as the best answer
John T.John T.

Thanks man, really appreciate it. I'm excited to try it then.