0
Req :-  Custom Settings :-  Vacancy Media
                Fields:-   Name
                           Type
                           Area
                           Path
        Map -- mapvacancymedia1

i have created a map mapvacanymedia1 in which i am fetching the values from the above custom setting and i need to create an XML file for the same.

But i am geeting error as : SObject row does not allow errors

Please help me to generate the XML for the same.

Code as below.

  if(mapvacanymedia1.size()>0){
                        for(integer i=0;i<=vacancyMediaMapping.size();i++){
                            xmlW.writeStartElement(null,'VacancyMedia',null);
                            xmlW.writeStartElement(null,'Type',null);
                            xmlW.writeCharacters(vacancyMediaMapping.get('Client Logo').Type__c);
                            xmlW.writeStartElement(null,'Area',null);
                            xmlW.writeCharacters(vacancyMediaMapping.get('Job Video').Area__c);
                            xmlW.writeStartElement(null,'Path',null);
                            xmlW.writeCharacters(vacancyMediaMapping.get('Client Video').Path__c);
                            xmlW.writeEndElement();
                            System.debug('Debug at 743');
                        }
                    } 
1
  • Please use relevant tags. This question is not related to salesforce1-app or continuous-integration. – David Reed Jan 17 '19 at 14:27
2

When using a generator, you need to make sure you close all the elements you open (each "writeStartElement" must be paired with a "writeEndElement"). Because this can get complicated, I generally recommend using Dom.Document directly instead of using a generator. There are simply too many things that can go wrong. I don't want to take any presumptions about your data, but if you insist on using the generator, you need to remember to close each element you open.


Example

Dom.Document doc = new Dom.Document();
Dom.XmlNode root = doc.createRootElement('demo',null,null);

...

Dom.XmlNode vacancyMediaNode = root.addChildElement('VacancyMedia',null,null);
Dom.XmlNode typeNode = vacancyMediaNode.addChileElement('Type',null,null);
typeNode.addTextNode(vacancyMediaMapping.get('Client Logo').Type__c);
Dom.XmlNode areaNode = vacancyMediaNode.addChildElement('Area',null,null);
areaNode.addTextNode(vacancyMediaMapping.get('Job Video').Area__c);
Dom.XmlNode pathNode = vacancyMediaNode.addChildElement('Path',null,null);
pathNode.addTextNode(vacancyMediaMapping.get('Client Video').Path__c);

...

String xmlString = doc.toXmlString();
5
  • Thanks !!! can you give me the any example how to use the Dom.Document?? – Abhijeet Kumar Jan 17 '19 at 14:01
  • @AbhijeetKumar you can find example here: Reading and Writing XML Using the DOM – Oleksandr Berehovskyi Jan 17 '19 at 14:05
  • @AbhijeetKumar I added an example that shows how the parts might work. You'll need to do additional work as necessary. – sfdcfox Jan 17 '19 at 14:15
  • Hi Currently i am not allowed to use the Dom.document ....as per project requirement , and after closing all the tab still i am getting the error "SObject row does not allow errors". Please help me out for this one. – Abhijeet Kumar Jan 20 '19 at 2:23
  • @AbhijeetKumar That error is not at all related to this code. Consider asking a new question so it can get appropriate attention. – sfdcfox Jan 20 '19 at 4:21

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.