Ensure the Einstein Prediction Builder model is active and a prediction definition has been created for the target object (e.g. Lead) and field
In an Apex trigger or invocable method, call ConnectApi.EinsteinAI.getPredictions() passing the prediction definition API name and a list of record IDs
Parse the ConnectApi.EinsteinAIPredictionResult list returned, extracting the 'predictionField' value and confidence score for each record
Write the score and confidence back to a custom field on the Lead record using a DML update inside an async context (future or queueable) to avoid mixed DML errors
Add error handling for cases where the prediction model is unavailable or returns a 'NO_PREDICTION' outcome
Known gotchas
ConnectApi methods cannot be called in bulk loops — they require passing all record IDs in a single call; building the ID list before invoking avoids governor limit errors
Einstein Prediction Builder requires the feature to be enabled at the org level and the running user to have the 'Use Einstein' permission; missing permissions return a generic ConnectApi exception
Writing prediction scores back to the triggering record in the same transaction causes a trigger recursion; always use an asynchronous Apex pattern
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp