So recently I got that error "Record ID: cannot specify Id in an insert call", and after doing some research I fixed it by.
try{
insert p;
}catch(exception e){
Database.rollback(sp);
p = p.clone(false);
system.debug('Broke');
}
What did I do? What exactly is going on here? Update**
This was my old test class
@isTest(SeeAllData=true)
private class AutoPopulateSampleTest {
static testMethod void rsmUpdate() {
Product2 p = new Product2(id = '01tE0000000hVTcIAM',
Name = 'Erics',
AE2__c = '01tE0000000hNN1IAM',
Country_code__c = 'USA'
);
insert p;
Sampling__c s = new Sampling__c(Quantity_of_Samples__c = 2,
//s.Date_Sample_Needed__c = (2014,3,18),
Product__c = '01tE0000000hNN1IAM',
Override__c = 'No',
Country__c = 'US',
State_Province__c = 'CA',
Zip_Postal_Code__c = '93003',
Contact__c = 'Boop Betty');
insert s;
try {
insert S;
} catch (DmlException e) {
system.assertEquals(true, e.getMessage().contains('my expected error'));
}
}
}