I have a JSON String Need to pass as request body with configurabale parameter as below.I have used a wrapper class for that called as EmailWrapper , but here assign value to wrapper.options.fieldOne ,throw Attempt to de-reference a null object but threatMapping.Field1__c has value. I think I have access wrapper in incorrect way. Can someone help me on this?
public with sharing class TestValid {
@AuraEnabled(cacheable=true)
public static void emailValidation(String email){
EmailOptionAttributes emailOptions = new EmailOptionAttributes();
EmailWrapper wrapper = new EmailWrapper();
System.debug('email====-: ' +email);
if(email != null){
System.debug('email====-: ' +email);
wrapper.emailValue = email;
System.debug('email2====-: ' +email);
}
Email_validation__mdt[] emailValidation = [SELECT Field1__c,Field2__c,Field3__c,Field4__c,Field5__c FROM Email_validation__mdt];
System.debug('emailValidation' +emailValidation);
for (Email_validation__mdt threatMapping : emailValidation) {
wrapper.options.fieldOne = threatMapping.Field1__c;
wrapper.options.fieldTwo = threatMapping.Field2__c;
wrapper.options.fieldThree = threatMapping.Field3__c;
wrapper.options.fieldFour = threatMapping.Field4__c;
wrapper.options.fieldFive = threatMapping.Field5__c;
}
System.debug('emailOptions: ' +emailOptions);
String jsonString = JSON.serialize(emailOptions);
System.debug('jsonString: ' +jsonString);
}
public class EmailOptionAttributes {
public Boolean fieldOne;
public Boolean fieldTwo;
public Boolean fieldThree;
public Boolean fieldFour;
public Boolean fieldFive;
}
public class EmailWrapper{
public String emailValue;
public EmailOptionAttributes options;
}
}
wrapper.options = emailOptions
before you try to set the option field values.