3
  1. I am trying to create a SkillUser through the soap api because dml operations are not allowed but keep getting the following error below.

  2. we plan on placing this code future call to send multiple records in a single call when a user is updated. The soap api call sounds like it would be the best design option since we can only send 1 record at a time through the rest api. if anyone has a better idea that would be great. thank you!

The prefix "soapenv" for element "soapenv:Header" is not bound.

Http h = new Http(); 
HttpRequest req2 = new HttpRequest();
String sfdcBaseURL = System.URL.getSalesforceBaseUrl().toExternalForm();
System.debug('Base URL: ' + sfdcBaseURL ); 
String url = sfdcBaseURL+'/services/Soap/u/33.0';
System.debug(url);
req2.setEndpoint(url);
req2.setHeader('content-type', 'text/xml'); 
req2.setHeader('SOAPAction', '""');
req2.setMethod('POST');
String xml2= '<?xml version="1.0" encoding="utf-8"?>' +
 +'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">' +
 '<soapenv:Header>'+
 '<urn:SessionHeader>'+
  '<urn:sessionId>'+ UserInfo.getSession() +'</urn:sessionId>'+
 '</urn:SessionHeader>'+
    '</soap:Header>' +
 '</soapenv:Header>'+
'<soapenv:Body>'+
     '<urn:create>'+
        '<urn:sObjects xsi:type="SkillUser">'+
           '<UserId>'+ '005j00000045gtyuj' + '</UserId>'+
           '<SkillId>' + '005j000000Crtrtrr' + '</SkillId>'+
        '</urn:sObjects>'+
     '</urn:create>'+
  '</soapenv:Body>'+
  '</soapenv:Envelope>';
req2.setBody(xml2);
HttpResponse res = h.send(req2);
String output = res.getBody();
System.debug('Body contains:' +output);    
1

The error:

The prefix "soapenv" for element "soapenv:Header" is not bound.

is most likely from your XML SOAP body.

The first line of your XML has

<soap:Envelope 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"  
    xmlns:urn="urn:enterprise.soap.sforce.com">

Notice how you have xmlns:soap namespace, but no xmlns:soapenv namespace.

So, you get the error when you try and reference the undefined soapenv namespace with '<soapenv:Header>'+...

0

Replacing soap:Envelope with soapenv:Envelopeshould do the trick.

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.