locked
webservice create campaignreponse throw error: Object reference not set to an instance of an object. RRS feed

  • Question

  • Hi,
    I use asp.net to create the campaign response throw webservice:
    But it throws error: Object reference not set to an instance of an object.
    And when i go to CRM. i do found all the reponses are created.  I just don't know why it throw error if it could be created, and where is the problem?
    anybody could help? thanks a lot.

    here is the code.

    campaignresponse response = new campaignresponse();
            response.regardingobjectid = new Lookup();
            response.regardingobjectid.Value = campaign.campaignid.Value;
            response.responsecode = new Picklist();
            response.responsecode.Value = 1; // interested

            response.gp_referringphysician = physician_id;
            response.gp_contactid = new Lookup();
            response.gp_contactid.Value = patient.leadid.Value;
            activityparty party = new activityparty();
            party.partyid = new Lookup();
            party.partyid.type = "lead";
            party.partyid.Value = patient.leadid.Value;
            response.customer = new activityparty[] { party };
            response.subject = subject;
            response.description = desc;
            response.channeltypecode = new Picklist();
            response.channeltypecode.Value = 6;//web
            response.receivedon = new CrmDateTime();
            response.receivedon.Value = DateTime.Now.ToString("MM/dd/yyyy");
    service.Create(response)
    Friday, October 16, 2009 5:37 PM

Answers

  • Oh..Ok..this is fine then....I guess CRM will throw "Object reference not set to an instance of an object." if some of the source entity (campaign or lead ) does not exist on the crm side..check if these records exist in crm and you able to do similair kind of operation through CRM UI..

    but again...as you said "Object reference not set to an instance of an object." is generic error and you will not get clear indication on how to resolve it..
    Friday, October 16, 2009 8:59 PM

All replies

  • can you able to debug the record which throws the error ..

    I guess error is coming after campaign response is created successfully ...is there any code after the lines you put in your question ...?

     


     

    Friday, October 16, 2009 7:27 PM
  • there is no line after create. when i debugger, the error from the create line.

    But i think i find where is the problem. The problem is from our CRM.
    i wrote campaign response for different entity's couple days ago and it's successful.
    I test that piece of code today again  and the old code throw same error as this one.

    So our CRM guy must changed some settings of campaignresponse. when i create campaign response, the CRM do something else and cause the problem. 

    The problem is unknown, but i will check with our CRM guy first for what he changed.
    Friday, October 16, 2009 7:48 PM
  • if problem with CRM side...then you will receive error message from crm side...like "Server was unable to process request." ...but since you are getting exception Object reference not set to an instance of an object.

    I suggest check the "service" and "response" object and make sure they are not null...

    anyways, if all this objects are fine then problem is definately with CRM...

    Friday, October 16, 2009 8:03 PM
  • yes. the CRM do throw error as: Server was unable to process request.


    but i want to get detail error message instead of generic CRM msg.  so I use catch SOAPException.Detail.InnerXml   which shows me error as
    Object reference not set to an instance of an object.

    usually, i could get meaningful error by get SOAPExcetpion and know how to fix it, but not his time
    Friday, October 16, 2009 8:50 PM
  • Oh..Ok..this is fine then....I guess CRM will throw "Object reference not set to an instance of an object." if some of the source entity (campaign or lead ) does not exist on the crm side..check if these records exist in crm and you able to do similair kind of operation through CRM UI..

    but again...as you said "Object reference not set to an instance of an object." is generic error and you will not get clear indication on how to resolve it..
    Friday, October 16, 2009 8:59 PM