• #15844
    Salesforce | PRANAV PRANAV #679
    Forcetalks

    How to make multiselect checkboxes in searched results of any Salesforce sObject?

    Hi All,

    How to make multiselect checkboxes in searched results of any Salesforce sobject?

    As in my scenario, there is a search box which searches the user’s entered value and shows the result via search button click. So I want to select multiple results (through checkbox) to use it further. How it can be done help me out.

    Thanks

     

    #16031
    Salesforce | Mohit Mohit #401
    Forcetalks

    Hi Pranav,

    You have to create a Visualforce page to show data and you have to make controller for it to perform operation.

    Here is Visualforce page:-
    <apex:page standardController=”Opportunity” extensions=”OpportunityProductsearch”>
    <apex:form id=”theForm”>
    <apex:pageBlock title=”Search the Product” >
    <apex:inputText value=”{!searchtext}”/>
    <apex:commandButton value=”search” action=”{!search}” />
    <apex:pageMessages />
    <apex:pageBlockSection Title=”List of Product” id=”table” collapsible=”false” rendered = “{!toshow}”>
    <apex:pageBlockTable value=”{!listofproductselected}” var=”p” >
    <apex:column title=”Select” >
    <apex:inputCheckbox value=”{!p.checked}” ></apex:inputcheckbox>
    </apex:column>
    <apex:column headervalue=”Name” value = “{!p.pro.Name}” />
    <apex:column headervalue=”Product Code” value=”{!p.pro.ProductCode}”/>
    <apex:column headervalue=”Description” value=”{!p.pro.Description}” />
    </apex:pageBlockTable>
    </apex:pageBlockSection>
    <apex:commandButton value =”Submit” action =”{!submit}” rendered=”{!toshow}” />
    <apex:pageBlockSection Title=”List of Product in Update” id=”table2″ collapsible=”false” rendered = “{!!toshow}”>
    <apex:pageBlockTable value=”{!showprod}” var=”s” >
    <apex:column headervalue=”Name” >
    <apex:inputField value = “{!s.Name}” />
    </apex:column>
    <apex:column headervalue=”Product Code”>
    <apex:inputField value=”{!s.ProductCode}”/>
    </apex:column>
    <apex:column headervalue=”Description”>
    <apex:InputField value=”{!s.Description}” />
    </apex:column>
    </apex:pageBlockTable>
    </apex:pageBlockSection>
    <apex:commandButton value =”save” action =”{!autoupdate}” rendered=”{!!toshow}” />
    <apex:commandButton value =”cancel” action =”{!search}” rendered=”{!!toshow}” />
    </apex:pageBlock>
    </apex:form>
    </apex:page>

    and Now the Controller:-
    public with sharing class OpportunityProductsearch {
    public String searchText{get;set;}
    public boolean toshow{get;set;}
    public List<Product2> prod{get;set;}
    public list<ProductWrapper> listofproductselected{get;set;}
    public list<Product2> selectedproduct;
    public list<Product2> showprod{get;set;}

    public class ProductWrapper{
    public Product2 pro{get;set;}
    public Boolean checked{get; set;}
    public ProductWrapper(Product2 p,boolean b){
    pro = p;
    checked = b;
    }
    }
    public OpportunityProductsearch(ApexPages.StandardController con){
    toshow = true;
    prod = new List<Product2>();
    prod.clear();
    }
    public void search(){
    prod.clear();
    toshow = true;
    listofproductselected = new list<ProductWrapper>();

    if(!String.isBlank(searchText)){
    String s = ‘%’+searchText+’%’;
    prod =[select Name,ProductCode,Description,family from Product2 where name like :s ];

    if(prod!=null){
    for(Product2 p : prod){
    ProductWrapper pw = new ProductWrapper(p,false);
    listofproductselected.add(pw);
    }
    }
    }
    }
    public void submit(){
    toshow = false;
    selectedproduct = new list<Product2>();
    for(ProductWrapper p : listofproductselected ){
    if(p.checked == true){
    selectedproduct.add(p.pro);
    }
    }
    System.debug(‘the select product to be printed : ‘+selectedproduct);
    showprod = selectedproduct;
    }
    public void autoupdate(){
    update showprod;
    search();
    }
    }

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?