fork download
  1. public class DuplicateProductChecker {
  2. public class PricebookEntry {
  3. public String Id { get; set; }
  4. public Decimal UnitPrice { get; set; }
  5. public String Product2Id { get; set; }
  6.  
  7. public PricebookEntry(String Id, Decimal UnitPrice, String Product2Id) {
  8. this.Id = Id;
  9. this.UnitPrice = UnitPrice;
  10. this.Product2Id = Product2Id;
  11. }
  12. }
  13.  
  14. public static Set<String> getProduct2Ids(List<PricebookEntry> objectList) {
  15. Set<String> product2Ids = new Set<String>();
  16. for (PricebookEntry entry : objectList) {
  17. product2Ids.add(entry.Product2Id);
  18. }
  19. return product2Ids;
  20. }
  21.  
  22. public static List<String> findDuplicates(List<PricebookEntry> objectList1, List<PricebookEntry> objectList2) {
  23. Set<String> set1 = getProduct2Ids(objectList1);
  24. Set<String> set2 = getProduct2Ids(objectList2);
  25. set1.retainAll(set2);
  26. return new List<String>(set1);
  27. }
  28.  
  29. public static void main() {
  30. // Sample data
  31. List<PricebookEntry> objectList1 = new List<PricebookEntry>{
  32. new PricebookEntry('01uIo000000nM1ZIAU', 720.00, '01t5i000007WIHkAAO'),
  33. new PricebookEntry('01uIo000000nHpiIAE', 1300.00, '01tIo000001W5MlIAK'),
  34. new PricebookEntry('01uIo000000nHpjIAE', 650.00, '01tIo000001W3YLIA0'),
  35. new PricebookEntry('01uIo000000nHpkIAE', 1500.00, '01tIo000001W5MrIAK'),
  36. new PricebookEntry('01uIo000000nHplIAE', 750.00, '01tIo000001W5MqIAK'),
  37. new PricebookEntry('01uIo000000nHpmIAE', 110.00, '01tIo000001W5NoIAK'),
  38. new PricebookEntry('01uIo000000nHpnIAE', -100.00, '01tIo000001W5O3IAK')
  39. };
  40.  
  41. List<PricebookEntry> objectList2 = new List<PricebookEntry>{
  42. new PricebookEntry('01uIo000000nIwYIAU', 100.00, '01tIo000001WdGqIAK'),
  43. new PricebookEntry('01u5i000004hWm0AAE', 595.00, '01t5i000007WIHkAAO'),
  44. new PricebookEntry('01uJ3000000ui9SIAQ', 695.00, '01tJ3000000rDGuIAM'),
  45. new PricebookEntry('01uIo000000nHokIAE', 1345.00, '01tIo000001W5MlIAK'),
  46. new PricebookEntry('01uIo000000nHouIAE', 1520.00, '01tIo000001W5MrIAK'),
  47. new PricebookEntry('01uIo000000nHl2IAE', 695.00, '01tIo000001W3YLIA0'),
  48. new PricebookEntry('01uIo000000nHozIAE', 120.00, '01tIo000001W5NoIAK'),
  49. new PricebookEntry('01uIo000000nHp0IAE', -100.00, '01tIo000001W5O3IAK'),
  50. new PricebookEntry('01uIo000000nHopIAE', 775.00, '01tIo000001W5MqIAK')
  51. };
  52.  
  53. // Finding duplicates
  54. List<String> duplicates = findDuplicates(objectList1, objectList2);
  55. System.debug('Duplicate Product2Id: ' + duplicates);
  56. }
  57. }
  58.  
Success #stdin #stdout #stderr 0.01s 8980KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #DuplicateProductChecker
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #DuplicateProductChecker (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
stderr
./prog:2: parse error, expected '}'