Skip to content

Commit 900e218

Browse files
committed
Add WITH RecordVisibilityContext
Update grammar to support `WITH RecordVisibilityContext` in SOQL queries.
1 parent 6771ccd commit 900e218

14 files changed

Lines changed: 4945 additions & 4355 deletions

formatter/soql_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,45 @@ func TestSOQL(t *testing.T) {
274274
`[SELECT Name FROM Account WHERE Id = :accountId WITH SYSTEM_MODE]`,
275275
`[SELECT Name FROM Account WHERE Id = :accountId WITH SYSTEM_MODE]`,
276276
},
277+
{
278+
`[SELECT Id, RecordVisibility.VisibilityAttribute FROM Account WHERE Id = 'xxx' WITH RecordVisibilityContext (maxDescriptorPerRecord=100, supportsDomains=true, supportsDelegates=true)]`,
279+
`[
280+
SELECT
281+
Id,
282+
RecordVisibility.VisibilityAttribute
283+
FROM
284+
Account
285+
WHERE
286+
Id = 'xxx'
287+
WITH RecordVisibilityContext (maxDescriptorPerRecord=100, supportsDomains=true, supportsDelegates=true)
288+
]`,
289+
},
290+
{
291+
`[SELECT recordId, VisibilityAttribute FROM RecordVisibility WHERE recordId = 'xxx' WITH RecordVisibilityContext (maxDescriptorPerRecord=100, supportsDomains=true, supportsDelegates=true)]`,
292+
`[
293+
SELECT
294+
recordId,
295+
VisibilityAttribute
296+
FROM
297+
RecordVisibility
298+
WHERE
299+
recordId = 'xxx'
300+
WITH RecordVisibilityContext (maxDescriptorPerRecord=100, supportsDomains=true, supportsDelegates=true)
301+
]`,
302+
},
303+
{
304+
`[SELECT Id, RecordVisibility.VisibilityAttribute FROM Account WHERE Id = 'xxx' WITH RecordVisibilityContext (maxDescriptorPerRecord=100)]`,
305+
`[
306+
SELECT
307+
Id,
308+
RecordVisibility.VisibilityAttribute
309+
FROM
310+
Account
311+
WHERE
312+
Id = 'xxx'
313+
WITH RecordVisibilityContext (maxDescriptorPerRecord=100)
314+
]`,
315+
},
277316
{
278317
`[SELECT StageName, COUNT(Id) cnt FROM opportunity GROUP BY StageName HAVING COUNT(Id) > 1]`,
279318
`[

formatter/visitors.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,31 @@ func (v *FormatVisitor) VisitWithClause(ctx *parser.WithClauseContext) interface
10091009
if ctx.SYSTEM_MODE() != nil {
10101010
return "WITH SYSTEM_MODE"
10111011
}
1012+
if ctx.RECORDVISIBILITYCONTEXT() != nil {
1013+
params := make([]string, 0, len(ctx.AllRecordVisibilityContextParam()))
1014+
for _, param := range ctx.AllRecordVisibilityContextParam() {
1015+
params = append(params, v.visitRule(param).(string))
1016+
}
1017+
return fmt.Sprintf("WITH RecordVisibilityContext (%s)", strings.Join(params, ", "))
1018+
}
10121019
return "WITH"
10131020
}
10141021

1022+
func (v *FormatVisitor) VisitRecordVisibilityContextParam(ctx *parser.RecordVisibilityContextParamContext) interface{} {
1023+
if intValue := ctx.IntegerLiteral(); intValue != nil {
1024+
return fmt.Sprintf("maxDescriptorPerRecord=%s", intValue.GetText())
1025+
}
1026+
if boolValue := ctx.BooleanLiteral(); boolValue != nil {
1027+
switch {
1028+
case ctx.SUPPORTSDOMAINS() != nil:
1029+
return fmt.Sprintf("supportsDomains=%s", boolValue.GetText())
1030+
case ctx.SUPPORTSDELEGATES() != nil:
1031+
return fmt.Sprintf("supportsDelegates=%s", boolValue.GetText())
1032+
}
1033+
}
1034+
return ctx.GetText()
1035+
}
1036+
10151037
func (v *FormatVisitor) VisitWhereClause(ctx *parser.WhereClauseContext) interface{} {
10161038
sep := " "
10171039
indent := 0

grammar/ApexLexer.g4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ ABOVE : A B O V E;
155155
BELOW : B E L O W;
156156
ABOVE_OR_BELOW : A B O V E '_' O R '_' B E L O W;
157157
SECURITY_ENFORCED : S E C U R I T Y '_' E N F O R C E D;
158+
RECORDVISIBILITYCONTEXT : R E C O R D V I S I B I L I T Y C O N T E X T;
159+
MAXDESCRIPTORPERRECORD : M A X D E S C R I P T O R P E R R E C O R D;
160+
SUPPORTSDOMAINS : S U P P O R T S D O M A I N S;
161+
SUPPORTSDELEGATES : S U P P O R T S D E L E G A T E S;
158162
REFERENCE : R E F E R E N C E;
159163
CUBE : C U B E;
160164
FORMAT : F O R M A T;

grammar/ApexParser.g4

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,15 @@ withClause
719719
| WITH SECURITY_ENFORCED
720720
| WITH USER_MODE
721721
| WITH SYSTEM_MODE
722+
| WITH RECORDVISIBILITYCONTEXT LPAREN recordVisibilityContextParam (COMMA recordVisibilityContextParam)* RPAREN
722723
| WITH logicalExpression;
723724

725+
recordVisibilityContextParam
726+
: MAXDESCRIPTORPERRECORD ASSIGN IntegerLiteral
727+
| SUPPORTSDOMAINS ASSIGN BooleanLiteral
728+
| SUPPORTSDELEGATES ASSIGN BooleanLiteral
729+
;
730+
724731
filteringExpression
725732
: dataCategorySelection (AND dataCategorySelection)*;
726733

@@ -1019,6 +1026,10 @@ id
10191026
| BELOW
10201027
| ABOVE_OR_BELOW
10211028
| SECURITY_ENFORCED
1029+
| RECORDVISIBILITYCONTEXT
1030+
| MAXDESCRIPTORPERRECORD
1031+
| SUPPORTSDOMAINS
1032+
| SUPPORTSDELEGATES
10221033
| USER_MODE
10231034
| SYSTEM_MODE
10241035
| REFERENCE
@@ -1233,6 +1244,10 @@ anyId
12331244
| BELOW
12341245
| ABOVE_OR_BELOW
12351246
| SECURITY_ENFORCED
1247+
| RECORDVISIBILITYCONTEXT
1248+
| MAXDESCRIPTORPERRECORD
1249+
| SUPPORTSDOMAINS
1250+
| SUPPORTSDELEGATES
12361251
| USER_MODE
12371252
| SYSTEM_MODE
12381253
| REFERENCE

parser/ApexLexer.interp

Lines changed: 13 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)