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
cml9cml9 

Need Help I am new to VF and Tutorials doesn't make sense regarding this project

I have three Objects as follows
Sales
Product
Products Entry

What I want to happen is that when I am adding a new product on Sales the picture below is what I am seeing. (the picture below is the list of Product Entry.
User-added image

Once I checked 1 or more and then clicked the button Select, it will bring me to another visual for page where I can edit the price, quatity and description and when I hit Save, it will be saved in Products object.

Hope someone can help me. This is a bit urgent and my job depends on this. Thank you very much.
NagendraNagendra (Salesforce Developers) 
Hi cml9,

You will need to write a wrapper class to include the object that you are updating and a boolean variable which will take the value (True/False) from the checkbox of the corresponding record of the object. So while displaying the records on the VF page you will have to use the instance of the wrapper class.The value of the boolean variable will be false by default.

Please refer to the below sample codes below so that you get a clear idea.

Sample code 1 how to write a wrapper

Apex Controller:
public class OuterClass
{
List<WrapperClass> wrapperList = new List<WrapperClass>();

public class WrapperClass
{
	public YourObject__c obj{get;set;}
	public Boolean checked{get;set;}
	public WrapperClass()
	{
		obj = new YourObject__c();
		checked = false;
	}
}

}

Visualforce Page:
<apex:pageBlockTable value="{!wrapperList}" var="list">
    <apex:column value="{!list.obj.Field1}"/>
	<apex:column value="{!list.obj.Field1}"/>
	<apex:column value="{!list.checked}"/>
</apex:pageBlockTable>

Sample code 2 how to update the records using checkboxes and save them in the database

Apex Controller:
<apex:page standardController="Contact" extensions="FStoringCheckBoxValueExtension">
    <apex:form >
        <apex:pageBlock title="Update Contact Details">
                <apex:pageBlockButtons location="bottom">
                    <apex:commandButton action="{!savingCheckBoxValue}" value="Save"/>
                    <apex:commandButton action="{!cancel}" value="Cancel"/>
                </apex:pageBlockButtons>
                
                <apex:pageBlockSection id="NewPage" title="Select The Country">
                    <apex:inputField value="{!Contact.Country__c}">
                        <apex:actionSupport event="onchange" reRender="IndiaBlock, USBlock, ChinaBlock, AusesBlock"/>
                    </apex:inputField>
                    <!--<apex:inputField value="{!Contact.LastName}"/>-->
                  <p> Last Name: <apex:inputText value="{!lastname}"/></p>
                </apex:pageBlockSection> 
                
                <apex:outputPanel id="IndiaBlock">
                    <apex:pageBlockSection rendered="{!Contact.Country__c == 'India'}" id="SampleSendInfoBlock" title="Select Places Visited">
                        <apex:outputLabel value="Agra" for="indiacheck">
                            <apex:inputCheckbox value="{!Indiaplaceist}" id="indiacheck1">
                                 <apex:actionSupport event="onclick" action="{!getSelected}" rerender="IndiaBlock"/>
                            </apex:inputCheckbox>
                        </apex:outputLabel> 
                        
                        <apex:outputLabel value="Delhi" for="indiacheck2">   
                            <apex:inputcheckbox id="indiacheck2" value="{!Indiaplace2nd}">
                                <apex:actionSupport event="onclick" action="{!getSelected}" rerender="IndiaBlock"/>
                            </apex:inputCheckbox>
                        </apex:outputLabel>
                        
                     </apex:pageBlockSection>
                </apex:outputPanel>
                
                <apex:outputPanel id="USBlock">
                    <apex:pageBlockSection title="Select Places Visited" rendered="{!Contact.Country__c == 'America'}" id="USPageBlock">
                        <apex:outputLabel value="Newyork" for="Newyorkcheck1">  
                            <apex:inputCheckbox value="{!Newyorkplaceist}" id="Newyorkcheck1">
                                <apex:actionSupport event="onclick" action="{!getSelected}" rerender="IndiaBlock"/>
                            </apex:inputCheckbox>
                         </apex:outputLabel>
                         <apex:outputLabel value="Washington" for="Newyorkcheck2">       
                             <apex:inputCheckbox value="{!Newyorkplace2nd}">
                                 <apex:actionSupport event="onclick" action="{!getSelected}" rerender="IndiaBlock"/>
                             </apex:inputCheckbox> 
                         </apex:outputLabel>       
                    </apex:pageBlockSection> 
                </apex:outputPanel>
                
                
                
        </apex:pageBlock>
    </apex:form>
</apex:page>

Visualforce Page:
public class FStoringCheckBoxValueExtension {
    private  Contact contact;
    public String Indiaplaceist{get;set;}
    public String lastname{get;set;}
    public String Indiaplace2nd{get;set;}
    
    
    public String Newyorkplaceist{get;set;}
    public String Newyorkplace2nd{get;set;}
   
    public String resultString{get;set;}
    public FStoringCheckBoxValueExtension(ApexPages.StandardController controller) {
        Contact contact = new Contact();
    }
    public void savingCheckBoxValue()
    {   
        
        
        //upsert acct;
        //System.debug('@@@@@@@@@@@@@@@@@@@Indiaplace@@@@@@@@@@'+Indiaplace);
         System.debug('@@@@@@@@@@@@@@@@@@@resultString @@@@@@@@@@'+resultString );
         Contact contact = new Contact();
        contact.PlacesVisisted__c = resultString ;
        contact.LastName= lastname;
        insert contact;
    }    
    public PageReference getSelected(){
        System.debug('@@@@@@@@@@@@@@@@@@@Indiaplace@@@@@@@@@@'+Indiaplaceist);
        if(Indiaplaceist == 'true'){
            if(resultString !=null){
                resultString = resultString+' '+ 'Agra'; 
            }
            else{
                resultString = 'Agra'; 
             }      
           System.debug('@@@@@@@@@@@@@@@@@@@resultStringtestIf @@@@@@@@@@'+resultString ); 
         }
         else if(Indiaplace2nd == 'true'){
              if(resultString !=null){
                  resultString = resultString+' '+'Delhi' ;
              }
              else{
                  resultString = 'Delhi' ;  
              }     
          }
         else if(Newyorkplaceist == 'true') {
             if(resultString !=null){
                resultString = resultString+' '+'Newyork' ;  
             }
             else{
                 resultString = 'Newyork' ;  
              }   
         } 
         else if(Newyorkplace2nd == 'true') {
             if(resultString !=null){
                 resultString = resultString+' '+'Washington';
             }
              else{
                  resultString = 'Washington';
               }
         }
         else{
         }   
         
        return null;
    }
}
Let me know if you have any issues further.

Please mark it as solved if it helps.

Best Regards,
Nagendra.P 
cml9cml9
Can you please elaborate more on this?