You need to sign in to do that
Don't have an account?
Writing Test Method with master-detail issue
I have a test class that I am writing, and I need to insert a record. The records custom object has two master-detail relationships.
Custom Object = Invoice__c
Standard = Opportunity
Standard = Account
My insert statement is as such:
Invoice__c invoice = new Invoice__c(T_Invoice__c = '1234', Date_of_Purchase_Order_Authorization__c = testdate, Payment_Due_Date__c = testdate, Payment_Received_Date__c = testdate, Aging__c = 0, Your_Purchase_Order__c = '1234', Account_Name__c = testrenewal.accountId, Amount_w_o_Tax__c = 100.00, Amount__c = 100.00, MR_Opportunity__c = ???, Account_Id__c = ???);
When I try to add logic to get the "id" from the opportunity record, I dont seem to get any errors, but the account "id" keeps throwing errors at me like:
Missing required field (if I remove account_id__c)
Insufficient access on cross reference entity (if I try to grab the id from a test opportunity that I insert before this invoice)
Insufficient access on cross reference entity(if I try to grab the id from a test account that I insert before this invoice)
The idea is that I am creating an invoice from an opportunity, but it must have the Account Name and Opportunity Name on the invoice. The invoice is created from a button off the opportunity page (code for that is done and testing at 94%).
Not sure what else to do !!
Any help is appreciated. Thank you.
In Test class, the same user is trying to access the records?
What is the OWD settings of Account and Opportunity? If it is private then please check the sharing rules defined. As this is clearly the sharing related error, where the user trying to access the record which is not shared with him.
Hi
If you are doing a query for Opportunityid and Account id please make sure you add @isTest(SeeAllData=true) to your @Test annotation.
If not the option is two reate your test account and opportunity and assign it like below:
Account acc = new Account(name='Test Account');
insert acc;
Opportunity opp = new Opportunity(name='Test opportunity', closedate = system.today(),AccountId = acc.Id);
insert opp;
Invoice__c invoice = new Invoice__c(T_Invoice__c = '1234', Date_of_Purchase_Order_Authorization__c = testdate, Payment_Due_Date__c = testdate, Payment_Received_Date__c = testdate, Aging__c = 0, Your_Purchase_Order__c = '1234', Account_Name__c = testrenewal.accountId, Amount_w_o_Tax__c = 100.00, Amount__c = 100.00, MR_Opportunity__c = opp.Id, Account_Id__c = acc.Id);
Vriavm -
I thought the same as what you have written.
Here is the full test code:
The way I have it laid out, it makes sense to me, but with this code I get the error:
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
Whats happening?