0

I search to solve problem with access to JS var(Object). I use Select2 lib on my Visualforce component wheare i get acsess to data from Salesforce objects( List of Emails and emails Id's) I use some code

<apex:component >
   <apex:attribute name="fieldValue" description="This is the value for the component." type="String"  required="true"/>
  <apex:attribute name="optionList" description="This is the value for the component." type="Mywrapper[]"  required="true"/>
  <apex:includeScript value="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js" />
  <apex:stylesheet value="{!URLFOR($Resource.Dropdown, 'dropdown/select2.css')}" />
  <apex:includeScript value="{!URLFOR($Resource.Dropdown, 'dropdown/select2.js')}" />


  <!-- Dropdown --> 
<select id='{!fieldValue+"selUser"}' style='width: 200px;'>
  <apex:repeat value="{!optionList}" var="option">
      <option value="{!option.value}">{!option.label}</option>
  </apex:repeat>
</select>
  <input type='button' value='Save'  id="{!fieldValue}but_read"/> 
<br/>
<div id='{"result"}'></div>
  <script>   

  var username;
  var userid;    

  $j = jQuery.noConflict();
  $j(document).ready(function(){ 
// Initialize select2
$j("#{!fieldValue}selUser").select2();
$j('#{!fieldValue}but_read').click(function(){
   username = $j('#{!fieldValue}selUser option:selected').text();
   userid = $j('#{!fieldValue}selUser').val();
  var myobj = {
value: userid,
label: username
};
console.log(username+' '+userid);
    console.log(myobj);
  $j('#{!fieldValue}result').html("id : " + userid + ", name : " + username);

});
});
  </script>

</apex:component>

I need some method for push "myobj" to Apex Class i get records but dont know how to push my change from dropdown picklist to Controller class. Maybe have some method with use JSON Deserialize for new result object?

6
  • 1
    Do you already have an Apex method that would potentially consume your myObj data? Commented Mar 19, 2020 at 14:15
  • I have a wrapper class wheare i have Strings named as value and label wheare name is email like a "[email protected]" and Label like a "Support Team" in Salesforce objects. After getting this values i put this data to object and upsert new record to Salesforce.
    – Oleh21
    Commented Mar 19, 2020 at 14:18
  • You may have to annotate your method as @RemoteAction and then call it this way developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/… Commented Mar 19, 2020 at 14:21
  • On example i see how get records and display it with JS but dont understand how to set data to Class.
    – Oleh21
    Commented Mar 19, 2020 at 14:25
  • Can you add your Apex method to your question Commented Mar 19, 2020 at 14:34

0

You must log in to answer this question.

Browse other questions tagged .