Skip to content

Commit bb63260

Browse files
authored
Add OrganizationSettings global variable resolver and update document… (#208)
* Add OrganizationSettings global variable resolver and update documentation * Releasing and promoting a new package version.
1 parent bc7d159 commit bb63260

File tree

8 files changed

+67
-4
lines changed

8 files changed

+67
-4
lines changed

docs/public/packages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"packageId": "04tRb0000037T8PIAU",
2+
"packageId": "04tRb000003L5m9IAC",
33
"componentPackageId": "04tRb0000012Mv8IAE"
44
}

docs/src/app/docs/referencing-org-data/page.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,12 @@ The `timeZone` property of the `$UserSettings` global variable returns a map con
8383
Object result = expression.Evaluator.run('$UserSettings.timeZone.name');
8484
Object gmtOffset = expression.Evaluator.run('$UserSettings.timeZone.gmtOffset');
8585
```
86+
87+
## Organization
88+
89+
You can reference information about the current organization through the `$Organization` global variable.
90+
91+
Available references are:
92+
93+
* `OrgId`
94+
* `Name`

expression-src/main/src/interpreter/Environment.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public with sharing class Environment {
2323
GLOBAL_VARIABLES.put('$action', new ActionVariableResolver());
2424
GLOBAL_VARIABLES.put('$user', new UserVariableResolver());
2525
GLOBAL_VARIABLES.put('$usersettings', new UserSettingsVariableResolver());
26+
GLOBAL_VARIABLES.put('$organizationsettings', new OrganizationSettingsVariableResolver());
2627

2728
// Placeholder value for whatever the called Action returned. Not used by language,
2829
// but can be used by the caller to get the return value of the Action.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public with sharing class OrganizationSettingsVariableResolver implements IGlobalVariableResolver {
2+
public Object get(String referenceName, List<Object> args) {
3+
switch on referenceName.toLowerCase() {
4+
when 'name' {
5+
return getOrganizationSettings().name;
6+
}
7+
when 'orgid' {
8+
return getOrganizationSettings().orgId;
9+
}
10+
when else {
11+
throw new OrganizationSettingsVariableResolverException('Unknown reference name: ' + referenceName);
12+
}
13+
}
14+
}
15+
16+
private static ConnectApi.OrganizationSettings getOrganizationSettings() {
17+
return ConnectApi.Organization.getSettings();
18+
}
19+
20+
public class OrganizationSettingsVariableResolverException extends Exception {}
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>60.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@IsTest
2+
private class OrganizationSettingsVariableTest {
3+
// ConnectApi methods are not supported in data siloed
4+
// tests, so we need to use SeeAllData=true.
5+
6+
@IsTest(SeeAllData=true)
7+
static void canRetrieveOrganizationName() {
8+
String expression = '$OrganizationSettings.name';
9+
Object result = Evaluator.run(expression);
10+
Assert.isTrue(result instanceof String);
11+
Assert.isNotNull(result);
12+
}
13+
14+
@IsTest(SeeAllData=true)
15+
static void canRetrieveOrganizationId() {
16+
String expression = '$OrganizationSettings.orgId';
17+
Object result = Evaluator.run(expression);
18+
Assert.isTrue(result instanceof String);
19+
Assert.isNotNull(result);
20+
}
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>60.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

sfdx-project_packaging.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
{
44
"path": "expression-src",
55
"package": "Expression",
6-
"versionName": "Version 1.33",
7-
"versionNumber": "1.33.0.NEXT",
6+
"versionName": "Version 1.34",
7+
"versionNumber": "1.34.0.NEXT",
88
"default": false,
99
"versionDescription": "Expression core language",
1010
"ancestorVersion": "HIGHEST"
@@ -62,6 +62,7 @@
6262
"Expression@1.30.0-2": "04tRb0000036iJBIAY",
6363
"Expression@1.31.0-2": "04tRb0000037GO5IAM",
6464
"Expression@1.32.0-1": "04tRb0000037HYfIAM",
65-
"Expression@1.33.0-1": "04tRb0000037T8PIAU"
65+
"Expression@1.33.0-1": "04tRb0000037T8PIAU",
66+
"Expression@1.34.0-3": "04tRb000003L5m9IAC"
6667
}
6768
}

0 commit comments

Comments
 (0)