You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/advanced-usage/mocking.md
+12-11Lines changed: 12 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ sidebar_position: 30
7
7
Mocking provides a way to substitute records from a Database with some prepared data. Data can be prepared in form of SObject records and lists in Apex code or Static Resource `.csv` file.
8
8
Mocked queries won't make any SOQL's and simply return data set in method definition, mock __will ignore all filters and relations__, what is returned depends __solely on data provided to the method__. Mocking is working __only during test execution__. To mock SOQL query, use `.mockId(id)` method to make it identifiable. If you mark more than one query with the same ID, all marked queries will return the same data.
9
9
10
-
```apex
10
+
```apex title="ExampleController.cls"
11
11
public with sharing class ExampleController {
12
12
13
13
public static List<Account> getPartnerAccounts(String accountName) {
@@ -111,7 +111,7 @@ This behavior is consistent with Salesforce’s native limits, ensuring that you
111
111
112
112
## List of records
113
113
114
-
```apex
114
+
```apex title="ExampleControllerTest.cls"
115
115
@IsTest
116
116
private class ExampleControllerTest {
117
117
@@ -134,7 +134,7 @@ private class ExampleControllerTest {
134
134
135
135
## Single record
136
136
137
-
```apex
137
+
```apex title="ExampleControllerTest.cls"
138
138
@IsTest
139
139
private class ExampleControllerTest {
140
140
@@ -152,7 +152,7 @@ private class ExampleControllerTest {
152
152
153
153
## Static resource
154
154
155
-
```apex
155
+
```apex title="ExampleControllerTest.cls"
156
156
@IsTest
157
157
private class ExampleControllerTest {
158
158
@@ -170,7 +170,7 @@ private class ExampleControllerTest {
170
170
171
171
## Count Result
172
172
173
-
```
173
+
```apex title="ExampleControllerTest.cls"
174
174
@IsTest
175
175
private class ExampleControllerTest {
176
176
@@ -195,7 +195,7 @@ _Using JSON String_
195
195
196
196
By passing simple String, it is possible to write non-writable fields, like `Name` on Contact object.
`USER_MODE` is a enabled by default. It means that the object permissions, field-level security and **sharing rules are enforced**.
21
21
22
-
```apex
22
+
```apex title="SOQL_Account.cls"
23
23
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {
24
24
public static SOQL_Account query() {
25
25
return new SOQL_Account();
@@ -34,7 +34,7 @@ public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selecto
34
34
35
35
The object permissions, field-level security, and sharing rules are enforced. Class sharing mode is ignored (`without sharing`).
36
36
37
-
```apex
37
+
```apex title="ExampleController.cls"
38
38
public without sharing class ExampleController {
39
39
public static List<Account> getAccountsByRecordType(String recordType) {
40
40
return SOQL_Account.query().toList();
@@ -51,7 +51,7 @@ Developers can control the sharing mode (`inherited sharing`, `with sharing`, an
51
51
52
52
**NOTE!** To make it work, always set `inherited sharing` in your selector class.
53
53
54
-
```apex
54
+
```apex title="SOQL_Account.cls"
55
55
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {
56
56
public static SOQL_Account query() {
57
57
return new SOQL_Account();
@@ -67,7 +67,7 @@ public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selecto
67
67
68
68
The object permissions and field-level permissions are ignored. Sharing rules are controlled by the sharing mode (`without sharing`).
69
69
70
-
```apex
70
+
```apex title="ExampleController.cls"
71
71
public without sharing class ExampleController {
72
72
public static List<Account> getAccountsByRecordType(String recordType) {
73
73
return SOQL_Account.query().toList();
@@ -79,7 +79,7 @@ public without sharing class ExampleController {
79
79
80
80
You can force the sharing mode for all of your queries.
81
81
82
-
```apex
82
+
```apex title="SOQL_Account.cls"
83
83
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {
84
84
public static SOQL_Account query() {
85
85
return new SOQL_Account();
@@ -96,7 +96,7 @@ public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selecto
96
96
97
97
The object permissions and field-level permissions are ignored. Sharing rules are controlled by the sharing mode specified in the `query()` method (`.withSharing()`).
98
98
99
-
```apex
99
+
```apex title="ExampleController.cls"
100
100
public with sharing class ExampleController {
101
101
public static List<Account> getAccountsByRecordType(String recordType) {
102
102
return SOQL_Account.query().toList();
@@ -109,7 +109,7 @@ public with sharing class ExampleController {
109
109
110
110
You can force the sharing mode for all of your queries.
111
111
112
-
```apex
112
+
```apex title="SOQL_Account.cls"
113
113
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {
114
114
public static SOQL_Account query() {
115
115
return new SOQL_Account();
@@ -126,7 +126,7 @@ public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selecto
126
126
127
127
The object permissions and field-level permissions are ignored. Sharing rules are controlled by the sharing mode specified in the `query()` method (`.withoutSharing()`).
128
128
129
-
```apex
129
+
```apex title="ExampleController.cls"
130
130
public with sharing class ExampleController {
131
131
public static List<Account> getAccountsByRecordType(String recordType) {
0 commit comments