Skip to content

Commit bcdec7e

Browse files
committed
More examples
1 parent 35899b1 commit bcdec7e

File tree

1 file changed

+62
-43
lines changed

1 file changed

+62
-43
lines changed

website/src/pages/playground.js

Lines changed: 62 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import Layout from '@theme/Layout';
33
import Heading from '@theme/Heading';
44

@@ -22,6 +22,9 @@ class SOQLToSOQLLibTranslator {
2222
this.reset();
2323
const cleanQuery = soqlQuery.trim().replace(/\s+/g, ' ');
2424

25+
// Check if query explicitly specifies SYSTEM_MODE
26+
const hasSystemMode = /WITH\s+SYSTEM_MODE/i.test(cleanQuery);
27+
2528
// Extract SObject from FROM clause
2629
this.parseSObjectType(cleanQuery);
2730

@@ -49,7 +52,7 @@ class SOQLToSOQLLibTranslator {
4952
// Parse FOR clause
5053
this.parseForClause(cleanQuery);
5154

52-
return this.generateSOQLLibCode();
55+
return this.generateSOQLLibCode(hasSystemMode);
5356
} catch (error) {
5457
return `// Error parsing SOQL: ${error.message}\n// Please check your SOQL syntax and try again.`;
5558
}
@@ -677,7 +680,7 @@ class SOQLToSOQLLibTranslator {
677680
}
678681
}
679682

680-
generateSOQLLibCode() {
683+
generateSOQLLibCode(hasSystemMode = false) {
681684
let code = `SOQL.of(${this.sobjectType}.SObjectType)`;
682685

683686
// Handle SELECT fields
@@ -823,6 +826,12 @@ class SOQLToSOQLLibTranslator {
823826
}
824827
}
825828

829+
// Add system mode when WITH SYSTEM_MODE is specified in the query
830+
if (hasSystemMode) {
831+
code += '\n .systemMode()';
832+
code += '\n .withoutSharing()';
833+
}
834+
826835
// Add result method
827836
code += '\n .toList();';
828837

@@ -1103,11 +1112,21 @@ FROM Account
11031112
WHERE Industry = 'Technology'
11041113
AND BillingCity = 'San Francisco'
11051114
ORDER BY Name ASC
1106-
LIMIT 10`);
1115+
LIMIT 10
1116+
WITH USER_MODE`);
11071117

11081118
const [soqlLibOutput, setSoqlLibOutput] = useState('');
11091119
const [isLoading, setIsLoading] = useState(false);
11101120

1121+
// Trigger syntax highlighting when output changes
1122+
useEffect(() => {
1123+
if (typeof window !== 'undefined' && window.Prism && soqlLibOutput) {
1124+
setTimeout(() => {
1125+
window.Prism.highlightAll();
1126+
}, 100);
1127+
}
1128+
}, [soqlLibOutput]);
1129+
11111130
const translator = new SOQLToSOQLLibTranslator();
11121131

11131132
const handleTranslate = () => {
@@ -1134,65 +1153,65 @@ LIMIT 10`);
11341153
};
11351154

11361155
const examples = [
1137-
{
1138-
name: "Simple Query",
1139-
query: `SELECT Id, Name FROM Account WHERE Name LIKE '%Test%'`
1140-
},
1156+
{
1157+
name: "Simple Query",
1158+
query: `SELECT Id, Name FROM Account WHERE Name LIKE '%Test%' WITH USER_MODE`
1159+
},
11411160
{
11421161
name: "Multiple Conditions",
1143-
query: `SELECT Id, Name, Owner.Name FROM Account WHERE Industry = 'Technology' AND BillingCity = 'San Francisco'`
1162+
query: `SELECT Id, Name, Owner.Name FROM Account WHERE Industry = 'Technology' AND BillingCity = 'San Francisco' WITH USER_MODE`
11441163
},
11451164
{
11461165
name: "OR Conditions",
1147-
query: `SELECT Id, Name FROM Account WHERE Industry = 'Technology' OR Industry = 'Healthcare'`
1166+
query: `SELECT Id, Name FROM Account WHERE Industry = 'Technology' OR Industry = 'Healthcare' WITH USER_MODE`
11481167
},
11491168
{
11501169
name: "Parent Fields",
1151-
query: `SELECT Id, Name, CreatedBy.Id, CreatedBy.Name, Parent.Id, Parent.Name FROM Account`
1152-
},
1153-
{
1154-
name: "Aggregate Query",
1155-
query: `SELECT Industry, COUNT(Id) total FROM Account GROUP BY Industry HAVING COUNT(Id) > 5`
1170+
query: `SELECT Id, Name, CreatedBy.Id, CreatedBy.Name, Parent.Id, Parent.Name FROM Account WITH USER_MODE`
11561171
},
11571172
{
11581173
name: "COUNT & SUM",
1159-
query: `SELECT CampaignId, COUNT(Id) totalRecords, SUM(Amount) totalAmount FROM Opportunity GROUP BY CampaignId`
1174+
query: `SELECT CampaignId, COUNT(Id) totalRecords, SUM(Amount) totalAmount FROM Opportunity GROUP BY CampaignId WITH USER_MODE`
11601175
},
11611176
{
11621177
name: "AVG & MIN",
1163-
query: `SELECT Industry, AVG(AnnualRevenue) avgRevenue, MIN(NumberOfEmployees) minEmployees FROM Account GROUP BY Industry`
1178+
query: `SELECT Industry, AVG(AnnualRevenue) avgRevenue, MIN(NumberOfEmployees) minEmployees FROM Account GROUP BY Industry WITH USER_MODE`
11641179
},
11651180
{
11661181
name: "SubQuery",
1167-
query: `SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account`
1182+
query: `SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account WITH USER_MODE`
11681183
},
11691184
{
11701185
name: "Complex WHERE",
1171-
query: `SELECT Id FROM Account WHERE Industry = 'IT' AND ((Name = 'My Account' AND NumberOfEmployees >= 10) OR (Name = 'My Account 2' AND NumberOfEmployees <= 20))`
1186+
query: `SELECT Id FROM Account WHERE Industry = 'IT' AND ((Name = 'My Account' AND NumberOfEmployees >= 10) OR (Name = 'My Account 2' AND NumberOfEmployees <= 20)) WITH USER_MODE`
11721187
},
11731188
{
11741189
name: "LIKE Patterns",
1175-
query: `SELECT Id, Name FROM Account WHERE Name LIKE 'Test%' AND BillingCity LIKE '%Francisco%'`
1190+
query: `SELECT Id, Name FROM Account WHERE Name LIKE 'Test%' AND BillingCity LIKE '%Francisco%' WITH USER_MODE`
11761191
},
11771192
{
11781193
name: "IN Operator",
1179-
query: `SELECT Id, Name FROM Account WHERE Industry IN ('Technology', 'Healthcare', 'Finance')`
1194+
query: `SELECT Id, Name FROM Account WHERE Industry IN ('Technology', 'Healthcare', 'Finance') WITH USER_MODE`
11801195
},
11811196
{
11821197
name: "ORDER BY Multiple",
1183-
query: `SELECT Id, Name, Industry FROM Account ORDER BY Name DESC, Industry ASC LIMIT 50`
1198+
query: `SELECT Id, Name, Industry FROM Account ORDER BY Name DESC, Industry ASC LIMIT 50 WITH USER_MODE`
11841199
},
11851200
{
11861201
name: "Complex Query",
1187-
query: `SELECT Id, Name FROM Account WHERE (Industry = 'Technology' OR Industry = 'Healthcare') AND NumberOfEmployees > 100 ORDER BY Name LIMIT 20`
1202+
query: `SELECT Id, Name FROM Account WHERE (Industry = 'Technology' OR Industry = 'Healthcare') AND NumberOfEmployees > 100 ORDER BY Name LIMIT 20 WITH USER_MODE`
11881203
},
11891204
{
11901205
name: "Boolean Fields",
1191-
query: `SELECT Id, Name FROM Account WHERE IsDeleted = false AND IsPersonAccount = true`
1206+
query: `SELECT Id, Name FROM Account WHERE IsDeleted = false AND IsPersonAccount = true WITH USER_MODE`
11921207
},
11931208
{
11941209
name: "NULL Checks",
1195-
query: `SELECT Id, Name FROM Account WHERE ParentId != null AND BillingCity = null`
1210+
query: `SELECT Id, Name FROM Account WHERE ParentId != null AND BillingCity = null WITH USER_MODE`
1211+
},
1212+
{
1213+
name: "System Mode",
1214+
query: `SELECT Id, Name, CreatedBy.Id, CreatedBy.Name, Parent.Id, Parent.Name FROM Account WITH SYSTEM_MODE`
11961215
}
11971216
];
11981217

@@ -1208,7 +1227,7 @@ LIMIT 10`);
12081227
<div className="container mx-auto px-4 py-8 max-w-7xl">
12091228
<div className="text-center mb-8">
12101229
<Heading as="h1" className="text-4xl font-bold mb-4">
1211-
SOQL to SOQL Lib Playground
1230+
SOQL Lib Playground
12121231
</Heading>
12131232
<p className="text-lg text-gray-600 dark:text-gray-300 max-w-2xl mx-auto">
12141233
Paste your traditional SOQL query and see how it translates to SOQL Lib syntax.
@@ -1232,31 +1251,31 @@ LIMIT 10`);
12321251
</div>
12331252
</div>
12341253

1235-
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
1254+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6 items-start">
12361255
{/* Input Panel */}
1237-
<div className="space-y-4">
1256+
<div className="space-b-4 h-full">
12381257
<div className="flex items-center justify-between">
12391258
<h2 className="text-xl font-semibold">Traditional SOQL</h2>
12401259
<button
12411260
onClick={handleClear}
1242-
className="px-3 py-1 text-sm bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 rounded transition-colors"
1261+
className="px-3 py-1 text-sm bg-gray-200 dark:bg-gray-700 hover:bg-gray-300 dark:hover:bg-gray-600 rounded transition-colors border-none"
12431262
>
12441263
Clear
12451264
</button>
12461265
</div>
12471266
<textarea
12481267
value={soqlInput}
12491268
onChange={(e) => setSoqlInput(e.target.value)}
1250-
className="w-full h-64 p-4 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 font-mono text-sm resize-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
1269+
className="w-full h-80 p-4 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 font-mono text-sm resize-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
12511270
placeholder="Enter your SOQL query here..."
12521271
/>
12531272
</div>
12541273

12551274
{/* Output Panel */}
1256-
<div className="space-y-4">
1275+
<div className="space-y-4 h-full">
12571276
<h2 className="text-xl font-semibold">SOQL Lib Syntax</h2>
12581277
<div className="relative">
1259-
<pre className="w-full h-64 p-4 border border-gray-300 dark:border-gray-600 rounded-lg bg-gray-50 dark:bg-gray-900 font-mono text-sm overflow-auto">
1278+
<pre className="w-full h-80 p-4 border border-gray-300 dark:border-gray-600 rounded-lg bg-gray-50 dark:bg-gray-900 font-mono text-sm overflow-auto">
12601279
<code className="language-java">{soqlLibOutput || '// Your translated SOQL Lib code will appear here...'}</code>
12611280
</pre>
12621281
{soqlLibOutput && (
@@ -1296,21 +1315,21 @@ LIMIT 10`);
12961315
{/* Info Section */}
12971316
<div className="mt-12 p-6 bg-blue-50 dark:bg-blue-900/20 rounded-lg">
12981317
<h3 className="text-lg font-semibold mb-3">💡 How it works</h3>
1299-
<ul className="space-y-2 text-sm text-gray-700 dark:text-gray-300">
1300-
<li><strong>Field Selection:</strong> Converts SELECT fields to <code>.with()</code> methods</li>
1301-
<li><strong>Relationships:</strong> Transforms parent.field syntax to <code>.with('Parent', fields)</code></li>
1302-
<li><strong>WHERE Conditions:</strong> Parses conditions into <code>SOQL.Filter</code> and <code>SOQL.FilterGroup</code></li>
1303-
<li><strong>Filter Operations:</strong> Maps SOQL operators to methods like <code>.equal()</code>, <code>.contains()</code>, <code>.greaterThan()</code></li>
1304-
<li><strong>Logic Operators:</strong> AND conditions are grouped, OR uses <code>.anyConditionMatching()</code></li>
1305-
<li><strong>Aggregate Functions:</strong> Maps to specific methods like <code>.count()</code>, <code>.sum()</code></li>
1306-
<li><strong>ORDER BY:</strong> Translates to <code>.orderBy()</code> with direction methods</li>
1307-
<li><strong>LIMIT/OFFSET:</strong> Converts to <code>.setLimit()</code> and <code>.offset()</code></li>
1308-
</ul>
1318+
<ul className="space-y-2 text-sm text-gray-700 dark:text-gray-300">
1319+
<li><strong>Field Selection:</strong> Converts SELECT fields to <code>.with()</code> methods - <a href="/soql/api/soql#with" className="text-blue-600 hover:text-blue-800 underline">API docs</a></li>
1320+
<li><strong>Relationships:</strong> Transforms parent.field syntax to <code>.with('Parent', fields)</code> - <a href="/soql/api/soql#with-related-field" className="text-blue-600 hover:text-blue-800 underline">API docs</a></li>
1321+
<li><strong>WHERE Conditions:</strong> Parses conditions into <code>SOQL.Filter</code> and <code>SOQL.FilterGroup</code> - <a href="/soql/api/soql-filter" className="text-blue-600 hover:text-blue-800 underline">Filter API</a> | <a href="/soql/api/soql-filters-group" className="text-blue-600 hover:text-blue-800 underline">FilterGroup API</a></li>
1322+
<li><strong>Filter Operations:</strong> Maps SOQL operators to methods like <code>.equal()</code>, <code>.contains()</code>, <code>.greaterThan()</code> - <a href="/soql/api/soql-filter#comparators" className="text-blue-600 hover:text-blue-800 underline">API docs</a></li>
1323+
<li><strong>Logic Operators:</strong> AND conditions are grouped, OR uses <code>.anyConditionMatching()</code> - <a href="/soql/api/soql-filters-group#anyconditionmatching" className="text-blue-600 hover:text-blue-800 underline">API docs</a></li>
1324+
<li><strong>Aggregate Functions:</strong> Maps to specific methods like <code>.count()</code>, <code>.sum()</code> - <a href="/soql/api/soql#aggregate-functions" className="text-blue-600 hover:text-blue-800 underline">API docs</a></li>
1325+
<li><strong>ORDER BY:</strong> Translates to <code>.orderBy()</code> with direction methods - <a href="/soql/api/soql#order-by" className="text-blue-600 hover:text-blue-800 underline">API docs</a></li>
1326+
<li><strong>LIMIT/OFFSET:</strong> Converts to <code>.setLimit()</code> and <code>.offset()</code> - <a href="/soql/api/soql#limit" className="text-blue-600 hover:text-blue-800 underline">LIMIT</a> | <a href="/soql/api/soql#offset" className="text-blue-600 hover:text-blue-800 underline">OFFSET</a></li>
1327+
</ul>
13091328

13101329
<p className="mt-4 text-sm text-gray-600 dark:text-gray-400">
13111330
<strong>Note:</strong> This is a learning tool that covers most common SOQL patterns.
13121331
Complex nested conditions may need manual refinement. Check the
1313-
<a href="/soql/getting-started" className="text-blue-600 hover:text-blue-800 underline"> full documentation</a> for advanced features.
1332+
<a href="/soql/examples/select" className="text-blue-600 hover:text-blue-800 underline"> full documentation</a> for advanced features.
13141333
</p>
13151334
</div>
13161335
</div>

0 commit comments

Comments
 (0)