0

i have a visualforce page with some fields all fields are check box fields. if i selected some chck box fields and after saved it.

my requirement is how to filter in soql query for all selected fields in visualforce page

this is my page ::

                 font-size:15px;color:blue;">
        Incident Fields 
     </div>
 <table>
     <tr>
         <td>
             Imtpact
         </td>
         <td>
             <apex:inputCheckbox value="{!impact}"/>
         </td>
         </tr>
         <tr>
         <td>
             Incident_state
         </td>
         <td>
            <apex:inputCheckbox value="{!incident_state}"/>
         </td>
         </tr>
         <tr>
         <td>
             Short_description
         </td>
         <td>
            <apex:inputCheckbox value="{!short_description}"/>
         </td>
         </tr>

         <tr>
         <td>
             sys_id
         </td>
         <td>
             <apex:inputCheckbox value="{!sys_id}"/>
         </td>
     </tr>
     <tr>
         <td>
             Contact_type
         </td>
         <td>
            <apex:inputCheckbox value="{!contact_type}"/>
         </td>
         </tr>
         <tr>
         <td>
             U_sftype
         </td>
         <td>
            <apex:inputCheckbox value="{!u_sftype}"/>
         </td>
         </tr>
         <tr>
         <td>
             sys_updated_onONLast
         </td>
         <td>
            <apex:inputCheckbox value="{!sys_updated_onONLast}"/>
         </td>
         </tr>
     <tr >
         <td colspan="2" align="center">
             <apex:commandButton value="INSERT" style="color:red;" action="{!doInsert}" />
         </td>
     </tr>
 </table>
 </div>   

this my apex class ::

public with sharing class DataInsert {

     public Boolean impact {get;set;} 
     public Boolean incident_state {get;set;} 
     public Boolean short_description {get;set;} 
     public Boolean sys_id {get;set;} 
     public Boolean contact_type {get;set;} 
     public Boolean u_sftype {get;set;} 
     public Boolean sys_updated_onONLast {get;set;}


     List<Incident__c> lst = new List<Incident__c>();
     public PageReference doInsert() {

        Incident__c objdlt = new Incident__c();      
        objdlt.impact__c=impact ;
        objdlt.incident_state__c=incident_state;
        objdlt.short_description__c=short_description;
        objdlt.sys_id__c=sys_id;
        objdlt.contact_type__c=contact_type;
        objdlt.u_sftype__c=u_sftype;
        objdlt.sys_updated_onONLast__c=sys_updated_onONLast;
        insert objdlt;
        lst.add(objdlt);

    PageReference myVFPage = new PageReference('https://c.na40.visual.force.com/apex/Data_Insert_page');
      myVFPage.setRedirect(true);   
      return myVFPage;

    }      
}

if i saved a record with only some checkbox fields how should i filter only selected fields from that record

Thanks In Advance

0

1 Answer 1

0

I think you want to achieve this

Incident__c objdlt = new Incident__c(); 
//checking if impact is true    
if(impact){ 
  objdlt.impact__c=impact ;
}
//checking if incident_state is true and same with all
if(incident_state){
   objdlt.incident_state__c=incident_state;
}
if(short_description){
   objdlt.short_description__c=short_description;
}
if(sys_id){
   objdlt.sys_id__c=sys_id;
}
if(contact_type){
   objdlt.contact_type__c=contact_type;
}
if(u_sftype){
   objdlt.u_sftype__c=u_sftype;
}
if(sys_updated_onONLast){
   objdlt.sys_updated_onONLast__c=sys_updated_onONLast;
}           
insert objdlt; //but before inserting to make sure at least required fields are filled. so it can insert without exception.
lst.add(objdlt);
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .