You need to sign in to do that
Don't have an account?
Jyosi jyosi
Custom setting and @isTest(SeeAlldata=false)
Hello Everyone,
When i use @isTest(SeeAlldata=true) the test class run with out any error .
Want to build the test class @isTest(SeeAlldata=false ) while accesing the custom setting data
I have created the test data for custom setting as below
AuthenticationSettings__c GLIntegration = new AuthenticationSettings__c();
//uthenticationSettings__c GLIntegration = new AuthenticationSettings__c();
GLIntegration.User__c='Test';
GLIntegration.Name='121';
GLIntegration.Password__c='Test';
GLIntegration.EndPoint__c='https://XXX/XXX/XXX.svc';
Insert GLIntegration;
system.debug('customSettinInsert!!'+GLIntegration);
System.assert(GLIntegration != null);
List<GLIntegrationAuthenticationSettings__c> GLIntegrationQuery= new List<GLIntegrationAuthenticationSettings__c>();
GLIntegrationQuery=[Select Id,Name,User__c,Password__c,EndPoint__c from GLIntegrationAuthenticationSettings__c where id=:GLIntegration.Id];
system.debug('GLIntegrationQuerysize!!!'+GLIntegrationQuery.size());
AuthenticationSettings__c GLIntegrationTestValues = AuthenticationSettings__c.getAll().get('121');
String UserName=GLIntegrationTestValues.User__c;
String Password=GLIntegrationTestValues.Password__c;
String Biz_Talk_EndPoint=GLIntegrationTestValues.EndPoint__c;
String Name=GLIntegrationTestValues.Name;
System.debug('@@'+UserName+'!!!'+Password+'*****'+Biz_Talk_EndPoint+'----'+Name); I can see all the values in the debug.
But it still fails
Class.GlobalComplaintOutbound.<init>: line 16, column 1
Below is the code which uses the custom setting data
GLIntegrationAuthenticationSettings__c GLIntegration = GLIntegrationAuthenticationSettings__c.getAll().get('BizTalk');
String UserName=GLIntegration.User__c;
String Password=GLIntegration.Password__c;
String Biz_Talk_EndPoint=GLIntegration.EndPoint__c;
Class.GlobalComplaintWebSvcCalloutTest.testEchoString: line 51, column 1
GlobalComplaintOutbound outbound= new GlobalComplaintOutbound();
Note: I am using the batch apex to make the callout to external system.
Can you please suggest what i am missing here.
Thanks for the help.
Regards,
Jyo
When i use @isTest(SeeAlldata=true) the test class run with out any error .
Want to build the test class @isTest(SeeAlldata=false ) while accesing the custom setting data
I have created the test data for custom setting as below
AuthenticationSettings__c GLIntegration = new AuthenticationSettings__c();
//uthenticationSettings__c GLIntegration = new AuthenticationSettings__c();
GLIntegration.User__c='Test';
GLIntegration.Name='121';
GLIntegration.Password__c='Test';
GLIntegration.EndPoint__c='https://XXX/XXX/XXX.svc';
Insert GLIntegration;
system.debug('customSettinInsert!!'+GLIntegration);
System.assert(GLIntegration != null);
List<GLIntegrationAuthenticationSettings__c> GLIntegrationQuery= new List<GLIntegrationAuthenticationSettings__c>();
GLIntegrationQuery=[Select Id,Name,User__c,Password__c,EndPoint__c from GLIntegrationAuthenticationSettings__c where id=:GLIntegration.Id];
system.debug('GLIntegrationQuerysize!!!'+GLIntegrationQuery.size());
AuthenticationSettings__c GLIntegrationTestValues = AuthenticationSettings__c.getAll().get('121');
String UserName=GLIntegrationTestValues.User__c;
String Password=GLIntegrationTestValues.Password__c;
String Biz_Talk_EndPoint=GLIntegrationTestValues.EndPoint__c;
String Name=GLIntegrationTestValues.Name;
System.debug('@@'+UserName+'!!!'+Password+'*****'+Biz_Talk_EndPoint+'----'+Name); I can see all the values in the debug.
But it still fails
Class.GlobalComplaintOutbound.<init>: line 16, column 1
Below is the code which uses the custom setting data
GLIntegrationAuthenticationSettings__c GLIntegration = GLIntegrationAuthenticationSettings__c.getAll().get('BizTalk');
String UserName=GLIntegration.User__c;
String Password=GLIntegration.Password__c;
String Biz_Talk_EndPoint=GLIntegration.EndPoint__c;
Class.GlobalComplaintWebSvcCalloutTest.testEchoString: line 51, column 1
GlobalComplaintOutbound outbound= new GlobalComplaintOutbound();
Note: I am using the batch apex to make the callout to external system.
Can you please suggest what i am missing here.
Thanks for the help.
Regards,
Jyo
Looks like you are on the right track. Custom Settings are not available by default so you need to create mock custom settings records as you are doing. However, in your example you posted, you're not inserting a custom setting record that has a Name value of "BizTalk".
Your GlobalCompliantOutbound class is looking for this particular value, and seemingly cannot find it. Try changing:
to:
and see if that fixes your issue.
All Answers
Looks like you are on the right track. Custom Settings are not available by default so you need to create mock custom settings records as you are doing. However, in your example you posted, you're not inserting a custom setting record that has a Name value of "BizTalk".
Your GlobalCompliantOutbound class is looking for this particular value, and seemingly cannot find it. Try changing:
to:
and see if that fixes your issue.