1

Looked over some of the previous posts that may be related, but unfortunately I have no idea about using webservices and XML. Another developer did this class, and it works great in DE org, but as a managed package I get error below. He can't look at for few weeks, but I feel like this is simple...but I'm not getting it. We are just trying to install into our own org right now and not publish on Appexchange so I don't care if items are hardcoded or ugly to start with.

Line 23 of HitQuestion is bolded below. This is ultimately an AWS WSDL.

Apex script unhandled exception by user/organization: Visualforce
Page: /apex/oneout__GenerateHitAuditSetting caused by:
System.XmlException: Prefix cannot be specified if namespace is not specified Class.OneOut.HitQuestion.getQuestionXml: line 23, column 1
Class.OneOut.AMT.GenerateHit: line 181, column 1
Class.OneOut.Mturk_GenerateHitAuditSettingController.Generate: line 42, column 1

public class HitQuestion {

  MTurk__c masterSettings;   
    public  List<String> lstAuditSettingNumber = new List<String>
 {'1','2','3','4','5','6','7','8','9','10','11', '12','13','14','15','16','17','18','19','20'};
      private String QUESTION = 'Ques_Criteria_';   private String QUESTION_AUDIT = 'Question_';
      public String ANSWER = 'Ans_Criteria_';
      public String QUESTION_IDENTIFIER = 'Criteria_';   public String QUESTION_AUDIT_IDENTIFIER = 'Response_';
      public String REQUIRED = 'Required';
      public HitQuestion() {
     this.masterSettings = MTurk__c.getInstance();   }
      public String getQuestionXml(AuditSetting__c setting){
     Dom.Document doc = new Dom.Document();


     // **The line below is throwing the exception**
     Dom.XmlNode questionForm = doc.createRootElement('QuestionForm',masterSettings.Question_Namespace__c,'');

     addInstructions(questionForm,setting);

     for(Integer i = 0; i < lstAuditSettingNumber.size(); i++) {
       String questionValue = String.valueOf(setting.get(QUESTION_AUDIT + lstAuditSettingNumber[i] + '__c'));
       if(questionValue == null || questionValue == '') break;

       String answer = String.valueOf(setting.get(getAuditAnswerKey(lstAuditSettingNumber[i])));

       String answerType = String.valueOf(setting.get(QUESTION_AUDIT + lstAuditSettingNumber[i] + '_Type__c'));

       if(answerType != 'Text' && String.isEmpty(answer)) {
         continue;
       } 

       Boolean isRequired = Boolean.valueOf(setting.get(QUESTION_AUDIT + lstAuditSettingNumber[i] + '_Required__c'));
       //if(answer == null || answer == '') continue;

       Dom.XmlNode question = questionForm.addChildElement('Question',null,null);
       String questionIdentifier = QUESTION_AUDIT_IDENTIFIER + lstAuditSettingNumber[i] + '__c';
       AddQuestionDetails(question,questionValue,answer,questionIdentifier,answerType,isRequired);
     }
     return doc.toXmlString();    }
     public void addInstructions(Dom.XmlNode questionForm,AuditSetting__c setting){
      if(setting.Instructions__c != null) {
        Dom.XmlNode ndOverview = questionForm.addChildElement('Overview', null,null);
        ndOverview.addChildElement('Text',null,null).addTextNode(setting.Instructions__c);
      }
0

So the line in question is:

Dom.XmlNode questionForm =   
    doc.createRootElement('QuestionForm',masterSettings.Question_Namespace__c,'');

I think the issue here is the empty string being passed as the third parameter to createRootElement when masterSettings.Question_Namespace__c is null or empty.

Try using null instead of the empty string for the third parameter.

|improve this answer|||||
  • Did change error but basically still same issue. caused by: System.NullPointerException: Argument cannot be null. Class.OneOut.AMT.GenerateSignature: line 347, column 1 Class.OneOut.AMT.GenerateHit: line 196, column 1 Class.OneOut.Mturk_GenerateHitAuditSettingController.Generate: line 42, column 1 – ddeve May 27 '14 at 2:44
  • 1
    Is it possible that masterSettings is null? – Daniel Ballinger May 27 '14 at 3:34
  • 1
    @user2451 or masterSettings.Question_Namespace__c is null? – Daniel Ballinger May 27 '14 at 3:56
  • masterSettings was null. Adding the class to populate the Custom Setting where this was contained resolved all the errors. – ddeve May 27 '14 at 15:12

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.