You need to sign in to do that
Don't have an account?
Vamshi Krishna
Issue with mapping the fields when there is an apex webservice xml response
Apex call out has an xml response.How can I map the fields in Salesforce to the response I receieved. I could map the fields like clean etc. But how could I map fields like make,model, year relatively.
Assume the fields are : Make__c ,Model__c etc.... Considering the XML response.
Apex callout:
*<Year>2011</Year> <Make>Chevrolet</Make> <Model>Suburban</Model>
to the fields in salesforce.
Assume the fields are : Make__c ,Model__c etc.... Considering the XML response.
XML response is: <?xml version="1.0" encoding="UTF-8"?> <result> <vin>xxxxxxxxxxx</vin> <id>xxxxxxxxxxx</id> <date>2018-02-08 05:02:15 PST</date> <specs> <VIN /> *<Year>2011</Year> <Make>Chevrolet</Make> <Model>Suburban</Model>* <Trim>LS 1500</Trim></specs><clean>0</clean> <success>1</success> <error /> </result>
Apex callout:
public PageReference doVinExtract() { HttpRequest httpRequest = new HttpRequest(); httpRequest.setEndpoint('https:/VinProviderxxxx.php'); String body = 'id=01123999999198&key=xxxxxxx&vin=1GNSKHE34BRxxxxxxx&mode=test&user=vxxxxxx&pass=slll4250&format=xml'; httpRequest.setBody(body); httpRequest.setMethod('GET'); Http htt = new hTTP(); HttpResponse httpRe = htt.send(httpRequest); system.debug(httpRe.geTbody()); String re = httpRe.geTbody(); Dom.Document doc = httpRe.getBodyDocument(); Dom.XMLNode address = doc.getRootElement(); String vinDate= address.getChildElement('date', null).getText(); String state = address.getChildElement('specs', null).getText(); // print out specific elements System.debug('address: ' + address); System.debug('state: ' + state); system.debug('result'+re); for(Dom.XMLNode child : address.getChildElements()) { if(child.getName() == 'specs'){ System.debug('******'+child.getText()); } }I was struck and could not map these three fields:
*<Year>2011</Year> <Make>Chevrolet</Make> <Model>Suburban</Model>
to the fields in salesforce.
All Answers