Whenever i am calling CampaignMember.getSobjectType() method , getting nullpointer exception. I tried to debug the CampaignMember object but getting null value object as well. Marketing User checkbox is checked on user record.

  • 1
    As you mentioned you are getting null value for the campaignmember object as well, trying to call a method on null returns nullpointer exception. Try to figure out why you are getting campaignmember object as null. – Vigneshwaran G Jul 23 '15 at 7:26

If you have a local variable or field in your class called CampaignMember (case doesn't matter in Apex) that will shadow (hide) the SObject type name and generate the NPE is it is null at that point in the code.

A quick fix is to use:


But probably best to change the name of the variable or field.

| improve this answer | |

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.