0

im having trouble getting the output from my webservice which was based in an wsdl generated apex class, it brings through a simple string 'D2978' which will need to be added to a new custom field called invoiceNumber__c everytime a commandbutton is pressed however im getting "attempted to de-reference null object

 public String getInvoiceNumber(String invoicenumberid) {
        ws_GenerateInvoiceNumber.invoicenumberServiceSearchQuery_element request_x = new ws_GenerateInvoiceNumber.invoicenumberServiceSearchQuery_element();
        request_x.invoicenumberid = invoicenumberid;
        ws_GenerateInvoiceNumber.invoicenumberServiceResponse_element response_x;
        Map<String, ws_GenerateInvoiceNumber.invoicenumberServiceResponse_element> response_map_x = new Map<String, ws_GenerateInvoiceNumber.invoicenumberServiceResponse_element>();
        response_map_x.put('response_x', response_x);
        WebServiceCallout.invoke(
          this,
          request_x,
          response_map_x,
          new String[]{endpoint_x,

im then referencing this in an apex class to move the string to the custom field however this is where i think im going wrong any pointers would be huge help getting very frustrated at this

        private static string callWebservice(String invoicenumberid ){
        ws_GenerateInvoiceNumber.InvoiceNumberSearchServicePort soapService = new ws_GenerateInvoiceNumber.InvoiceNumberSearchServicePort();
        string response = soapService.getInvoiceNumber( invoicenumberid);
    return response;
}

    private static string callWebserviceUpdate(String invoicenumberid ){
        ws_GenerateInvoiceNumber.InvoiceNumberSearchServicePort soapService = new ws_GenerateInvoiceNumber.InvoiceNumberSearchServicePort();
        string response = soapService.incrementupdateInvoiceNumber(invoicenumberid);
    return response;
}

    public void InvoiceNumberView (String projectId) {
        this.Project = [SELECT Id, Name, InvoiceNumber__c FROM Project__c WHERE Id =: projectId];

        // callWebservice(String invoicenumberid);
        // callWebservice(string response);
         string response = Project.InvoiceNumber__c ;
        // string response =  callWebservice(String.valueof(this.project.invoicenumber__c));
        // string response;
        // Project.InvoiceNumber__c = response;


    update project;
}
10
  • Can you show the declaration of this.Project please ?
    – SF_user
    Aug 12, 2014 at 8:27
  • String ProjectId {get;set;} this.Project = [SELECT Id, Name, InvoiceNumber__c FROM Project__c WHERE Id =: projectId]; Aug 12, 2014 at 8:28
  • Yes, that I saw it in your code, but what's the type of Project ?
    – SF_user
    Aug 12, 2014 at 8:29
  • ahh sorry Project is a custom object protected project__c Project; Aug 12, 2014 at 8:30
  • Did you check with the developer console that your query return a result ?
    – SF_user
    Aug 12, 2014 at 8:33

2 Answers 2

0

Where you catch the exception, use the getLineNumber() and getStackTraceString() methods to determine the location of the NullPointerException.

Then examine the line in question to find the variables that could possibly be null.

If there are more than one, use something like the following immediately before the line that threw the exception.

System.assertNotEquals(null, variableThatMightBeNull, 'variableThatMightBeNull was the issue!');
3
  • rookie mistake: didnt put the apex class in the constructor there was a wsdl error :) Aug 12, 2014 at 13:08
  • @ClevelandDan I'm glad you've got it sorted. I didn't see any constructor in the question. Are you able to post and accept your own answer? It will be helpful to anyone else who comes across this question and will show that it has been resolved. Aug 12, 2014 at 19:49
  • Yeah no problem Aug 13, 2014 at 12:17
0
    public vf_projectComplete(){
    this.project = [SELECT Id, Name, InvoiceNumber__c, updateBoolean__c  
                    FROM Project__c
                    WHERE Id =: projectId];
    GINC = new GenerateInvoiceNumberController(this.project.Id);
    this.productOrders = [SELECT Id, Name, Product__r.DisplayName__c, Complete__c 
                          FROM ProductOrder__c 
                          WHERE Project__c =: this.projectId];
}

i forgot to add the controller to the constructor this then found an error which was sorted in my wsdl

You must log in to answer this question.

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