Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

AI Accelerator Predictions API Using Apex

This AI Accelerator Predictions API is also exposed to Apex. You can access/invoke this API from within your Apex class to get realtime prediction results.
Here are the details to invoke/access the AI Accelerator Predictions API from an Apex class:
  1. In the Developer Console, select File | New Apex Class.
  2. Implement the AI Accelerator Connect API request in the Apex class.
    This example shows an implementation of the connect API request from an Apex class.
    1ConnectApi.PredictionRequest predictionInputRepresentation = new ConnectApi.PredictionRequest();
    2predictionInputRepresentation.async = false;
    3predictionInputRepresentation.enableScorePersistence = false;
    4predictionInputRepresentation.enableInsightPersistence = false;
    5predictionInputRepresentation.enableFeaturePersistence = false;
    6predictionInputRepresentation.enableSuggestionPersistence = false;
    7predictionInputRepresentation.usecaseDefinition = '0sIx00000000006EAA';
    8predictionInputRepresentation.predictionDefinition = '0sIx00000000006EAB';
    9predictionInputRepresentation.inputType = 'ExtractedRawData';
    10predictionInputRepresentation.featureExtractorId = '0sIx00000000006EAC';
    11Map < String, Integer > insightsSettings = new Map < String, Integer > ();
    12insightsSettings.put('maxInsights', 0);
    13insightsSettings.put('suggestionImpactMinimumPct', 0);
    14predictionInputRepresentation.insightsSettings = insightsSettings;
    15List < String > recordIds = new List < String > ();
    16recordIds.add('subscriptionId');
    17predictionInputRepresentation.records = recordIds;
    18
    19//Create a Map with feature extraction parameters
    20//Replace 'key1', 'recordId' with the required params in your feature extractor
    21Map < String, Object > map1 = new Map < String, Object > ();
    22map1.put('recordId', '0sIx000000000068EAC');
    23map1.put('key1', 'value1');
    24Object objForList = map1;
    25ConnectApi.FeatureExtractionParametersFieldMapValue features = new ConnectApi.FeatureExtractionParametersFieldMapValue();
    26features.featureExtractionParametersMapValue = objForList;
    27List < ConnectApi.FeatureExtractionParametersFieldMapValue > featuresList = new List < ConnectApi.FeatureExtractionParametersFieldMapValue > ();
    28featuresList.add(features);
    29predictionInputRepresentation.featureExtractionParameters = featuresList;
    30//Act
    31ConnectApi.PredictionResponse predictionOutputRepresentation = ConnectApi.AIAcceleratorConnectFamily.predictions(predictionInputRepresentation);