• Subbeh2
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

Hi,

 

I've been trying to deploy something but I keep getting the following error:

 

Failure Message: "System.NullPointerException: Attempt to de-reference a null object", Failure Stack Trace: "Class.callOut.main: line 70, column 13 External entry point"

 

line 70:

 

 

if (getLead.Web_Form_Source__c.substring(0, 2) == 'X0') {

 code:

 

 

public class callOut {
public static boolean isApexTest=false;
    public static HttpRequest buildWebServiceRequest(String pid, String gid, String pass, String getLead, String password){
        // Build the XML Request
        string body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:reg="http://webservice">' +
                          '<soapenv:Header/>' +
                          '<soapenv:Body>' +
                              '<reg:RegisterUserWithAutoId>' +
                                  '<reg:partnerID>'+pid+'</reg:partnerID>' +
                                  '<reg:partnerGuid>'+gid+'</reg:partnerGuid>' +
                                  '<reg:partnerPassword>'+pass+'</reg:partnerPassword>' +
                                  '<reg:clientName>'+getLead+'</reg:clientName>' +
                                  '<reg:clientPassword>'+password+'</reg:clientPassword>' +
                              '</reg:RegisterUserWithAutoId>' +
                          '</soapenv:Body>' +
                      '</soapenv:Envelope>';
        system.debug(body);

        //construct an HTTP request
        HttpRequest req = new HttpRequest();
        req.setHeader('content-type', 'text/xml; charset=utf-8');
        req.setHeader('Host','mitsweb.iitech.dk');
        req.setEndpoint('http://webservice');
        req.setMethod('POST');
        req.setBody(body); 
        return req;
    }
    
    public static String invokeWebService(Http h, HttpRequest req){
        //Invoke Web Service
        if(!isApexTest)
        {
        try{
        HttpResponse res = h.send(req);
        return res.getBody();
        }
        catch(Exception e){
        throw e;
        }
        }
        else{
        return '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><RegisterUserWithAutoId_testResponse xmlns="webservice"><RegisterUserWithAutoId_testResult><registrationResponse clientid="0" success="True" xmlns=""><clientName value="getLead" success="True" errorCode="0"/><password success="True" errorCode="0"/><loginName value="0" success="True" errorCode="0"/></registrationResponse></RegisterUserWithAutoId_testResult></RegisterUserWithAutoId_testResponse></soap:Body></soap:Envelope>';}
    }
    
    public static void handleWebServiceResponse(string xml, String password, String id){
        //Parse and apply logic to the res message
                    //string xml = res.getBody();
            string xmlRegex = '^.*clientid="';
            pattern xmlPattern = pattern.compile(xmlRegex);
            matcher xmlMatcher = xmlPattern.matcher(xml);
            List<String> result = xml.split(xmlRegex);
            List<String> result2 = result[1].split('\"');
            
            
            Lead getLead = [select id,name,email,Web_Form_Source__c from lead where id = :id];
            
            getLead.ClientPassword__c = password;
            getLead.ClientID__c = result2[0];
            update getLead;
      
            //send email
            SendMail.newLead(getLead.id, getLead.email, getLead.Web_Form_Source__c);          
    }
    
    @Future(callout=true)
    public static void main(Id id){
        
        Lead getLead = [select name,email,Web_Form_Source__c from lead where id = :id];
        
        if (getLead.Web_Form_Source__c.substring(0, 2) == 'X0') {
            string password = EncodingUtil.convertToHex(Crypto.generateDigest('MD5',Blob.valueOf(getLead.name + Crypto.getRandomInteger()))).substring(0, 8);
            
            String pid;
            String gid;
            String pass;
            
            //apply business logic
            if        (getLead.Web_Form_Source__c == 'X00001' || 
                       getLead.Web_Form_Source__c == 'X00002' ||
                       getLead.Web_Form_Source__c == 'X00003') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
            
            // 4293938 Citi Bank Retail 1-2011
            } else if (getLead.Web_Form_Source__c == 'X00014' ||
                      getLead.Web_Form_Source__c == 'X00015' ||
                      getLead.Web_Form_Source__c == 'X00016') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
                         
            // 4293946 Citi Bank Retail 2-2011
            } else if (getLead.Web_Form_Source__c == 'X00017' ||
                      getLead.Web_Form_Source__c == 'X00018' ||
                      getLead.Web_Form_Source__c == 'X00019') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
                         
            // 4293948 Citi Bank Retail3-2011 Fee Based
            } else if (getLead.Web_Form_Source__c == 'X00020' ||
                      getLead.Web_Form_Source__c == 'X00021' ||
                      getLead.Web_Form_Source__c == 'X00022') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
            }
            
            //now need to make web service callout

            //build the http request
            Http h = new Http();
            HttpRequest req = buildWebServiceRequest(pid, gid, pass, getLead.name, password);
   
            //invoke web service call 
            string xmlres = invokeWebService(h, req);
   
            //handling the response
            handleWebServiceResponse(xmlres, password, id);    
        }
    }
    
    static testMethod void testWebService(){
        //build the http request
        isApexTest=true;
        Lead l = new Lead();
        l.Email='test@test.com';
        l.Web_Form_Source__c='X00001';
        l.LastName='LastName';
        insert l;
    }
}

 

Someone please help me, I can't figure out what's wrong.

 

 

 

Hi,

 

I'm struggling to get the following code deployed. It keeps coming with the message "Average test coverage across all Apex Classes and Triggers is 24%, at least 75% test coverage is required"

 

Please give me some help on what to include in the test method.

 

 

public class callOut {
    public static HttpRequest buildWebServiceRequest(String pid, String gid, String pass, String getLead, String password){
        // Build the XML Request
        string body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:reg="http://test">' +
                          '<soapenv:Header/>' +
                          '<soapenv:Body>' +
                              '<reg:RegisterUserWithAutoId_test>' +
                                  '<reg:partnerID>'+pid+'</reg:partnerID>' +
                                  '<reg:partnerGuid>'+gid+'</reg:partnerGuid>' +
                                  '<reg:partnerPassword>'+pass+'</reg:partnerPassword>' +
                                  '<reg:clientName>'+getLead+'</reg:clientName>' +
                                  '<reg:clientPassword>'+password+'</reg:clientPassword>' +
                              '</reg:RegisterUserWithAutoId_test>' +
                          '</soapenv:Body>' +
                      '</soapenv:Envelope>';
        system.debug(body);

        //construct an HTTP request
        HttpRequest req = new HttpRequest();
        req.setHeader('content-type', 'text/xml; charset=utf-8');
        req.setHeader('Host','test');
        req.setEndpoint('http://test');
        req.setMethod('POST');
        req.setBody(body); 
        return req;
    }
    
    public static HttpResponse invokeWebService(Http h, HttpRequest req){
        //Invoke Web Service
        HttpResponse res = h.send(req);
        return res;
    }
    
    public static void handleWebServiceResponse(HttpResponse res, String password, String id){
        //Parse and apply logic to the res message
        if (res.getStatusCode() == 200) {
    
            string xml = res.getBody();
            string xmlRegex = '^.*clientid="';
            pattern xmlPattern = pattern.compile(xmlRegex);
            matcher xmlMatcher = xmlPattern.matcher(xml);
            List<String> result = xml.split(xmlRegex);
            List<String> result2 = result[1].split('\"');
            
            Lead l = new Lead(Id=id);
            List<Lead> getLead = [select name,email,LeadSource from lead where id = :id];
            
            l.ClientPassword__c = password;
            l.ClientID__c = result2[0];
            update l;
      
            //send email
            SendMail.newLead(getLead[0].id, getLead[0].email);
      
            System.debug('Callout body: ' + res.getBody());
        } else {
            System.debug('Callout failed: ' + res);
        } 
    }
    
    @Future(callout=true)
    public static void main(Id id){
    
        //apply business logic
        String pid = '1234';
        String gid = '1234';
        String pass = 'test';
        
        Lead l = new Lead(Id=id);
        List<Lead> getLead = [select name,email,LeadSource from lead where id = :id];
        
        if (getLead[0].LeadSource == 'Web2Lead') {
            string password = EncodingUtil.convertToHex(Crypto.generateDigest('MD5',Blob.valueOf(getLead[0].name + Crypto.getRandomInteger()))).substring(0, 8);
        
            //now need to make web service callout

            //build the http request
            Http h = new Http();
            HttpRequest req = buildWebServiceRequest(pid, gid, pass, getLead[0].name, password);
   
            //invoke web service call 
            HttpResponse res = invokeWebService(h, req);
   
            //handling the response
            handleWebServiceResponse(res, password, id);    
        }
    }
    
    static testMethod void testWebService(){
        //build the http request
        HttpRequest req = buildWebServiceRequest('test', 'test', 'test', 'test', 'test');

        //write apex code to build a sample HttpResponse object
        HttpResponse res = new HttpResponse();

        //Apply test data and attributes to the HttpResponse object as needed
        handleWebServiceResponse(res, 'test', 'test');
    }
}

 

 

  • September 14, 2010
  • Like
  • 0

Hi,

 

I've been trying to deploy something but I keep getting the following error:

 

Failure Message: "System.NullPointerException: Attempt to de-reference a null object", Failure Stack Trace: "Class.callOut.main: line 70, column 13 External entry point"

 

line 70:

 

 

if (getLead.Web_Form_Source__c.substring(0, 2) == 'X0') {

 code:

 

 

public class callOut {
public static boolean isApexTest=false;
    public static HttpRequest buildWebServiceRequest(String pid, String gid, String pass, String getLead, String password){
        // Build the XML Request
        string body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:reg="http://webservice">' +
                          '<soapenv:Header/>' +
                          '<soapenv:Body>' +
                              '<reg:RegisterUserWithAutoId>' +
                                  '<reg:partnerID>'+pid+'</reg:partnerID>' +
                                  '<reg:partnerGuid>'+gid+'</reg:partnerGuid>' +
                                  '<reg:partnerPassword>'+pass+'</reg:partnerPassword>' +
                                  '<reg:clientName>'+getLead+'</reg:clientName>' +
                                  '<reg:clientPassword>'+password+'</reg:clientPassword>' +
                              '</reg:RegisterUserWithAutoId>' +
                          '</soapenv:Body>' +
                      '</soapenv:Envelope>';
        system.debug(body);

        //construct an HTTP request
        HttpRequest req = new HttpRequest();
        req.setHeader('content-type', 'text/xml; charset=utf-8');
        req.setHeader('Host','mitsweb.iitech.dk');
        req.setEndpoint('http://webservice');
        req.setMethod('POST');
        req.setBody(body); 
        return req;
    }
    
    public static String invokeWebService(Http h, HttpRequest req){
        //Invoke Web Service
        if(!isApexTest)
        {
        try{
        HttpResponse res = h.send(req);
        return res.getBody();
        }
        catch(Exception e){
        throw e;
        }
        }
        else{
        return '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><RegisterUserWithAutoId_testResponse xmlns="webservice"><RegisterUserWithAutoId_testResult><registrationResponse clientid="0" success="True" xmlns=""><clientName value="getLead" success="True" errorCode="0"/><password success="True" errorCode="0"/><loginName value="0" success="True" errorCode="0"/></registrationResponse></RegisterUserWithAutoId_testResult></RegisterUserWithAutoId_testResponse></soap:Body></soap:Envelope>';}
    }
    
    public static void handleWebServiceResponse(string xml, String password, String id){
        //Parse and apply logic to the res message
                    //string xml = res.getBody();
            string xmlRegex = '^.*clientid="';
            pattern xmlPattern = pattern.compile(xmlRegex);
            matcher xmlMatcher = xmlPattern.matcher(xml);
            List<String> result = xml.split(xmlRegex);
            List<String> result2 = result[1].split('\"');
            
            
            Lead getLead = [select id,name,email,Web_Form_Source__c from lead where id = :id];
            
            getLead.ClientPassword__c = password;
            getLead.ClientID__c = result2[0];
            update getLead;
      
            //send email
            SendMail.newLead(getLead.id, getLead.email, getLead.Web_Form_Source__c);          
    }
    
    @Future(callout=true)
    public static void main(Id id){
        
        Lead getLead = [select name,email,Web_Form_Source__c from lead where id = :id];
        
        if (getLead.Web_Form_Source__c.substring(0, 2) == 'X0') {
            string password = EncodingUtil.convertToHex(Crypto.generateDigest('MD5',Blob.valueOf(getLead.name + Crypto.getRandomInteger()))).substring(0, 8);
            
            String pid;
            String gid;
            String pass;
            
            //apply business logic
            if        (getLead.Web_Form_Source__c == 'X00001' || 
                       getLead.Web_Form_Source__c == 'X00002' ||
                       getLead.Web_Form_Source__c == 'X00003') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
            
            // 4293938 Citi Bank Retail 1-2011
            } else if (getLead.Web_Form_Source__c == 'X00014' ||
                      getLead.Web_Form_Source__c == 'X00015' ||
                      getLead.Web_Form_Source__c == 'X00016') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
                         
            // 4293946 Citi Bank Retail 2-2011
            } else if (getLead.Web_Form_Source__c == 'X00017' ||
                      getLead.Web_Form_Source__c == 'X00018' ||
                      getLead.Web_Form_Source__c == 'X00019') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
                         
            // 4293948 Citi Bank Retail3-2011 Fee Based
            } else if (getLead.Web_Form_Source__c == 'X00020' ||
                      getLead.Web_Form_Source__c == 'X00021' ||
                      getLead.Web_Form_Source__c == 'X00022') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
            }
            
            //now need to make web service callout

            //build the http request
            Http h = new Http();
            HttpRequest req = buildWebServiceRequest(pid, gid, pass, getLead.name, password);
   
            //invoke web service call 
            string xmlres = invokeWebService(h, req);
   
            //handling the response
            handleWebServiceResponse(xmlres, password, id);    
        }
    }
    
    static testMethod void testWebService(){
        //build the http request
        isApexTest=true;
        Lead l = new Lead();
        l.Email='test@test.com';
        l.Web_Form_Source__c='X00001';
        l.LastName='LastName';
        insert l;
    }
}

 

Someone please help me, I can't figure out what's wrong.

 

 

 

Is it possible to run apex datalader from unix platfom?

 

I have a requirement to schedule a dataloader batch job in a unix platform. How can it be done? 

 

Any solutions will be appreciated.