diff --git a/website/src/pages/playground.js b/website/src/pages/playground.js index ae5f71fb..5a812869 100644 --- a/website/src/pages/playground.js +++ b/website/src/pages/playground.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import Layout from '@theme/Layout'; import Heading from '@theme/Heading'; @@ -22,6 +22,9 @@ class SOQLToSOQLLibTranslator { this.reset(); const cleanQuery = soqlQuery.trim().replace(/\s+/g, ' '); + // Check if query explicitly specifies SYSTEM_MODE + const hasSystemMode = /WITH\s+SYSTEM_MODE/i.test(cleanQuery); + // Extract SObject from FROM clause this.parseSObjectType(cleanQuery); @@ -49,7 +52,7 @@ class SOQLToSOQLLibTranslator { // Parse FOR clause this.parseForClause(cleanQuery); - return this.generateSOQLLibCode(); + return this.generateSOQLLibCode(hasSystemMode); } catch (error) { return `// Error parsing SOQL: ${error.message}\n// Please check your SOQL syntax and try again.`; } @@ -677,7 +680,7 @@ class SOQLToSOQLLibTranslator { } } - generateSOQLLibCode() { + generateSOQLLibCode(hasSystemMode = false) { let code = `SOQL.of(${this.sobjectType}.SObjectType)`; // Handle SELECT fields @@ -823,6 +826,12 @@ class SOQLToSOQLLibTranslator { } } + // Add system mode when WITH SYSTEM_MODE is specified in the query + if (hasSystemMode) { + code += '\n .systemMode()'; + code += '\n .withoutSharing()'; + } + // Add result method code += '\n .toList();'; @@ -1103,11 +1112,21 @@ FROM Account WHERE Industry = 'Technology' AND BillingCity = 'San Francisco' ORDER BY Name ASC -LIMIT 10`); +LIMIT 10 +WITH USER_MODE`); const [soqlLibOutput, setSoqlLibOutput] = useState(''); const [isLoading, setIsLoading] = useState(false); + // Trigger syntax highlighting when output changes + useEffect(() => { + if (typeof window !== 'undefined' && window.Prism && soqlLibOutput) { + setTimeout(() => { + window.Prism.highlightAll(); + }, 100); + } + }, [soqlLibOutput]); + const translator = new SOQLToSOQLLibTranslator(); const handleTranslate = () => { @@ -1134,65 +1153,65 @@ LIMIT 10`); }; const examples = [ - { - name: "Simple Query", - query: `SELECT Id, Name FROM Account WHERE Name LIKE '%Test%'` - }, + { + name: "Simple Query", + query: `SELECT Id, Name FROM Account WHERE Name LIKE '%Test%' WITH USER_MODE` + }, { name: "Multiple Conditions", - query: `SELECT Id, Name, Owner.Name FROM Account WHERE Industry = 'Technology' AND BillingCity = 'San Francisco'` + query: `SELECT Id, Name, Owner.Name FROM Account WHERE Industry = 'Technology' AND BillingCity = 'San Francisco' WITH USER_MODE` }, { name: "OR Conditions", - query: `SELECT Id, Name FROM Account WHERE Industry = 'Technology' OR Industry = 'Healthcare'` + query: `SELECT Id, Name FROM Account WHERE Industry = 'Technology' OR Industry = 'Healthcare' WITH USER_MODE` }, { name: "Parent Fields", - query: `SELECT Id, Name, CreatedBy.Id, CreatedBy.Name, Parent.Id, Parent.Name FROM Account` - }, - { - name: "Aggregate Query", - query: `SELECT Industry, COUNT(Id) total FROM Account GROUP BY Industry HAVING COUNT(Id) > 5` + query: `SELECT Id, Name, CreatedBy.Id, CreatedBy.Name, Parent.Id, Parent.Name FROM Account WITH USER_MODE` }, { name: "COUNT & SUM", - query: `SELECT CampaignId, COUNT(Id) totalRecords, SUM(Amount) totalAmount FROM Opportunity GROUP BY CampaignId` + query: `SELECT CampaignId, COUNT(Id) totalRecords, SUM(Amount) totalAmount FROM Opportunity GROUP BY CampaignId WITH USER_MODE` }, { name: "AVG & MIN", - query: `SELECT Industry, AVG(AnnualRevenue) avgRevenue, MIN(NumberOfEmployees) minEmployees FROM Account GROUP BY Industry` + query: `SELECT Industry, AVG(AnnualRevenue) avgRevenue, MIN(NumberOfEmployees) minEmployees FROM Account GROUP BY Industry WITH USER_MODE` }, { name: "SubQuery", - query: `SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account` + query: `SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account WITH USER_MODE` }, { name: "Complex WHERE", - query: `SELECT Id FROM Account WHERE Industry = 'IT' AND ((Name = 'My Account' AND NumberOfEmployees >= 10) OR (Name = 'My Account 2' AND NumberOfEmployees <= 20))` + 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` }, { name: "LIKE Patterns", - query: `SELECT Id, Name FROM Account WHERE Name LIKE 'Test%' AND BillingCity LIKE '%Francisco%'` + query: `SELECT Id, Name FROM Account WHERE Name LIKE 'Test%' AND BillingCity LIKE '%Francisco%' WITH USER_MODE` }, { name: "IN Operator", - query: `SELECT Id, Name FROM Account WHERE Industry IN ('Technology', 'Healthcare', 'Finance')` + query: `SELECT Id, Name FROM Account WHERE Industry IN ('Technology', 'Healthcare', 'Finance') WITH USER_MODE` }, { name: "ORDER BY Multiple", - query: `SELECT Id, Name, Industry FROM Account ORDER BY Name DESC, Industry ASC LIMIT 50` + query: `SELECT Id, Name, Industry FROM Account ORDER BY Name DESC, Industry ASC LIMIT 50 WITH USER_MODE` }, { name: "Complex Query", - query: `SELECT Id, Name FROM Account WHERE (Industry = 'Technology' OR Industry = 'Healthcare') AND NumberOfEmployees > 100 ORDER BY Name LIMIT 20` + query: `SELECT Id, Name FROM Account WHERE (Industry = 'Technology' OR Industry = 'Healthcare') AND NumberOfEmployees > 100 ORDER BY Name LIMIT 20 WITH USER_MODE` }, { name: "Boolean Fields", - query: `SELECT Id, Name FROM Account WHERE IsDeleted = false AND IsPersonAccount = true` + query: `SELECT Id, Name FROM Account WHERE IsDeleted = false AND IsPersonAccount = true WITH USER_MODE` }, { name: "NULL Checks", - query: `SELECT Id, Name FROM Account WHERE ParentId != null AND BillingCity = null` + query: `SELECT Id, Name FROM Account WHERE ParentId != null AND BillingCity = null WITH USER_MODE` + }, + { + name: "System Mode", + query: `SELECT Id, Name, CreatedBy.Id, CreatedBy.Name, Parent.Id, Parent.Name FROM Account WITH SYSTEM_MODE` } ]; @@ -1208,7 +1227,7 @@ LIMIT 10`);
- SOQL to SOQL Lib Playground + SOQL Lib Playground

Paste your traditional SOQL query and see how it translates to SOQL Lib syntax. @@ -1232,14 +1251,14 @@ LIMIT 10`);

-
+
{/* Input Panel */} -
+

Traditional SOQL

@@ -1247,16 +1266,16 @@ LIMIT 10`);