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
Subrahmanyam KonathlapalliSubrahmanyam Konathlapalli 

The below code is giving o/p in oneline..... I need the o/p in line by line, I tried but i didn't get....

list<laptop__c> laplist=new list<laptop__c>();
laplist= [select id,name,Harddisk__c,Processor__c from laptop__c];
set<id> recordid=new set<id>();
for (laptop__c lap:laplist){
   recordid.add(lap.Harddisk__c); 
}
system.debug(recordid);
Best Answer chosen by Subrahmanyam Konathlapalli
Niraj Kr SinghNiraj Kr Singh
Hi,
Try this for unique:

for (laptop__c lap:laplist){
   if(!recordid.contains(lap.Harddisk__c)) {
       recordid.add(lap.Harddisk__c);
       system.debug(lap.Harddisk__c);
   }
}

And let me know if it work for you.

All Answers

Niraj Kr SinghNiraj Kr Singh
Hi,
better to put debug log inside the for loop:

for (laptop__c lap:laplist){
   recordid.add(lap.Harddisk__c); 
   system.debug(lap.Harddisk__c);
}

Thanks
NKS
Subrahmanyam KonathlapalliSubrahmanyam Konathlapalli
But it is printing duplicates also...
 
Steven NsubugaSteven Nsubuga
list<laptop__c> laplist=new list<laptop__c>();
laplist= [select id,name,Harddisk__c,Processor__c from laptop__c];
set<id> recordid=new set<id>();
for (laptop__c lap:laplist){
   recordid.add(lap.Harddisk__c); 
}
system.debug(recordid);
for (Id rid:recordid){
   system.debug(rid);
}

 
Niraj Kr SinghNiraj Kr Singh
Hi,
Try this for unique:

for (laptop__c lap:laplist){
   if(!recordid.contains(lap.Harddisk__c)) {
       recordid.add(lap.Harddisk__c);
       system.debug(lap.Harddisk__c);
   }
}

And let me know if it work for you.
This was selected as the best answer
Subrahmanyam KonathlapalliSubrahmanyam Konathlapalli
Thank you @Niraj kr singh,@Steven nsubuga. It works....
 
Niraj Kr SinghNiraj Kr Singh
It will good to mark your Ans, might be help others !!

thanks