2

I am creating sample example from http://andyinthecloud.com/2013/10/27/introduction-to-calling-the-metadata-api-from-apex/

I am getting following exception on Click of the button

Whats wrong?

Web service callout failed: WebService returned a SOAP Fault: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session faultcode=sf:INVALID_SESSION_ID faultactor=

Request XML:-

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <env:Header>
        <SessionHeader xmlns="http://soap.sforce.com/2006/04/metadata">
            <sessionId>00Di0000000kMtH!ARAAQC8gQUuNLICckL_8RNTs.cekDai6jQOAFR_Bj0durQozIiuBPikPce2xyDP5KnlS6JE_W2ihvsVRbih6DPsyMn9ETdy7</sessionId>
        </SessionHeader>
    </env:Header>
    <env:Body>
        <create xmlns="http://soap.sforce.com/2006/04/metadata">
            <metadata xsi:type="CustomField">
                <fullName>Activity__c.TestField__c</fullName>
                <label>Test Field</label>
                <length>42</length>
                <type>Text</type>
            </metadata>
        </create>
    </env:Body>
</env:Envelope>
  • how did you retrieve the session ID? – Guy Clairbois Apr 4 '14 at 13:59
  • @guy like this- service.SessionHeader.sessionId = UserInfo.getSessionId(); – Ganesh Bhosle Apr 4 '14 at 14:00
  • does your user have API access enabled? – Guy Clairbois Apr 4 '14 at 14:27
  • 1
    The code should be defaulting to your local Salesforce instance using URL.getSalesforceBaseUrl(), but are you trying to connect to an external Salesforce org by chance? – James Loghry Apr 4 '14 at 15:20
  • Yep agree with @JamesLoghry in absence of more info, this would be my bet also. – Andrew Fawcett Apr 4 '14 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.