4

To update a picklist value I'm referring to the metadataclass.cls

I'm calling a class method (as like in metadadataclass example) to update the picklist value via a trigger (class method set to @Future(callout=true)) which seems to work but in the log i get an error as below:

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=

Please any help on to fix this error so that i would be able to update the picklist value for the picklist list (custom field)?

1 Answer 1

6

UserInfo.getSessionId() returns null in asynchronous contexts so you have to pass the session ID in when you call the future method:

public class PicklistUpdater {

    public static void updateInFuture() {
        updateInFuture(UserInfo.getSessionId());
    }

    @future(callout=true)
    private static void updateInFuture(String sessionId) {
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = sessionId;
        service ...
    }
}

Not sure how high the risk is of the session ID no longer being valid by the time the future executes.

2
  • Unless the user explicitly logs out before it runs, it should be okay, unless the action be queued longer than the session timeout value of the org. In most cases, this threat is virtually nil.
    – sfdcfox
    Nov 3, 2015 at 3:54
  • Thanks Keith, it worked! I'm having a different error now...but will post it in a separate thread...thank you Nov 3, 2015 at 10:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .