The example WorkerIdWalletLink class exposes Generate Worker ID Wallet Link to Flow and a generate method to Apex. It calls POST /api/v1/passes/link and returns a shareable wallet URL and its expiry time.
The Version 1 release includes a Salesforce example project ZIP and a separate copy of WorkerIdWalletLink.cls. Open the product's Version 1 release log to download them. The ZIP includes the original class filenames, both metadata files, WorkerIdWalletLinkTest.cls and sfdx-project.json, ready to extract as a Salesforce DX project.
The example project uses API version 62.0. If downloading the individual worker-id-wallet-link.cls file, rename it to WorkerIdWalletLink.cls before adding it to a Salesforce project. Use the ZIP when you also need the metadata and tests.
The class expects a Named Credential with the exact API name WorkerIdWallet.
WorkerIdWallet, using the Custom authentication protocol.ApiKey. Add an authentication parameter named ApiKey and populate it with the API key issued to your organisation (see the API guide).x-api-key with value {!$Credential.WorkerIdWallet.ApiKey}.WorkerIdWallet, pointing to https://<identity-service-host>, and connect it to that External Credential. Enable callouts and leave Generate Authorization Header off.WorkerIdWallet - ApiKey external credential principal through a permission set assigned to the users running the action. Grant access to the Apex class where needed. Check the actual running user for automated flows as well.Salesforce's custom API-key header guidance describes this authentication pattern, and its Named Credentials reference explains principal access. The class supplies Content-Type: application/json; the credential supplies the API key.
Edit the BRANDING map at the top of WorkerIdWalletLink.cls before deployment. It applies to every card this class issues. The supplied values use the 3B colours and the title 3B4SF; change the title, colours and optional logoSvg for your organisation. Branding is not a per-call input in this sample.
From the extracted directory containing sfdx-project.json, authenticate and deploy:
sf org login web --alias client-org
sf project deploy start --target-org client-org \
--test-level RunSpecifiedTests --tests WorkerIdWalletLinkTest
The included tests use mocked callouts. They cover successful mapping, blank detail values, service errors, non-JSON responses and mismatched detail lists. They do not prove that the Named Credential or a device wallet is configured correctly; make a separate end-to-end call after deployment.
Run this after deploying the class and configuring the credential. Replace the sample values with fields from your own worker record; the service does not require a particular Salesforce object or field name.
WorkerIdWalletLink.Request request = new WorkerIdWalletLink.Request();
request.firstName = 'Jane';
request.lastName = 'Smith';
request.company = 'Example Staffing';
request.dob = Date.newInstance(1992, 8, 24);
request.employeeId = 'EMP-88301';
request.qrData = 'EMP-88301';
request.targetWallet = 'both';
request.frontLabels = new List<String>{ 'Role', 'Assignment' };
request.frontValues = new List<String>{ 'Teaching assistant', 'North campus' };
request.backLabels = new List<String>{ 'Office' };
request.backValues = new List<String>{ 'London' };
request.notice = 'Check current assignment before granting access.';
WorkerIdWalletLink.Result result = WorkerIdWalletLink.generate(
new List<WorkerIdWalletLink.Request>{ request }
)[0];
if (result.isSuccess) {
// Store result.url and result.expiresAt on your chosen record,
// or pass them to your existing worker communication process.
} else {
// Handle result.errorCode and result.errorMessage in your application.
}
The method returns results in the same order as its input list. It performs one synchronous HTTP callout per request, with a 30-second timeout per call. Keep batches within the transaction's remaining callout and cumulative timeout limits; a list parameter does not make this an asynchronous bulk issuer. Do not make the callout after uncommitted record changes in the same transaction.
| Apex property / Flow input | Required | Notes |
|---|---|---|
firstName, lastName, company, employeeId |
Yes | Text, up to 100 characters each |
dob / Date of Birth |
Yes | Apex Date / Flow Date; serialised as YYYY-MM-DD |
middleName |
No | Text, up to 100 characters |
qrData / QR Data |
No | Up to 500 characters; defaults to employee ID |
photoUrl / Photo URL |
No | Direct public HTTPS photo URL, up to 2,048 characters |
targetWallet / Target Wallet |
No | apple, google or both; sample trims and lowercases this value |
frontLabels, frontValues |
No | Parallel text collections, up to three nonblank rows |
backLabels, backValues |
No | Parallel text collections, up to ten nonblank rows |
notice / Back Notice |
No | Up to 500 characters |
Label and value collections must have the same length. The class pairs them by position and skips rows with a blank value. Remaining rows must satisfy the API's label and value limits. It returns a local VALIDATION_ERROR without making a callout when collection lengths differ.
| Apex property / Flow output | Meaning |
|---|---|
isSuccess / Success |
True when the service returns 201 with a URL |
url / Link URL |
Shareable wallet page; anyone holding it can add the pass |
expiresAt / Expires At |
Link expiry as a Salesforce Datetime, normally 30 days after issuance |
errorCode / Error Code |
Service error code, local VALIDATION_ERROR, HTTP_<status> or CALLOUT_FAILED |
errorMessage / Error Message |
Error message, including service field details when present |
The sample returns handled errors in the result; check isSuccess before using the URL. HTTP_<status> is used when a response does not contain a service error code, such as an HTML proxy response. Callout and other caught exceptions use CALLOUT_FAILED.
The class itself does not save records or send messages. Link creation also does not confirm that a worker added the card. Store links in fields that can accommodate their variable length, especially when sending inline SVG branding.
The same Named Credential can call the other API routes. For example, this returns a Google Wallet save URL as JSON:
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:WorkerIdWallet/api/v1/passes/google');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setTimeout(30000);
req.setBody(JSON.serialize(new Map<String, Object>{
'firstName' => 'Jane',
'lastName' => 'Smith',
'company' => 'Example Staffing',
'dob' => '1992-08-24',
'employeeId' => 'EMP-88301'
}));
HttpResponse response = new Http().send(req);
if (response.getStatusCode() == 200) {
Map<String, Object> payload =
(Map<String, Object>) JSON.deserializeUntyped(response.getBody());
String saveUrl = (String) payload.get('saveUrl');
// Return saveUrl to the worker through your application.
} else {
// Parse the API error body and handle the failure.
}
For /apple, use response.getBodyAsBlob() after checking for 200. For /generate, parse the JSON and decode apple.pkpassBase64 with EncodingUtil.base64Decode when Apple output is present. Account for Apex response and heap limits when handling binary passes. See the API reference for the complete response contracts.