+ Start a Discussion
St2018St2018 

How to test and insert data that source_system_id is not null in my test class

list<Opportunity> oppList = SATestUtil.createOpportunity(10);
        
        for(Opportunity opp : oppList ){
           opp.Type = 'New';
           opp.StageName = 'Executed'; 
           opp.Tenant_Construction = date.today();
           opp.Source_System_Id__c = 'test';
        }
    	update oppList;

 I am migrating records and I've wrote a batch class.In my query I have a where condition to filter the migrated records. how can i test for that in my test class?   the where condition is Source_System_Id__c != null;  I get an error System.DmlException: Update failed. First exception on row 1 with id 0061k000005ySO5AAM; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []
Guru Vemuru 11Guru Vemuru 11

Hi Stephanie,
To test your testclass, first set some debug log statements and run the test class.
After that goto log in developer console check your debug statements.
See below code

list<Opportunity> oppList = SATestUtil.createOpportunity(10);
for(Opportunity opp : oppList ){
opp.Type = 'New';
opp.StageName = 'Executed';
opp.Tenant_Construction = date.today();
opp.Source_System_Id__c = 'test';
}
update oppList;
sytem.debug('####TestOpp###'+oppList);




Thanks 
Guru Vemuru

 

Raj VakatiRaj Vakati
Looks like you have duplicate rules and can you not insetr the same opportunity from the createOpportunity method