-2

I'm trying to deploy/validate a class but getting this error, even though the class is working in the sandbox.

Method does not exist or incorrect signature void buildHTTPRequest(String,String,String,String) 
from the type HTTPRequestBuilder

It's coming from this class :

public with sharing class Http_Utility_Pardot {
    

    public static String login(Pardot_Tracking_Configuration__mdt pardotTrackingConfig) {
        
        String requestBody = 'email=' + EncodingUtil.urlEncode(pardotTrackingConfig.UserName__c, Constants.UTF_8)
                                + '&password=' + EncodingUtil.urlEncode(pardotTrackingConfig.Passward__c, Constants.UTF_8)
                                + '&user_key=' + EncodingUtil.urlEncode(pardotTrackingConfig.User_Key__c, Constants.UTF_8);

        
        HttpRequest request = new HttpRequest();
        request.setEndpoint('callout:APEX_Pardot_Credential/account/version/4/do/read');        
        request.setHeader('Pardot-Business-Unit-Id', '0Uv2J000000CaWgX13');
        
        request.setMethod('POST');
        
        HttpResponse response = HTTPService.send(request);
        
        return HTTPResponseParser.parseLoginResponse(response);
        
    }

    public static String pardotCreateProspect(Set<Id> contactIds) {
        

        List<Pardot_Tracking_Configuration__mdt> pardotTrackingConfigs = [SELECT Id, Login_URL__c, UserName__c, Passward__c, User_Key__c,
                                                                            Email_Tracking_URL__c, Create_Prospect_Endpoint__c, Batch_Create_Prospect_Endpoint__c
                                                                            FROM Pardot_Tracking_Configuration__mdt WHERE DeveloperName = 'Pardot_Tracking_Data'];
        
        if(pardotTrackingConfigs.size() == 0)
            return System.Label.Pardot_Error_PTC_Not_Defined;
        
        
        String apiKey = login(pardotTrackingConfigs[0]);
        if(contactIds.size() == 0)
            return System.Label.Pardot_Error_Contact_Id_Missing;
            
        // Querying the particular Contact details for the creation of Prospect record  
        List<Contact> contacts = [SELECT Id, Email, FirstName, LastName, OwnerId FROM Contact WHERE Id =: contactIds];
        if(contacts.size() == 0)
            return System.Label.Pardot_Error_Invalid_Contact;

            String endpoint;
            String requestBody;            

            Map<String, String> headerParameters= new Map<String, String>{'Pardot-Business-Unit-Id' => '0Uv2J000000CaWgX13'};
            
           if(contacts.size() == 1){  
                Contact contactRecord = contacts[0];  

            endpoint = 'callout:APEX_Pardot_Credential/prospect/version/4/do/create/email/' + contactRecord.Email;
            requestBody = 'first_name=' + EncodingUtil.urlEncode(contactRecord.FirstName,Constants.UTF_8)
                                    + '&last_name=' + EncodingUtil.urlEncode(contactRecord.LastName,Constants.UTF_8)
                                    + '&email=' + EncodingUtil.urlEncode(contactRecord.Email,Constants.UTF_8);
                                    //+ '&crm_owner_fid=' + contactRecord.OwnerId;

        } else {
        
            endpoint = pardotTrackingConfigs[0].Batch_Create_Prospect_Endpoint__c;
            requestBody = '';
            for(Contact contactRecord:contacts){
                                                        
                requestBody = requestBody +'{"email":"' + EncodingUtil.urlEncode(contactRecord.Email,Constants.UTF_8) 
                                          + '","first_name":"'+ EncodingUtil.urlEncode(contactRecord.FirstName,Constants.UTF_8) 
                                          + '","last_name":"'+ EncodingUtil.urlEncode(contactRecord.LastName,Constants.UTF_8)                                           + '",},';

                }
                
                requestBody = 'prospects={"prospects":['+ requestBody.removeEnd(',')+']}';
        }       
        
        **HttpRequest request= HTTPRequestBuilder.buildHTTPRequest(endpoint, Constants.POST,
                                                                        Constants.APPLICATIONX_WWW_FORM_URLENCODED,
                                                                        requestBody);
        request.setHeader('Pardot-Business-Unit-Id', '0Uv2J000000CaWgX13');**
        
        HttpResponse response = HTTPService.send(request);
        return HTTPResponseParser.parseCreateRecordResponse(response);
    }
}

And this is the class it is referencing, which has that buildHTTPRequest method :

public class HTTPRequestBuilder {    public static HttpRequest createSky(String endPoint, String requestBody){


        HttpRequest request = new HttpRequest();
        request.setEndpoint(endPoint);
        request.setMethod('POST');
        request.setHeader('Content-Type','application/json');
        request.setBody(requestBody);
    system.debug(request);
        return request;
    }
    
    public static HttpRequest buildHTTPRequest(String endPoint, String methodType, String contentType, 
                                            Map<String, String> headerParameters, String requestBody) {

        HttpRequest request = new HttpRequest();
        request.setEndpoint(endPoint);
        request.setMethod(methodType);
        request.setHeader('content-type', contentType);

        if(headerParameters != null) {
            for(String headerKey: headerParameters.keySet()) {
                
                request.setHeader(headerKey, headerParameters.get(headerKey));
            }
        }
        request.setBody(requestBody);
        return request;
    }
}

Any ideas on what is causing this ? Thank you.

2
  • 3
    Seems pretty clear. You're trying to call buildHTTPRequest(String, String, String, String) but the signature your HTTPRequestBuilder has is buildHTTPRequest(String, String, String, Map<String, String>, String). Your call is missing the 4th parameter (Map<String, String>). Either your usage is wrong or you've made an update to HTTPRequestBuilder that needs to be deployed as well.
    – Derek F
    Oct 25 '21 at 19:41
  • @DerekF - thank you so much. I guess I'm going to have to write a whole test class for this ? I'm looking through the whole library and there isn't one (and this is code that is already deployed). Do you know of any examples I could reference to see fitting test classes for this ? Thanks again.
    – Zoom_v
    Oct 25 '21 at 21:18
2

You are not passing all the parameters that are required to the buildHTTPRequest() method. You are not including the headerParameters. That's why you get the compilation error.

2
  • So do I have to write a whole test class for HTTPRequestBuilder ? Can you give me an example of something I could use to get me started on it ? Thanks !
    – Zoom_v
    Oct 25 '21 at 21:19
  • In case there is no class covering it, yes, you should write a test class for that class but I don't see the relation between the initial question and this one. About how to test a class that performs an external callout, you can check out the following Trailhead Unit which explains exactly what you need trailhead.salesforce.com/en/content/learn/modules/… Oct 26 '21 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.