You need to sign in to do that
Don't have an account?
Can't create test object
Hello gurus,
I'm trying to be a better developer by writing the test code first. I can't create all the needed test objects. Account, Contact, Case are created and I can see the IDs in the debug log but get an error when creating the Asset. What am I overlooking?
There is no other code created yet.
Error:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Every asset needs an account, a contact, or both.: [AccountId, ContactId]
Class.AssetUpdateTest.createAsset: line 69, column 1
Class.AssetUpdateTest.testAssetLink: line 9, column 1
I'm trying to be a better developer by writing the test code first. I can't create all the needed test objects. Account, Contact, Case are created and I can see the IDs in the debug log but get an error when creating the Asset. What am I overlooking?
There is no other code created yet.
@IsTest(SeeAllData=True) public class AssetUpdateTest { public static testmethod void testAssetLink() { Account acc = createAccount(); Contact con = createContact(acc); Case cas = createCase(acc,con); Asset ast = createAsset(acc,con,cas); System.debug('************************** Case ID: ' + cas.id); System.debug('************************** Case.Asset: ' + cas.AssetId); } public static Account createAccount(){ Account theAccount = new Account( recordtypeid='01270000000Q7rQ', name='Test Account', Status__c='Client', Line_of_Business__c='CRS', phone='8005551212', currencyisocode='USD'); insert theAccount; return theAccount; } public static Contact createContact(Account theAccount){ Contact theContact = new Contact( recordtypeid='01270000000Q7ra', email='tim.bouscal@audatex.com', firstname='George', lastname='Washington', accountid=theAccount.id); insert theContact; return theContact; } public static Case createCase(Account acc, Contact con){ Case theCase = new Case( recordtypeid='01270000000Dy9u', AccountId = acc.Id, ContactId = con.Id, Requestor__c=con.Id, Reason='New Account Setup', Reason_Detail__c='New - ADXE Shop 02', Status='New', Origin='Sales Request', Subject='AssetUpdateTest Sample BisOps Case', Description='This is a sample case for testig the AssetUpdate class' ); insert theCase; return theCase; } public static Asset createAsset(Account acc, Contact con, Case cas){ System.debug('***** ***** ***** Account ID: ' + acc.id + ' Contact Id: ' + con.id + ' Case ID: '+ cas.Id); // all 3 values show in debug log Asset theAsset = new Asset( Name='Test Asset', Account = acc, Contact = con, Case_Number__c = cas.CaseNumber, Type__c='New', Status='Purchased', Description='This is a test asset for testing the AssetUpdate class' ); insert theAsset; return theAsset; } }
Error:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Every asset needs an account, a contact, or both.: [AccountId, ContactId]
Class.AssetUpdateTest.createAsset: line 69, column 1
Class.AssetUpdateTest.testAssetLink: line 9, column 1
Did this help?
Shawn
All Answers
Did this help?
Shawn
Account and Contact are the names of the relationships.
AccountId = acc.id,
ContactId = con.id,