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
diydiy 

how to using set Remove duplicate values for this code?

public List<Equipment_Master__c> ProductList{ get; set;}
public List<Equipment_Master__c> ProductListadd{ get; set;}
 Set<Equipment_Master__c> setEquipment = new Set<Equipment_Master__c>();  

    List<Equipment_Master__c> productresults;  
    public pagereference productadd (){
    for(integer i=0;i<AssetAddList.size();i++ ){
    ProductList = [select Product_Number__c from Equipment_Master__c where Serial_Number__c   =: AssetAddList[i].Serial_Number__c];
    setEquipment.add(ProductList[i].Product_Number__c);
    ProductListadd.add(setEquipment);  -- How can i add a product list value in productlistadd?
    }
}

 public List<Equipment_Master__c> getproductresults(){
   

  return ProductListadd;
 
    
}


<apex:pageBlockTable value="{!productresults}" var="pro">
          <apex:column headerValue="Product Number">
                    <apex:inputField value="{!pro.id}"/>
                </apex:column>  
                           
         </apex:pageBlockTable>




 ProductList - 1,1,2,3,4,5,2,4,2,3,2,4 - using set I want to distinct value

  o/p - 1,2 3,4,5

digamber.prasaddigamber.prasad

Hi Diya,

 

Based upon content of your controller, I have made some changes and following controller should give you desired result:-

 

public List<Equipment_Master__c> ProductList{ get; set;}
public List<Equipment_Master__c> ProductListadd{ get; set;}
Set<Integer> setEquipmentNumber = new Set<Integer>();  

List<Equipment_Master__c> productresults;  
public pagereference productadd (){
	for(integer i=0;i<AssetAddList.size();i++ ){
		ProductList = [select Product_Number__c from Equipment_Master__c where Serial_Number__c   =: AssetAddList[i].Serial_Number__c];
		for(Equipment_Master__c quip : ProductList){
			if(!setEquipmentNumber.contains(quip.Product_Number__c)){
				setEquipmentNumber.add(quip.Product_Number__c)
				ProductListadd.add(quip);  // How can i add a product list value in productlistadd?
			}
		}
    }
}

public List<Equipment_Master__c> getproductresults(){

	return ProductListadd;
}

 

Also, your part of VF page may look like:-

 

<apex:pageBlockTable value="{!productresults}" var="pro">
	<apex:column headerValue="Product Number">
		<apex:inputField value="{!pro.Product_Number__c}"/>
	</apex:column>  
				   
 </apex:pageBlockTable>

 Hope it will help you!

 

Happy to help you!

 

Regards,

Digamber Prasad