You need to sign in to do that
Don't have an account?
Bablu Kumar Pandit
Test class Not cover when access Recode from custom setting
//Controller Class Please Any one Help Pardot_Credential_Setting__c is Custom Setting public class pardotActivityController{ public static Pardot_Credential_Setting__c customSetting(){ Pardot_Credential_Setting__c objSetting = Pardot_Credential_Setting__c.getValues('Pardot Access'); if(objSetting != null && objSetting.Sync_disabled__c == false){ return objSetting; } return null; } public static String authMethod(){ Pardot_Credential_Setting__c objSetting = customSetting(); if(objSetting != null){ <----Not Covering --------> String email = objSetting.Pardot_Email__c; String password = objSetting.Pardot_Password__c; String userKey = objSetting.User_Api_Key__c; HttpRequest req = new HttpRequest(); req.setEndpoint( objSetting.Pardot_BaseUrl__c+'/api/login/version/4' ); req.setMethod( 'POST' ); req.setBody( 'email=' + email + '&password=' + password + '&user_key=' + userKey ); HttpResponse res = new Http().send( req ); System.debug('>>>>>>>>res'+ res ); System.debug('>>>>>>>>>res.getStatus()'+ res.getStatus() ); System.debug('>>>>>>res.getBody()'+ res.getBody() ); String response = res.getBody(); Integer startIdx; Integer endIdx; String apiKey; if(response.contains('<api_key>')){ startIdx = response.indexOf( '<api_key>' ) + 9; endIdx = response.indexOf( '</api_key>' ); apiKey = response.substring( startIdx, endIdx ); System.debug( '>>>>>>>apiKey'+ apiKey ); return apiKey; } } return null; } } <------Test class-------> static Testmethod void authMethodTest(){ Pardot_Credential_Setting__c objSetting = New Pardot_Credential_Setting__c(); objSetting.Name = 'Test'; objSetting.Pardot_Email__c = 'abc@gmail.com'; objSetting.User_Api_Key__c = '<api_key>'; objSetting.Pardot_BaseUrl__c = 'https://pi.pardot.com/api/login/version/4'; objSetting.Pardot_Password__c = 'test12'; objSetting.Sync_disabled__c = false; insert objsetting; Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator()); test.startTest(); pardotActivityController.authMethod(); test.stopTest(); } public class MockHttpResponseGenerator implements HttpCalloutMock{ //Http callout class for authmothod public HTTPResponse respond(HTTPRequest req){ String json= '{'+ ' "EMail": "leadsscotia@culliganwaterco.com",'+ ' "Password": "<api_key>,'+ ' "Userkey": "</api_key>",'+ '}'; System.assertEquals('https://pi.pardot.com/api/login/version/4', req.getEndpoint()); System.assertEquals('POST', req.getMethod()); //make a fake responce HttpResponse res = new HttpResponse(); res.setBody(json); res.setStatusCode(200); return res; } }
If you solve this issue with that fix then please mark as correct. If it is not working try using Pardot_Credential_Setting__c objSetting = Pardot_Credential_Setting__c.getall().values(); and you will pass line 17.
Please also mark my answer on your other question as correct, it is a reward for the time helping others.
Good luck
All Answers
Looking this where are you setting a value Pardot Access? Maybe thats because you are not retrieving anything.
see the code Line no. 17 not covering after line number 17
so please guide me where i am mistake,How i correct
If you solve this issue with that fix then please mark as correct. If it is not working try using Pardot_Credential_Setting__c objSetting = Pardot_Credential_Setting__c.getall().values(); and you will pass line 17.
Please also mark my answer on your other question as correct, it is a reward for the time helping others.
Good luck
Great bablu, if you can please mark as correct my comment on your previous question so it can be closed and help any other having the same inquiry.
Good luck