You need to sign in to do that
Don't have an account?
Save error: Illegal assignment from String to Boolean when parsing SOAP XML
Dear Gurus,
I have an Apex class that makes a web service call out. I am using Ron Hess's XML DOM class to help parse the SOAP XML. I am runningn into an issue when obtaining strings from the serivce parameter and trying to assign it to a boolean value in Salesforce. I am looking for advise in what I need to do to allow the assignment of the return value.
The value in the Salesforce data base is a boolean value. The service returns a .NET boolean value. Currently I get the following error when saving my Apex class at compile time.
"Save error: Illegal assignment from String to Boolean." Error is happening for the follwoing line of code. The d parameter is the XMLDOM response.
ua.Open_Service_Orders__c = d.getElementsByTagName('OpenServiceOrders')[0].nodeValue;
Thanks in advance,
Dodi
All Answers
That appears to work. Thanks!
Hi Dodi,
Can u please explain me how u r parsing xml by using Ron Hess's XML DOM class?
Where i usually do it with XMLStreamReader class....Its very time consuming....
Regards,
Shravan
Sure, posting my code below which uses the class. I started to get errors with the class when parsing complex nested elements. There were govenror exceptions thrown(Script Limit)...But those exceptions were being generated in the XML Dom class. But it works for single element responses fine.
global class EnrichUANInfo {
//------------------------------------------------------------
// UPDATES AN INDIVIDUAL UTILTIY ACCOUNT
// Parameter(s):Utility Account's SFDC Id and
// Utility Account Number
//------------------------------------------------------------
webService static String enrichSingleUAN(Id uanRecordId, String uanNumber) {
string username = 'Fahd';
string password = 'mypwd';
string soapXML;
xmldom d;
string address;
string unit;
string city;
string state;
string zipCode;
string duns;
string meterReadCycle;
string premiseType;
string powerRegion;
string stationCode;
string stationName;
string metered;
string openServiceOrders;
string tdsp;
string csp;
string cspStatus;
string zone;
string meterTampering;
map<string,string> utility_map = new map<string,string>();
List<Utility__c> list_utility = [SELECT Id, Name, LDC_Code__c FROM Utility__c];
for(Utility__c util : list_utility){
utility_map.put(util.LDC_Code__c, util.Id);
}
//building a SOAP XML with Utility Account Id and Number
soapXML = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:gex="http://gexaenergy.com/"><soap:Header/><soap:Body><gex:GetDataFromEsiID><!--Optional:--><!--Optional:--><gex:userid>' + username + '</gex:userid><!--Optional:--><gex:password>' + password + '</gex:password><!--Optional:--><gex:applicationName>any</gex:applicationName><gex:esiid>' + uanNumber + '</gex:esiid></gex:GetDataFromEsiID></soap:Body></soap:Envelope>';
Integer ContentLength = 0;
ContentLength = SoapXML.length();
HttpRequest req = new HttpRequest();
HttpResponse res = null;
req.setMethod('GET');
Http h = new Http();
req.setEndpoint('https://yourendpoint.asmx');
req.setHeader('Content-type','text/xml');
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
req.setTimeout(100000);
req.setBody(soapXML);
System.Debug(req);
System.Debug('Request Body is = ' + req.getBody());
//makes the webservice call
res = h.send(req);
String response = res.getBody();
System.debug('Response Body is = ' + response);
//processing the webservice response
d = new xmldom(response);
Utility_Account__c ua;
ua = [Select u.Station_Name__c, u.Station_Code__c, u.Service_Zip_Code__c, u.Service_Street__c, u.Service_State__c, u.Service_City__c, u.Premise_Type__c, u.Power_Region__c, u.Open_Service_Orders__c, u.Metered__c, u.Meter_Read_Cycle__c, u.DUNS_Number__c, u.CSP__c, u.CSP_Status__c, u.Utility__c From Utility_Account__c u WHERE u.id = :uanRecordId];
//update individual uan with values from web service
if(ua.Service_Street__c == null) ua.Service_Street__c = d.getElementsByTagName('Address')[0].nodeValue;
if(ua.Service_City__c == null) ua.Service_City__c = d.getElementsByTagName('City')[0].nodeValue;
if(ua.Service_State__c == null) ua.Service_State__c = d.getElementsByTagName('State')[0].nodeValue;
if(ua.Service_Zip_Code__c == null) ua.Service_Zip_Code__c = d.getElementsByTagName('ZipCode')[0].nodeValue;
if(ua.DUNS_Number__c == null) ua.DUNS_Number__c = d.getElementsByTagName('DUNS')[0].nodeValue;
if(ua.Meter_Read_Cycle__c == null) ua.Meter_Read_Cycle__c = d.getElementsByTagName('MeterReadCycle')[0].nodeValue;
if(ua.Premise_Type__c == null) ua.Premise_Type__c = d.getElementsByTagName('PremiseType')[0].nodeValue;
if(ua.Power_Region__c == null) ua.Power_Region__c = d.getElementsByTagName('PowerRegion')[0].nodeValue;
if(ua.Station_Code__c == null) ua.Station_Code__c = d.getElementsByTagName('StationCode')[0].nodeValue;
if(ua.Station_Name__c == null) ua.Station_Name__c = d.getElementsByTagName('StationName')[0].nodeValue;
if(ua.Metered__c == null) ua.Metered__c = d.getElementsByTagName('Metered')[0].nodeValue;
if(ua.Open_Service_Orders__c == null) ua.Open_Service_Orders__c = Boolean.valueOf(d.getElementsByTagName('OpenServiceOrders')[0].nodeValue);
if(ua.Utility__c == null) ua.Utility__c = utility_map.get(d.getElementsByTagName('TDSP')[0].nodeValue);
if(ua.CSP__c == null) ua.CSP__c = d.getElementsByTagName('CSP')[0].nodeValue;
if(ua.CSP_Status__c == null) ua.CSP_Status__c = d.getElementsByTagName('CSPStatus')[0].nodeValue;
if(ua.Zone__c == null) ua.Zone__c = d.getElementsByTagName('Zone')[0].nodeValue;
if(ua.Service_County__c == null) ua.Service_County__c = d.getElementsByTagName('County')[0].nodeValue;
if(ua.Meter_Tampering__c == null) ua.Meter_Tampering__c = Boolean.valueOf(d.getElementsByTagName('MeterTampering')[0].nodeValue);
//update table
upsert ua;
return response;
}
Forgot to mention the work around for parsing of the response xml when there was a list of responses was to move the actual parsing of the respone to the browser and use the browsers XML parser. In our case it was the Microsoft DOM.
Thanks for sharing Dodi. It will be helpful for me.........
Regards,
Shravan