| name | apex-security-tests |
|---|---|
| description | Write and review Apex test classes that respect user security via System.runAs and permission set assignment. Use when creating or updating Apex tests, @TestSetup, runAs users, permission sets, API 67 user-mode defaults, FLS, CRUD, sharing enforcement, or debugging insufficient-permissions test failures. |
Background: I find Cursor struggles to retrieve content from Salesforce documentation links due to various approaches used such as as shadow dom and dynamic loading. This Cursor command leverages Cursors Browser Automation tool (needs to be explcitly enabled) to help give it a few more clues on how to deal with these pages. I initially built a shell script for it to call but then I discovered Cursor commands. So I built this command using Cursor itself once we had both figured this out - effectively it wrote its own instructions. Use at your own risk.
Usage: In Cursor type / and select Create Command enter sfdoc and press enter. Then paste the content below into the file. To use, use prompts like Read this https://developer.salesforce.com/docs... using /sfdoc. Make sure you have chromium NPM library installed globally as the Node.js scripts below require it. Also make sure you have given Cursor permission to use your browser - there is a icon bottom right of the chat window to enable this in
| public class SvgChartGeneratorFlowAction { | |
| public class ChartInput { | |
| @InvocableVariable(label='Bar Labels (e.g. Jan, Feb, Mar)' required=true) | |
| public List<String> labels; | |
| @InvocableVariable(label='Bar Values (e.g. 10, 20, 15)' required=true) | |
| public List<Integer> values; | |
| } |
| public with sharing class CMTService { | |
| public List<CMTWrapper> getCMTs() { | |
| List<CMTWrapper> cmtWrappers = new List<CMTWrapper>(); | |
| List<CMT__mdt> cmts = [SELECT Example_Field_1__c, Example_Field_2_c FROM CMT__mdt]; | |
| for(CMT__mdt c : cmts) { | |
| CMTWrapper cmtWrapper = new CMTWrapper(c.Example_Field_1__c, c.Example_Field_2__c); | |
| cmtWrappers.add(cmtWrapper); | |
| } | |
| return cmtWrappers; |
Requirement
Perform XSLT transform on XML returned from the Salesforce Metadata API retrieve operation (also requires unzip). Based on the code in https://github.com/financialforcedev/apex-mdapi
Solution
Adapting the metadataretrieve.page in the above repository. The original page passed the client side unzipped files from the MD retrieve zip file back to the server to add to the view state for display. As the XSLT is done client side, the above page is much simpler, the unzipped files are just handled client side and added dynamically to the page DOM.
Implementaiton Notes
- XSLT is loaded from a static resource
| public with sharing class EinsteinSentimentAction { | |
| public class Request { | |
| @InvocableVariable | |
| public String recordId; | |
| @InvocableVariable | |
| public String document; | |
| @InvocableVariable | |
| public String modelId; | |
| } |
| <aura:component implements="lightning:actionOverride,force:hasRecordId,force:hasSObjectName"> | |
| <aura:attribute name="record" type="Object" /> | |
| <aura:attribute name="componentRecord" type="Object" /> | |
| <aura:attribute name="recordError" type="String" /> | |
| <force:recordData | |
| aura:id="recordLoader" | |
| recordId="{!v.recordId}" | |
| layoutType="FULL" |
| /** | |
| * | |
| CustomMetadata.Operations | |
| .callback( | |
| // Platform event for deploy status | |
| MetadataDeployment__e.getSObjectType(), | |
| MetadataDeployment__e.DeploymentId__c, | |
| MetadataDeployment__e.Result__c) | |
| .enqueueUpsertRecords( | |
| // Metadata record type |
| public with sharing class EinsteinAction { | |
| public class Prediction { | |
| @InvocableVariable | |
| public String label; | |
| @InvocableVariable | |
| public Double probability; | |
| } | |
| @InvocableMethod(label='Classify the given files' description='Calls the Einsten API to classify the given ContentVersion files.') |