@@ -321,6 +321,12 @@ private with sharing class BDI_DataImportService_TEST {
321
321
accounts .add (acc );
322
322
}
323
323
insert accounts ;
324
+
325
+ // Store Account IDs for assertion
326
+ Set <Id > createdAccountIds = new Set <Id >();
327
+ for (Account acc : accounts ) {
328
+ createdAccountIds .add (acc .Id );
329
+ }
324
330
325
331
// Create Contacts to ensure matching
326
332
List <Contact > contacts = new List <Contact >();
@@ -342,6 +348,11 @@ private with sharing class BDI_DataImportService_TEST {
342
348
}
343
349
insert contacts ;
344
350
351
+ // Store Contact IDs for assertion
352
+ Set <Id > createdContactIds = new Set <Id >();
353
+ for (Contact con : contacts ) {
354
+ createdContactIds .add (con .Id );
355
+ }
345
356
// Assign created contact IDs to the data import records
346
357
for (Integer i = 0 ; i < 5 ; i ++ ) {
347
358
testDataImportss [i ].Contact1Imported__c = contacts [i * 2 ].Id ;
@@ -370,12 +381,12 @@ private with sharing class BDI_DataImportService_TEST {
370
381
service .importAccounts ();
371
382
Test .stopTest ();
372
383
373
- // Add assertions to verify the Account and Contact records were created/updated as expected
374
- List <Account > accounts1 = [SELECT Id , Name , Phone FROM Account WHERE Name LIKE ' Test Account% ' ];
375
- System .assert ( accounts1 .size () > 0 , ' Accounts should be created' );
376
-
377
- List <Contact > contactList = [SELECT Id , FirstName , LastName , Email FROM Contact WHERE LastName LIKE ' LastName% ' ];
378
- System .assert ( contactList .size () > 0 , ' Contacts should be created' );
384
+ // Assertions using IDs
385
+ List <Account > fetchedAccounts = [SELECT Id , Name FROM Account WHERE Id IN : createdAccountIds ];
386
+ System .assertEquals ( createdAccountIds .size (), fetchedAccounts . size () , ' Accounts should be created and fetched using Ids ' );
387
+
388
+ List <Contact > fetchedContacts = [SELECT Id , FirstName , LastName , Email FROM Contact WHERE Id IN : createdContactIds ];
389
+ System .assertEquals ( createdContactIds .size (), fetchedContacts . size () , ' Contacts should be created and fetched using Ids ' );
379
390
}
380
391
381
392
// Helpers
0 commit comments