-3

How We can Write Test Class for this Method.

public static String authMethod(){
            Pardot_Credential_Setting__c objSetting = customSetting();

            if(objSetting != null){
                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;
        }
0

1 Answer 1

1

Do you read this module:

https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_rest_callouts

It's a perfect start of research related with the topic of Integration Services and bring excellent recommendation and best practice.

Not the answer you're looking for? Browse other questions tagged .