Salesforce Apex and LWC Code Review Skill
Purpose
This skill reviews Salesforce Apex classes, triggers, Lightning Web Components
(
LWC), and async jobs for security
vulnerabilities, governor-limit risk, test coverage patterns, and sharing
enforcement. It flags patterns that cause data exposure, runaway resource
consumption, or privilege escalation. It does not execute code, access live
orgs, or authorize deployments.
When to use
- Apex or LWC code must be reviewed before a release.
- A code review has raised security or governor-limit concerns.
- A trigger is suspected of causing SOQL or DML governor limit errors.
- LWC components are being reviewed for XSS or Locker Service issues.
- Async job design (Batch, Queueable, Future, Schedulable) needs safety review.
When not to use
- Flow automation (not code) is the primary subject — use
salesforce-flow-automation-review-skill.
- Metadata quality (not code logic) — use
salesforce-metadata-review-skill.
- Live code deployment proposal — use
salesforce-live-change-approval-protocol.
- Full org posture assessment — use
salesforce-org-assessment-skill.
Minimum payload (required inputs)
- Pasted Apex code (class, trigger, or test class) or LWC component files
(JS controller, HTML template, or Apex controller).
- Context: what the code does, what object(s) it operates on, execution context
(trigger, batch, scheduled, invocable, REST endpoint, LWC component).
- Whether the code is deployed in production, sandbox, or scratch org.
Workflow
1. SOQL inside loops
- Scan for SOQL queries (
[SELECT ... FROM ...]) inside for loops,
while loops, or recursive method calls.
- Flag every SOQL-in-loop occurrence as a governor-limit risk.
- Recommend: bulkify by collecting IDs outside the loop and running a single
SOQL query.
2. DML inside loops
- Scan for DML statements (
insert, update, delete, upsert, merge,
undelete) inside loops.
- Flag every DML-in-loop occurrence.
- Recommend: collect records in a list and perform a single DML outside the loop.
3. Sharing enforcement
- Check every Apex class declaration for the
sharing keyword:
with sharing — enforces the running user's sharing rules (recommended default).
without sharing — bypasses sharing; flag all usages and require documented justification.
inherited sharing — flag if used in entry-point classes where explicit control is expected.
- No keyword — implicitly
without sharing in most contexts; flag all missing keywords.
- Flag any class that handles PII or financial data and uses
without sharing
or omits the keyword.
4. Field-level security enforcement
- Check SOQL queries for
WITH SECURITY_ENFORCED or WITH USER_MODE clause.
- Absence on queries returning PII or sensitive fields → flag as data exposure risk.
- Check for
Security.stripInaccessible usage before accessing returned field values.
- Flag: stripping only on output but not on input (incomplete FLS enforcement).
5. Governor limit risk
- SOQL: flag if total distinct SOQL calls per transaction could exceed 100.
- DML: flag if total DML statements per transaction could exceed 150.
- Heap: flag large in-memory collections (Lists, Maps, Sets) that grow with record volume.
- CPU: flag complex nested loops or recursive methods without break conditions.
- Callouts: flag synchronous callouts from triggers (not allowed); flag callouts
without timeout handling.
6. Test coverage patterns
- Check for test classes covering the reviewed code.
- Flag: test classes with
SeeAllData=true (
deprecated pattern).
- Flag: test methods with no assertions (
System.assertEquals, System.assertNotEquals,
System.assert).
- Flag: test data that is hardcoded with real org IDs or email addresses.
- Flag: missing negative test cases for validation or error paths.
7. LWC security surface
- HTML template: flag dynamic
<lightning-formatted-rich-text> or
innerHTML bindings with unsanitized values (XSS risk).
- JavaScript: flag
eval, Function constructor, or dangerouslySetInnerHTML
equivalents.
- Wire adapters: flag wire adapters returning PII fields exposed in template
without FLS enforcement in the backing Apex.
- Locker Service
: flag cross-namespace
DOM access patterns that depend on bypassing Locker Service.
8. Async job design
- Batch Apex: flag
Database.Batchable implementations that query without
scope limitation; flag missing finish method implementations.
- Queueable: flag Queueable chains > configured depth without a termination
condition (runaway chaining).
- Future: flag
@future(callout=true) methods called from loops.
- Schedulable: flag scheduled classes that chain into Batch without a
concurrency guard.
Evidence requirements
- Pasted code; no credentials, session tokens, or customer data in code comments.
- If code contains hardcoded credentials or tokens, stop and ask for sanitized version.
- Context about the object and field sensitivity helps calibrate sharing and FLS findings.
Output format
apex_lwc_code_review_findings:
soql_in_loops:
- location: [class/method or line range]
severity: High
recommendation: [brief]
dml_in_loops:
- location: [...]
severity: High
recommendation: [...]
sharing_enforcement:
- class: [name]
keyword: with sharing | without sharing | inherited sharing | missing
severity: Critical | High | Medium | Low
justification_required: true | false
recommendation: [...]
fls_enforcement:
- query_location: [...]
with_security_enforced: present | absent
strip_inaccessible: present | partial | absent
severity: [...]
recommendation: [...]
governor_limit_risks:
- pattern: [description]
severity: [...]
recommendation: [...]
test_coverage_patterns:
- finding: [description]
severity: [...]
recommendation: [...]
lwc_security_findings:
- finding: [description]
severity: [...]
recommendation: [...]
async_job_findings:
- finding: [description]
severity: [...]
recommendation: [...]
summary:
total_findings: [count]
critical_count: [count]
high_count: [count]
escalation_gates_fired: [from salesforce-risk-taxonomy, or "none"]
assumptions: [list]
missing_evidence: [what would improve the review]
Redaction rules
- Never request secrets, credentials, OAuth tokens, refresh tokens, session IDs, MFA seeds, customer PII.
- Sanitize org IDs, user IDs (replace with placeholders) before sharing in outputs.
- If pasted code contains hardcoded credentials or tokens, stop and ask for sanitized version.
Privilege / data handling rules
- Code review is logic-level only; do not carry record data from code samples.
without sharing classes handling PII must be flagged for compliance review.
- Test code containing real org IDs or customer email addresses must be refused.
Handoff rules
- Hands off to: salesforce-flow-automation-review-skill (if automation logic is intertwined),
salesforce-permission-model-review-skill (if sharing or FLS findings are systemic),
salesforce-release-readiness-skill (for deployment readiness after review).
- If escalation gate fires: salesforce-case-capsule with escalation_required = true.
- Required handoff fields: matter_id, critical_count, high_count, escalation_gates_fired,
sharing_enforcement summary.
Audit log fields
- matter_id, skill_id, skill_version, invoked_by, input_hash, evidence_quality, output_verdict, escalation_fired, timestamp
Stop conditions
- Pasted code contains live credentials, session tokens, or customer PII in comments — stop and ask for sanitized version.
- Critical
without sharing on PII-handling class in production — flag immediately and require human review.
- SOQL-in-loop count is very high (systemic) — escalate to salesforce-org-assessment-skill for full automation review.
Security notes
- Read-only static code review; never executes code or requests live org access.
without sharing is a security-relevant decision; every usage must have documented justification.
- LWC XSS patterns are particularly high risk in Experience Cloud guest-user context.
- Test class quality is a proxy for deployment safety; missing assertions are a reliability risk.
1---2name: salesforce-apex-lwc-code-review-skill3description: Salesforce Apex and LWC Code Review Skill4---56# Salesforce Apex and LWC Code Review Skill78## Purpose9This skill reviews Salesforce Apex classes, triggers, Lightning Web Components10(11LWC), and async jobs for security12vulnerabilities, governor-limit risk, test coverage patterns, and sharing13enforcement. It flags patterns that cause data exposure, runaway resource14consumption, or privilege escalation. It does not execute code, access live15orgs, or authorize deployments.1617## When to use18- Apex or LWC code must be reviewed before a release.19- A code review has raised security or governor-limit concerns.20- A trigger is suspected of causing SOQL or DML governor limit errors.21- LWC components are being reviewed for XSS or Locker Service issues.22- Async job design (Batch, Queueable, Future, Schedulable) needs safety review.2324## When not to use25- Flow automation (not code) is the primary subject — use `salesforce-flow-automation-review-skill`.26- Metadata quality (not code logic) — use `salesforce-metadata-review-skill`.27- Live code deployment proposal — use `salesforce-live-change-approval-protocol`.28- Full org posture assessment — use `salesforce-org-assessment-skill`.2930## Minimum payload (required inputs)31- Pasted Apex code (class, trigger, or test class) or LWC component files32 (JS controller, HTML template, or Apex controller).33- Context: what the code does, what object(s) it operates on, execution context34 (trigger, batch, scheduled, invocable, REST endpoint, LWC component).35- Whether the code is deployed in production, sandbox, or scratch org.3637## Workflow3839### 1. SOQL inside loops40- Scan for SOQL queries (`[SELECT ... FROM ...]`) inside `for` loops,41 `while` loops, or recursive method calls.42- Flag every SOQL-in-loop occurrence as a governor-limit risk.43- Recommend: bulkify by collecting IDs outside the loop and running a single44 SOQL query.4546### 2. DML inside loops47- Scan for DML statements (`insert`, `update`, `delete`, `upsert`, `merge`,48 `undelete`) inside loops.49- Flag every DML-in-loop occurrence.50- Recommend: collect records in a list and perform a single DML outside the loop.5152### 3. Sharing enforcement53- Check every Apex class declaration for the `sharing` keyword:54 - `with sharing` — enforces the running user's sharing rules (recommended default).55 - `without sharing` — bypasses sharing; flag all usages and require documented justification.56 - `inherited sharing` — flag if used in entry-point classes where explicit control is expected.57 - No keyword — implicitly `without sharing` in most contexts; flag all missing keywords.58- Flag any class that handles PII or financial data and uses `without sharing`59 or omits the keyword.6061### 4. Field-level security enforcement62- Check SOQL queries for `WITH SECURITY_ENFORCED` or `WITH USER_MODE` clause.63- Absence on queries returning PII or sensitive fields → flag as data exposure risk.64- Check for `Security.stripInaccessible` usage before accessing returned field values.65- Flag: stripping only on output but not on input (incomplete FLS enforcement).6667### 5. Governor limit risk68- SOQL: flag if total distinct SOQL calls per transaction could exceed 100.69- DML: flag if total DML statements per transaction could exceed 150.70- Heap: flag large in-memory collections (Lists, Maps, Sets) that grow with record volume.71- CPU: flag complex nested loops or recursive methods without break conditions.72- Callouts: flag synchronous callouts from triggers (not allowed); flag callouts73 without timeout handling.7475### 6. Test coverage patterns76- Check for test classes covering the reviewed code.77- Flag: test classes with `SeeAllData=true` (78deprecated pattern).79- Flag: test methods with no assertions (`System.assertEquals`, `System.assertNotEquals`,80 `System.assert`).81- Flag: test data that is hardcoded with real org IDs or email addresses.82- Flag: missing negative test cases for validation or error paths.8384### 7. LWC security surface85- HTML template: flag dynamic `<lightning-formatted-rich-text>` or86 `innerHTML` bindings with unsanitized values (XSS risk).87- JavaScript: flag `eval`, `Function` constructor, or `dangerouslySetInnerHTML`88 equivalents.89- Wire adapters: flag wire adapters returning PII fields exposed in template90 without FLS enforcement in the backing Apex.91- Locker Service92: flag cross-namespace93 DOM access patterns that depend on bypassing Locker Service.9495### 8. Async job design96- Batch Apex: flag `Database.Batchable` implementations that query without97 scope limitation; flag missing `finish` method implementations.98- Queueable: flag Queueable chains > configured depth without a termination99 condition (runaway chaining).100- Future: flag `@future(callout=true)` methods called from loops.101- Schedulable: flag scheduled classes that chain into Batch without a102 concurrency guard.103104## Evidence requirements105- Pasted code; no credentials, session tokens, or customer data in code comments.106- If code contains hardcoded credentials or tokens, stop and ask for sanitized version.107- Context about the object and field sensitivity helps calibrate sharing and FLS findings.108109## Output format110```111apex_lwc_code_review_findings:112 soql_in_loops:113 - location: [class/method or line range]114 severity: High115 recommendation: [brief]116 dml_in_loops:117 - location: [...]118 severity: High119 recommendation: [...]120 sharing_enforcement:121 - class: [name]122 keyword: with sharing | without sharing | inherited sharing | missing123 severity: Critical | High | Medium | Low124 justification_required: true | false125 recommendation: [...]126 fls_enforcement:127 - query_location: [...]128 with_security_enforced: present | absent129 strip_inaccessible: present | partial | absent130 severity: [...]131 recommendation: [...]132 governor_limit_risks:133 - pattern: [description]134 severity: [...]135 recommendation: [...]136 test_coverage_patterns:137 - finding: [description]138 severity: [...]139 recommendation: [...]140 lwc_security_findings:141 - finding: [description]142 severity: [...]143 recommendation: [...]144 async_job_findings:145 - finding: [description]146 severity: [...]147 recommendation: [...]148149summary:150 total_findings: [count]151 critical_count: [count]152 high_count: [count]153escalation_gates_fired: [from salesforce-risk-taxonomy, or "none"]154assumptions: [list]155missing_evidence: [what would improve the review]156```157158## Redaction rules159- Never request secrets, credentials, OAuth tokens, refresh tokens, session IDs, MFA seeds, customer PII.160- Sanitize org IDs, user IDs (replace with placeholders) before sharing in outputs.161- If pasted code contains hardcoded credentials or tokens, stop and ask for sanitized version.162163## Privilege / data handling rules164- Code review is logic-level only; do not carry record data from code samples.165- `without sharing` classes handling PII must be flagged for compliance review.166- Test code containing real org IDs or customer email addresses must be refused.167168## Handoff rules169- Hands off to: salesforce-flow-automation-review-skill (if automation logic is intertwined),170 salesforce-permission-model-review-skill (if sharing or FLS findings are systemic),171 salesforce-release-readiness-skill (for deployment readiness after review).172- If escalation gate fires: salesforce-case-capsule with escalation_required = true.173- Required handoff fields: matter_id, critical_count, high_count, escalation_gates_fired,174 sharing_enforcement summary.175176## Audit log fields177- matter_id, skill_id, skill_version, invoked_by, input_hash, evidence_quality, output_verdict, escalation_fired, timestamp178179## Stop conditions180- Pasted code contains live credentials, session tokens, or customer PII in comments — stop and ask for sanitized version.181- Critical `without sharing` on PII-handling class in production — flag immediately and require human review.182- SOQL-in-loop count is very high (systemic) — escalate to salesforce-org-assessment-skill for full automation review.183184## Security notes185- Read-only static code review; never executes code or requests live org access.186- `without sharing` is a security-relevant decision; every usage must have documented justification.187- LWC XSS patterns are particularly high risk in Experience Cloud guest-user context.188- Test class quality is a proxy for deployment safety; missing assertions are a reliability risk.