1

i have a JavaScript array and i want to send it as an argument to a remote method using javascript remoting , here is the javascript array:

  var quizQuestions  = [
    {
            type: "multiple",
            text: "Quelles sont les sanctions pour lesquels un entretien préalable est obligatoire ?",
            possibilities: [
            {
                correctAnswer:0,
                questionMultiple:"Rupture anticipée pour faute grave",
                possibilities: [
                {
                    answer: "Oui"
                },
                {
                    answer: "Non"
                }
                ],
            selected: null,
            correct: null
            },
            {
                correctAnswer:1,
                questionMultiple:"Avertissement",
                possibilities: [
                {
                    answer: "Oui"
                },
                {
                    answer: "Non"
                }
                ],
            selected: null,
            correct: null
            },
                {
                correctAnswer:0,
                questionMultiple:"Mise à pied disciplinaire",
                possibilities: [
                {
                    answer: "Oui"
                },
                {
                    answer: "Non"
                }
                ],
            selected: null,
            correct: null
            }
            ],
            selected: null,
        },


        {
            type: "multiple",
            text: "Pour chaque type de visite médicale, préciser les délais de passage des visites :",
            possibilities: [
            {
                correctAnswer:0,
                questionMultiple:"Embauche",
                possibilities: [
                {
                    answer: "avant la fin de la période d'essai"
                },
                {
                    answer: "dans les 8 premiers jours"
                },
                {
                    answer: "avant la prise de poste"
                }
                ],
            selected: null,
            correct: null
            },
            {
                correctAnswer:1,
                questionMultiple:"Après une absence d’au moins 30 jours pour cause d’accident du travail,de maladie",
                possibilities: [
                {
                    answer: "avant la fin de la période d'essai"
                },
                {
                    answer: "dans les 8 premiers jours"
                },
                {
                    answer: "avant la prise de poste"
                }
                ],
            selected: null,
            correct: null
            },
                {
                correctAnswer:2,
                questionMultiple:"Surveillance médicale des travailleurs handicapés",
                possibilities: [
                {
                    answer: "avant la fin de la période d'essai"
                },
                {
                    answer: "dans les 8 premiers jours"
                },
                {
                    answer: "avant la prise de poste"
                }
                ],
            selected: null,
            correct: null
            }
            ],
            selected: null,
        }
]

is it possible to send it as an argument ? and if yes how to handle it in the remoting method in the controller ?

thank you

0

You can consider parse it as a JSON string and send it as a string parameter to server. And at the server side, you can deserialize it via Apex. You need to define a custom wrapper class to hold the value.

Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm

  • can you explain more please i am new to salesforce and did not catch all what you have said – Merabti Ibrahim Apr 24 '16 at 13:13
  • @MerabtiIbrahim Are you new to programming as well? – Lance Shi Apr 24 '16 at 13:15
  • No really i am doing oriented object programming for while . did you mean that i an pass it directly like that ' Visualforce.remoting.Manager.invokeAction( 'ApexRemoteActionPageController.myContacts', quizQuestions, function(result, event){ } ' as an argument – Merabti Ibrahim Apr 24 '16 at 13:17
  • @MerabtiIbrahim It would be easy then. Take a look at developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… . You need to stringify the object as a string and pass that string as a parameter. And in your apex class. You can deserialize that string into an array of custom objects – Lance Shi Apr 24 '16 at 13:19

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.