@@ -65,11 +65,11 @@ class ClientContext:
6565
6666 org : Org
6767 """Information about the Salesforce org and the user that made the request."""
68- data_api : DataAPI
69- """An initialized data API client instance for interacting with data in the org."""
68+ data_api : DataAPI | None
69+ """An initialized data API client instance for interacting with data in the org. None if no access token is available. """
7070 request_id : str
7171 """Request ID from the Salesforce org."""
72- access_token : str
72+ access_token : str | None
7373 """Valid access token for the current context org/user."""
7474 api_version : str
7575 """API version of the Salesforce component that made the request."""
@@ -81,6 +81,19 @@ def from_header(cls, header: str, connection: Connection):
8181 decoded = base64 .b64decode (header )
8282 data = json .loads (decoded )
8383
84+ access_token = data .get ("accessToken" )
85+
86+ # Set data_api only if access token is available
87+ if access_token is None :
88+ data_api = None
89+ else :
90+ data_api = DataAPI (
91+ org_domain_url = data ["orgDomainUrl" ],
92+ api_version = data ["apiVersion" ],
93+ access_token = access_token ,
94+ connection = connection ,
95+ )
96+
8497 return cls (
8598 org = Org (
8699 id = data ["orgId" ],
@@ -91,15 +104,10 @@ def from_header(cls, header: str, connection: Connection):
91104 ),
92105 ),
93106 request_id = data ["requestId" ],
94- access_token = data [ "accessToken" ] ,
107+ access_token = access_token ,
95108 api_version = data ["apiVersion" ],
96109 namespace = data .get ("namespace" ), # Use get() to handle None case
97- data_api = DataAPI (
98- org_domain_url = data ["orgDomainUrl" ],
99- api_version = data ["apiVersion" ],
100- access_token = data ["accessToken" ],
101- connection = connection ,
102- ),
110+ data_api = data_api ,
103111 )
104112
105113# ContextVars for request-scoped data
0 commit comments