function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JamesSSJamesSS 

How to use datastructure in following method?

I have written following javascript function for some processing.

 

In js method have more than 15 parameters to pass to Controller using Saveaccount actionFunction.

<apex:actionFunction name="Saveaccount" action="{!createSavedSearch}" ">

<apex:param assignTo="{!text1}" value=""/>

.

.

.

.

.

.

<apex:param assignTo="{!text15}" value=""/>

 </apex:actionFunction>  

 

function save(){

 

Saveaccount($('.text1').html().replace('%',''),$('.text2').html().replace('%',''),$('.text3').html().replace(/[^\d]/g,''),$('.text4').html().replace(/[^\d]/g,''),
$('.text5').html().replace('x',''),$('.text6').html().replace('x',''), $('.text7').html(),$('.text8').html(),$('.text9').html().replace('%',''),
$('.text10').html().replace('%',''),$('.text11').html(),$('.text12').html(),$('.text13').html(),$('.text14').html(),$('#text15').val()
);

 

}

 

 

How to use  data structure - a map (hash), a JS object, or a custom class in above save method?

How  to improve this action function and it's associated JS and Apex code, calling it with one parameter?

Best Answer chosen by Admin (Salesforce Developers) 
kreshokresho

Hi,

 

Try grouping the parameters of the method in an apex class:

public void saveAccount(Wrapper w) {...}

public class Wrapper {
    public String text1;
    public String text2;
    public String text3;
    ...
}

 And in JavaScript populate a dictionary with the wrapper fields:

var param = {
    text1: $('.text1').html().replace('%',''),
    text2: $('.text2').html().replace('%',''),
    ...
};
saveAccount(param);

Regards,
Kresimir
Apex Editor LS - free alternative to Force.com apex editor.
Give kudos (click blue star under my icon) if this was useful