You need to sign in to do that
Don't have an account?
Robin Barnwell 3
JSON Class Assignment
I'm integrating Salesforce with Mailchimp as the default connecting isn't doing what I need. I've created a simple class to hold the REST Body
public class MailChimpSubscriberJson{
public class Merge_fields {
public String FNAME;
public String LNAME;
}
public class JSON2Apex {
public String id;
public String email_address;
public String status;
public Merge_fields merge_fields;
}
}
But my assignment works for apart of the sub-class, Merge_fields. Specifically this line of code is wrong, but I can't see why. There is data in the Firstname.
Subscriber.merge_fields.FNAME=MailchimpContact[0].Firstname;
I'm getting this error, common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object. I can only think Subscriber.merge_fields.FNAME is incorrect.
public class MailChimpSubscriberJson{
public class Merge_fields {
public String FNAME;
public String LNAME;
}
public class JSON2Apex {
public String id;
public String email_address;
public String status;
public Merge_fields merge_fields;
}
}
But my assignment works for apart of the sub-class, Merge_fields. Specifically this line of code is wrong, but I can't see why. There is data in the Firstname.
Subscriber.merge_fields.FNAME=MailchimpContact[0].Firstname;
I'm getting this error, common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object. I can only think Subscriber.merge_fields.FNAME is incorrect.
public class MailChimpSubscriberJson{
public class Merge_fields {
public String FNAME;
public String LNAME;
}
public class JSON2Apex {
public String id;
public String email_address;
public String status;
public Merge_fields merge_fields = new Merge_fields();
}
public static JSON2Apex parse(String json) {
return (JSON2Apex) System.JSON.deserialize(json, JSON2Apex.class);
}
}
I'll make contact with the authors to see what they think. Either way we've solved the problem.