Last active
January 24, 2025 20:22
-
-
Save patmcclellan/bceb63885f1fdbb58602fcae8ff26a91 to your computer and use it in GitHub Desktop.
Agentforce Development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prompt Builder Setup in Scratch | |
1. Add features and settings to your project-scratch-def.json. You can include whatever other features and settings you need. | |
Note: I found that including the "namespace" parameter causes an error when you try to run the prompt. Salesforce Support is still working on this case. | |
{ | |
"orgName": "Agentforce scratch org", | |
"edition": "Developer", | |
"features": ["Einstein1AIPlatform"], | |
"settings": { | |
"einsteinGptSettings": { | |
"enableEinsteinGptPlatform": true | |
} | |
} | |
} | |
2. Create your default scratch org using this config. | |
3. Assign yourself the permission sets: Prompt Template Manager & Prompt Template User (then refresh the Setup page) | |
4. Make sure Einstein is enabled: Setup > Einstein Generative AI > Einstein Setup | |
5. Go to Prompt Builder: Setup > Einstein Generative AI > Prompt Builder. This page features an intro video, link to Prompt Builder Help articles, and a guided tour. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApexFlexTemplateExample1 { | |
@InvocableMethod | |
public static List<Response> getPrompt(List<Request> requests) { | |
Request input = requests[0]; | |
List<Response> responses = new List<Response>(); | |
Response output = new Response(); | |
responses.add(output); | |
output.Prompt = 'generate a summary using the following info:'; | |
// account_1 matches the API Name for the input | |
output.Prompt += '\nAccount 1: ' + input.account_1.Name; | |
output.Prompt += '\nAccount 2: ' + input.account_2.Name; | |
output.Prompt += '\nCase Number: ' + input.case_1.CaseNumber; | |
return responses; | |
} | |
// Type and API Name of all variables must match the template | |
public class Request { | |
@InvocableVariable(required=true) | |
public Account account_1; | |
@InvocableVariable(required=true) | |
public Account account_2; | |
@InvocableVariable(required=true) | |
public Case case_1; | |
} | |
public class Response { | |
@InvocableVariable | |
public String Prompt; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class OpportunityAssessmentDataController { | |
@InvocableMethod | |
public static List<Response> getPrompt(List<Request> requests){ | |
//deal with the implicit bulkification | |
Opportunity opp = requests[0].opportunity; | |
//run the SOQL query | |
List<Account> accounts = | |
[SELECT Id, Name, | |
(SELECT Name, Amount, StageName, IsWon, | |
(SELECT Contact.Name, Contact.Title, Role | |
FROM OpportunityContactRoles) | |
FROM Opportunities | |
WHERE IsClosed = true | |
ORDER BY CloseDate DESC | |
LIMIT 20) | |
FROM Account | |
WHERE Id = :opp.AccountId | |
LIMIT 1]; | |
//create the output response | |
List<Response> responses = new List<Response>(); | |
Response output = new Response(); | |
if(accounts.size() > 0 && accounts[0].Opportunities.size() > 0){ | |
//turn the data into a JSON string | |
output.Prompt = JSON.serialize(accounts[0], true); | |
}else{ | |
output.Prompt = 'No data available'; | |
} | |
// add the response to the list (implicit bulkification) | |
responses.add(output); | |
//return the list of responses | |
return responses; | |
} | |
public class Request { | |
@InvocableVariable(required=true) | |
public Opportunity opportunity; | |
} | |
public class Response { | |
@InvocableVariable | |
public String Prompt; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment