• Ravi_Panchal
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,

I am trying to consume Metadata API of one salesforce org to another org and trying to create custom field.

When i execute below code from developer console, i receive error saying : "System.CalloutException: 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".

Code :
*****************************************************************************************************
MetadataService.MetadataPort service = createService();   
    MetadataService.CustomField customField = new MetadataService.CustomField();
    customField.fullName = 'Contact.TestField__c';
    customField.label = 'Test Field';
    customField.type_x = 'Text';
    customField.length = 42;
    MetadataService.AsyncResult[] results = service.create(
    new List<MetadataService.Metadata> { customField });

public static MetadataService.MetadataPort createService()
{
    partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();

    partnerSoapSforceCom.LoginResult loginResult = sp.login('username','password');

    MetadataService.MetadataPort service = new MetadataService.MetadataPort();
    service.SessionHeader = new MetadataService.SessionHeader_element();
    service.SessionHeader.sessionId = loginResult.sessionId;
    System.debug(service.SessionHeader.sessionId);
    return service;    
}

*********************************************************************************
Hi,

I am trying to consume Metadata API of one salesforce org to another org and trying to create custom field.

When i execute below code from developer console, i receive error saying : "System.CalloutException: 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".

Code :
*****************************************************************************************************
MetadataService.MetadataPort service = createService();   
    MetadataService.CustomField customField = new MetadataService.CustomField();
    customField.fullName = 'Contact.TestField__c';
    customField.label = 'Test Field';
    customField.type_x = 'Text';
    customField.length = 42;
    MetadataService.AsyncResult[] results = service.create(
    new List<MetadataService.Metadata> { customField });

public static MetadataService.MetadataPort createService()
{
    partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();

    partnerSoapSforceCom.LoginResult loginResult = sp.login('username','password');

    MetadataService.MetadataPort service = new MetadataService.MetadataPort();
    service.SessionHeader = new MetadataService.SessionHeader_element();
    service.SessionHeader.sessionId = loginResult.sessionId;
    System.debug(service.SessionHeader.sessionId);
    return service;    
}

*********************************************************************************