I am having a hard time wrapping my head around a concept.
I write a query that pulls out data from salesforce and sends it to a web service. The webservice sends me back data for a report. This data is saved into a custom object.
Why am I able to hard code, in my test class, in my dev environment, the data I am sending to the webservice? Why does this hardcoded mock data not transfer over to prod? In dev I am getting full test coverage and the green check to upload. But when my test class runs against the prod's tests, it fails with the error of null data.
Why am I able to deploy from sandbox to sandbox with hardcoded test data but not deploy to prod?
It doesn't make sense to me and I think I need to understand this before I am able to find the solution to deploy to prod.
public static testmethod void testAccountCallout()
{
createBVS();
oppId = [SELECT Opportunity__c FROM Credit_Review__c WHERE Credit_Review__r.Id = '123456789'].Opportunity__c;
SingleRequestMockClass fakeResponse = new SingleRequestMockClass(201,'Complete','{\"SignorZipCode\":"92109,\"SignorStreetAddress\":"123 Main St",\"SignorState\":"CA",\"SignorSSN\":"123222222",\"SignorLastName\":null,\"SignorHomePhone\":null,\"SignorFirstName\":null,\"SignorCity\":null,\"PhysicalAddressZip\":\"92109\",\"PhysicalAddressState\":\"CA\",\"PhysicalAddressCity\":\"San Diego\",\"PhysicalAddress1\":\"111 Rio Way\",\"FedTaxId\":"11111111",\"CompanyLegalName\":\"Broker The Joker\"}',null);
Test.startTest();
Test.setMock(HttpCalloutMock.class, fakeResponse);
sendToWebService2 ctrl = new sendToWebService2(new ApexPages.StandardController(new Credit_Review__c()));
ctrl.pullReport();
Test.stopTest();
System.assert(true);
System.assertNotEquals(null, fakeResponse, 'The callout returned a null response.');
}
public static testmethod void createBVS() {
Business_Verification_Summary__c bvs = new Business_Verification_Summary__c();
bvs.Lexis_Nexis_Report_Link__c = 'jjjjjjjjjjjsssssssssonnnnnn';
bvs.Status__c = 'Completed';
system.assertEquals('Completed', bvs.Status__c);
}
UPDATE:
public static testmethod void createBVS() {
Account a = new Account(Name = 'Test Account Olivia');
insert a;
Opportunity o = new Opportunity(AccountId = a.Id, Name = 'LexisNexis', CloseDate = Date.today(), StageName = 'Prospecting');
insert o;
Credit_Review__c crc = new Credit_Review__c(Opportunity__c = o.Id);
insert crc;
Business_Verification_Summary__c bvs = new Business_Verification_Summary__c();
bvs.Lexis_Nexis_Report_Link__c = 'jjjjjjjjjjjsssssssssonnnnnn';
bvs.Status__c = 'Completed';
bvs.Credit_Review__c = crc.Id;
insert bvs;
system.assertEquals('Completed', bvs.Status__c);
}
oppId = [SELECT Opportunity__c FROM Credit_Review__c WHERE Credit_Review__r.Id = '123456789'].Opportunity__c;
is the line that prod is saying has null data. But it does have this data, in the sandbox I am working in at least.Credit_Review__c
record coming from? Is there a@isTest(SeeAllData=true)
annotation used on that method?isTest(SeeAllData=true)
it fails in prod. I should not have to use this.