• David9133
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Passing the values from the visualforce page as JSON string and Assigning the values, Need the help in test class how to pass the JSON string to the test class as i am getting Null Pointer exception while saving the Method.

<apex:page controller="skillproficiencycontroller" id="p"> <apex:form id="f"> <script> var state = {}; function passState() { document.getElementById("p:f:hiddenField").value = JSON.stringify(state); passStateToController(); } function myFunction( value, id) { state[id] = value; console.log(state); } </script> <apex:inputHidden value="{!hidden}" id="hiddenField"/> <apex:pageBlock > <apex:pageblockTable value="{!skilllist}" var="s"> <apex:column value="{!s.Name}"/> <apex:column headerValue="Proficiency"> <apex:selectRadio value="{!Selected}" onclick="myFunction(this.value,'{!s.id}');"> <apex:selectOptions value="{!items}" /> </apex:selectRadio> </apex:column> </apex:pageblockTable> <apex:pageBlockButtons location="bottom"> <apex:commandButton onclick="passState(); return false;" value="Save" /> <apex:actionFunction name="passStateToController" action="{!Save}" reRender="hiddenField" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>


public void Save() { List<Skill_Details__c >skilldetailslist = new List<Skill_Details__c >(); JSONParser parser = JSON.createParser(hidden); while (parser.nextToken() != null) { if (parser.getCurrentToken() != JSONToken.START_OBJECT && parser.getCurrentToken() != JSONToken.END_OBJECT){ Skill_Details__c sd = new Skill_Details__c(); sd.Skill__c = id.valueOf(parser.getText()); parser.nextToken(); sd.Proficiency__c = parser.getText(); skilldetailslist.add(sd); } } //system.debug(skilldetailslist); Insert skilldetailslist; }

 
I want to capture both the Record Id and the selected Radio Button value and pass it to the controller and create new Child object record with the selected values only process the selected records.


Visualforce Code:
<apex:page controller="skillproficiencycontroller" >
<apex:form >
<script> function myFunction( val){ var x = val.value; callfunc(x); } </script>
<apex:pageBlock > <
apex:pageblockTable value="{!skilllist}" var="s">
<apex:column value="{!s.Name}"/>
<apex:column headerValue="Proficiency">
<apex:selectRadio value="{!Selected}" onclick="myFunction(this);">
<apex:selectOptions value="{!items}" /> </apex:selectRadio>
</apex:column>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller:
public with sharing class skillproficiencycontroller
{
    public List<skill__c> skilllist{get;set;}
    public String Selected{get;set;}
     
     public skillproficiencycontroller()
         {
             skilllist = new List<Skill__c>();
             skilllist= [select Name FROM skill__c];
         }

     public List<selectoption> getitems() {
         List<SelectOption> options = new List<SelectOption>();  
                 options.add(new SelectOption('Basic Knowledge' , 'Basic Knowledge'));  
                 options.add(new SelectOption('Intermediate' , 'Intermediate'));
                 options.add(new SelectOption('Advanced' , 'Advanced'));  
                 return options;
       }
   
   public void Save()
     {
    List<Skill_Details__c >skilldetailslist = new List<Skill_Details__c >();
         for(Skill s: selectedskilllist){
          Skill_Details__c sd = new Skill_Details__c();
           sd.Skill_c = s.Id;
           sd.Proficiency__c = Selectedvalue;
          skilldetailslist.add(sd);
          }
       Insert skilldetailslist;
}
}}

View Screenshot
This image is not available because: You don’t have the privileges to see it, or it has been removed from the system
I want to capture both the Record Id and the selected Radio Button value and pass it to the controller and create new Child object record with the selected values only process the selected records.


Visualforce Code:
<apex:page controller="skillproficiencycontroller" >
<apex:form >
<script> function myFunction( val){ var x = val.value; callfunc(x); } </script>
<apex:pageBlock > <
apex:pageblockTable value="{!skilllist}" var="s">
<apex:column value="{!s.Name}"/>
<apex:column headerValue="Proficiency">
<apex:selectRadio value="{!Selected}" onclick="myFunction(this);">
<apex:selectOptions value="{!items}" /> </apex:selectRadio>
</apex:column>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller:
public with sharing class skillproficiencycontroller
{
    public List<skill__c> skilllist{get;set;}
    public String Selected{get;set;}
     
     public skillproficiencycontroller()
         {
             skilllist = new List<Skill__c>();
             skilllist= [select Name FROM skill__c];
         }

     public List<selectoption> getitems() {
         List<SelectOption> options = new List<SelectOption>();  
                 options.add(new SelectOption('Basic Knowledge' , 'Basic Knowledge'));  
                 options.add(new SelectOption('Intermediate' , 'Intermediate'));
                 options.add(new SelectOption('Advanced' , 'Advanced'));  
                 return options;
       }
   
   public void Save()
     {
    List<Skill_Details__c >skilldetailslist = new List<Skill_Details__c >();
         for(Skill s: selectedskilllist){
          Skill_Details__c sd = new Skill_Details__c();
           sd.Skill_c = s.Id;
           sd.Proficiency__c = Selectedvalue;
          skilldetailslist.add(sd);
          }
       Insert skilldetailslist;
}
}}

View Screenshot
Skill vs Proficiency
HI I would like to know How to develop pageblocktable with first column as list of record names from the Master object and other 3 columns as input radio button and it should select only one radio button per record , I have to capture the result and save the column header value in the field with the record Name in another field in the child object.
 
I want to capture both the Record Id and the selected Radio Button value and pass it to the controller and create new Child object record with the selected values only process the selected records.


Visualforce Code:
<apex:page controller="skillproficiencycontroller" >
<apex:form >
<script> function myFunction( val){ var x = val.value; callfunc(x); } </script>
<apex:pageBlock > <
apex:pageblockTable value="{!skilllist}" var="s">
<apex:column value="{!s.Name}"/>
<apex:column headerValue="Proficiency">
<apex:selectRadio value="{!Selected}" onclick="myFunction(this);">
<apex:selectOptions value="{!items}" /> </apex:selectRadio>
</apex:column>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller:
public with sharing class skillproficiencycontroller
{
    public List<skill__c> skilllist{get;set;}
    public String Selected{get;set;}
     
     public skillproficiencycontroller()
         {
             skilllist = new List<Skill__c>();
             skilllist= [select Name FROM skill__c];
         }

     public List<selectoption> getitems() {
         List<SelectOption> options = new List<SelectOption>();  
                 options.add(new SelectOption('Basic Knowledge' , 'Basic Knowledge'));  
                 options.add(new SelectOption('Intermediate' , 'Intermediate'));
                 options.add(new SelectOption('Advanced' , 'Advanced'));  
                 return options;
       }
   
   public void Save()
     {
    List<Skill_Details__c >skilldetailslist = new List<Skill_Details__c >();
         for(Skill s: selectedskilllist){
          Skill_Details__c sd = new Skill_Details__c();
           sd.Skill_c = s.Id;
           sd.Proficiency__c = Selectedvalue;
          skilldetailslist.add(sd);
          }
       Insert skilldetailslist;
}
}}

View Screenshot
This image is not available because: You don’t have the privileges to see it, or it has been removed from the system
HI I would like to know How to develop pageblocktable with first column as list of record names from the Master object and other 3 columns as input radio button and it should select only one radio button per record , I have to capture the result and save the column header value in the field with the record Name in another field in the child object.
 
This code displays a multi-select picklist as checkboxes perfectly on a Visualforce page, but when clicking the save button, it shows this error.
Conversion Error setting value 'Its complicated' for '#{Benchmarking_Result__c.Challenges_with_M_E__c}'.

Here is the controller
Public ApexPages.StandardController stdcontroller;

List<SelectOption> Commprefvalue = new List<SelectOption>();
   
    public List<Selectoption> getCommpref()
    {
        Schema.DescribeFieldResult CommprefField = Schema.sObjectType.Benchmarking_Result__c.fields.Challenges_with_M_E__c; 
        Schema.PicklistEntry [] Commpref = CommprefField.getPickListValues();
       
        //Schema.PicklistEntry [] values = vendorField.getPickListValues();
        for(Schema.PicklistEntry val : Commpref)
        {
            Commprefvalue.add(new SelectOption(val.getValue(), val.getLabel()));
        }
        return Commprefvalue;        
    }

//Save button
    public PageReference MAndEDevSaveBtn(){
        stdcontroller.save();
        PageReference callNextPage= Page.CSI_Positioning_And_Governence;
        callNextPage.setRedirect(true);
        return callNextPage;
    }

On the VF page.
<apex:selectCheckboxes value="{!Benchmarking_Result__c.Challenges_with_M_E__c}" layout="pageDirection">
          <apex:selectoptions value="{!Commpref}"></apex:selectoptions>
 </apex:selectCheckboxes>

<apex:commandButton value="Save and Continue" action="{!MAndEDevSaveBtn}" />
The error
User-added image