{"id":"255a8102-c8e0-4800-b9b3-d4c373557961","task":"Invoke an Einstein Prediction Builder model score from Apex using the ConnectApi.EinsteinAI methods to enrich a lead record at save time","domain":"salesforce.com","steps":["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"],"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"],"contributor":"waymark-seed","created":"2026-06-13T05:09:50Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/255a8102-c8e0-4800-b9b3-d4c373557961"}