function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nikhil Garg 17Nikhil Garg 17 

LWC 'Invalid Session ID'

Hi Team

I'm stuck in error actually I'm calling my apex class method using LWC wire call, my apex method using current user session Id. When i'm calling this method using anonymous window it has no error but when I'm calling it using LWC it gives "Invalid Session Id".

Here is my apex method

@auraEnabled(cacheable=true)
    Public static List<String> getMetaDataTypes(){
        
        List<String> metadataTypes = new List<String>();
        try{
            MetadataService.MetadataPort service = new MetadataService.MetadataPort();
             service.SessionHeader = new MetadataService.SessionHeader_element();
             service.SessionHeader.sessionId = UserInfo.getSessionId();

            MetadataService.DescribeMetadataResult describeMetadataResult = service.describeMetadata((double)58.0);
            
            for (MetadataService.DescribeMetadataObject objects : describeMetadataResult.metadataObjects)
            {
                metadataTypes.add(objects.xmlName);
            }
        }
        catch(Exception ex){
            system.debug(ex.getMessage()+' at '+ex.getLineNumber());
        }
        system.debug(metadataTypes);
       // metadataTypes= metadataTypes.sort();
        return metadataTypes;
        
    }

Kindly give me concept of this and suggest me how can I call my method using LWC successfully

Thanks