{"id":1833,"date":"2026-10-12T13:00:00","date_gmt":"2026-10-12T07:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/"},"modified":"2026-11-22T11:01:25","modified_gmt":"2026-11-22T05:31:25","slug":"sosl-interview-questions-dynamic-soql","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/","title":{"rendered":"SOSL Interview Questions and Dynamic SOQL (60+ Q&amp;A)"},"content":{"rendered":"\r\n<p class=\"wp-block-paragraph\">SOSL Interview Questions test whether you know when to search and when to query. Interviewers also mix in dynamic SOQL, because both build flexible searches at run time. So expect questions on syntax, limits, testing and SOQL injection.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Last reviewed for the Winter &#8217;27 release (November 2026).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">This is Part 8 of our Salesforce developer interview series. It covers SOSL and dynamic SOQL, from simple to tricky, with short answers. It builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/sosl-in-salesforce-search-apex\/\">SOSL in Salesforce<\/a>, <a href=\"https:\/\/swapnilzambare.com\/blog\/dynamic-soql-in-apex-injection\/\">dynamic SOQL and injection<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/soql-relationship-interview-questions-aggregate\/\">Part 7 on relationship and aggregate queries<\/a>.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">What are SOSL Interview Questions?<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">SOSL Interview Questions test the Salesforce Object Search Language. SOSL searches text across many objects and fields at once, using the search index. In contrast, SOQL reads exact matches from one object and its relatives.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Think of a shop. SOQL is like asking for &#8220;aisle 4, shelf 2, blue mugs&#8221;. SOSL is like typing &#8220;blue&#8221; into the shop search bar and getting mugs, shirts and pens together.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Why SOSL Interview Questions Matter<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Search features appear in almost every app. Here is why SOSL Interview Questions matter.<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>First, choosing SOSL or SOQL is a classic design question.<\/li>\r\n\r\n<li>Also, SOSL has its own limits and return types.<\/li>\r\n\r\n<li>Next, SOSL in tests returns nothing unless you set fixed results.<\/li>\r\n\r\n<li>Dynamic queries open the door to SOQL injection.<\/li>\r\n\r\n<li>Finally, global search bars and lookups depend on these skills.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">So clear answers show you can build safe, fast search.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">How to Prepare for SOSL Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Preparing for SOSL Interview Questions follows five steps. First, learn the FIND, IN and RETURNING syntax. Next, practise reading the List of Lists result. Then learn Search.query and Database.query for dynamic strings. After that, study injection and how bind variables stop it. Finally, write a test with Test.setFixedSearchResults and explain each line.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-diagram-1-1024x640.png\" alt=\"SOSL Interview Questions diagram showing five steps to prepare for SOSL and dynamic SOQL questions\" class=\"wp-image-1831\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Five steps to prepare for SOSL and dynamic SOQL questions.<\/figcaption><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">SOSL Clauses at a Glance<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The table below lists the main SOSL clauses.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table><thead><tr><th>Clause<\/th><th>Purpose<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>FIND<\/td><td>Search term<\/td><td>FIND &#8216;Apex*&#8217;<\/td><\/tr><tr><td>IN<\/td><td>Which field group to search<\/td><td>IN NAME FIELDS<\/td><\/tr><tr><td>RETURNING<\/td><td>Objects and fields to return<\/td><td>RETURNING Course__c(Name, Fee__c)<\/td><\/tr><tr><td>WHERE<\/td><td>Filter rows per object<\/td><td>Course__c(Name WHERE Is_Online__c = true)<\/td><\/tr><tr><td>ORDER BY<\/td><td>Sort rows per object<\/td><td>Contact(Name ORDER BY Name)<\/td><\/tr><tr><td>LIMIT<\/td><td>Max rows per object or overall<\/td><td>LIMIT 20<\/td><\/tr><tr><td>WITH<\/td><td>Extra filters, such as division or snippet<\/td><td>WITH SNIPPET<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">SOSL vs SOQL<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The table below compares the two languages, the most common question here.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>SOSL<\/th><th>SOQL<\/th><\/tr><\/thead><tbody><tr><td>Searches<\/td><td>Many objects at once<\/td><td>One object plus related<\/td><\/tr><tr><td>Matching<\/td><td>Words in the search index<\/td><td>Exact field filters<\/td><\/tr><tr><td>Result in Apex<\/td><td>List of List of sObject<\/td><td>List of sObject<\/td><\/tr><tr><td>Limit per transaction<\/td><td>20 searches<\/td><td>100 queries<\/td><\/tr><tr><td>Max rows<\/td><td>2,000 per search<\/td><td>50,000 per transaction<\/td><\/tr><tr><td>Best for<\/td><td>Text search across objects<\/td><td>Known object and filters<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">When to use which is simple. Use SOSL when you search words across objects, while SOQL fits when you know the object and exact filters.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-diagram-2-1024x640.png\" alt=\"SOSL Interview Questions diagram comparing SOSL and SOQL\" class=\"wp-image-1832\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">SOSL vs SOQL.<\/figcaption><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Basic SOSL Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">These SOSL Interview Questions cover syntax and core rules.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on SOSL Syntax<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q1: What is SOSL?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">SOSL is Salesforce Object Search Language, used to <a href=\"https:\/\/swapnilzambare.com\/blog\/sosl-in-salesforce-search-apex\/\">search text across objects<\/a>. So one search can return accounts, contacts and custom records.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: give the one line difference: SOQL reads one object by filters, SOSL searches words across many objects.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q2: Write a simple SOSL search in Apex.<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">List&lt;List&lt;SObject&gt;&gt; res = [FIND &#8216;Apex&#8217; IN ALL FIELDS RETURNING Course__c(Name), Contact(Name)]. Then res[0] holds courses and res[1] holds contacts.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q3: What does SOSL return in Apex?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A List of List of sObject, one inner list per object in RETURNING. Also, the order matches the RETURNING order.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: How do you read the contacts from the result? Cast the inner list: (List&lt;Contact&gt;) res[1].<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q4: What quotes does FIND use in Apex and in the API?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In Apex, use single quotes, such as FIND &#8216;Apex&#8217;. However, in the API and Query Editor, use braces, such as FIND {Apex}.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: written tests often show the braces version. Spotting that it is API syntax, not Apex, wins marks.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q5: Which search groups can IN use?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">ALL FIELDS, NAME FIELDS, EMAIL FIELDS, PHONE FIELDS and SIDEBAR FIELDS. ALL FIELDS is the default.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q6: What wildcards does SOSL support?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">* matches zero or more characters, and ? matches exactly one. For example, FIND &#8216;Ap*&#8217; finds Apex and Apple.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Can a wildcard go at the start? Yes in SOSL, like *force, but it is slower.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q7: What is the minimum search term length?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Two characters, not counting wildcards. FIND &#8216;a*&#8217; fails.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">SOSL needs enough text to use the search index well. In a search box, wait until the user types at least two characters before calling the search, so you do not send failing requests.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q8: Can you filter and sort inside RETURNING?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, each object can have its own WHERE, ORDER BY and LIMIT. For example, RETURNING Contact(Name WHERE Email != null ORDER BY Name LIMIT 5).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q9: How do you search for a phrase?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Wrap the phrase in double quotes inside the term, such as FIND &#8216;&#8221;intro to apex&#8221;&#8216;. Then words must appear together.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q10: What does RETURNING do in SOSL?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It lists which objects to search and which fields to return for each one. Without RETURNING, SOSL returns IDs from all searchable objects, which is rarely useful. Example: RETURNING Account(Name, Phone), Contact(Name, Email).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q11: Which logical operators does SOSL support?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">AND, OR and AND NOT, plus brackets for grouping. For example, FIND &#8216;apex AND NOT java&#8217;.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The operators must be in capitals. Writing &#8216;apex and java&#8217; treats and as a search word, not an operator.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on SOSL Limits<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">SOSL Interview Questions on limits are short, but candidates often mix them up.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q12: How many SOSL searches can a transaction run?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">20 SOSL searches per transaction. SOQL allows 100 in synchronous Apex.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Limit<\/th><th>SOSL<\/th><th>SOQL<\/th><\/tr><\/thead><tbody><tr><td>Statements per transaction<\/td><td>20<\/td><td>100 sync, 200 async<\/td><\/tr><tr><td>Records returned<\/td><td>2,000 per search<\/td><td>50,000 in total<\/td><\/tr><tr><td>Sees brand new records<\/td><td>Not always, the index lags<\/td><td>Yes, right away<\/td><\/tr><tr><td>Searches across objects<\/td><td>Many in one statement<\/td><td>One object plus related ones<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q13: How many records can one SOSL search return?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Up to 2,000 records in total per search.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The cap covers all objects in RETURNING together. Add a LIMIT and filters to each object so the most useful results fit, like RETURNING Contact(Name LIMIT 50), Lead(Name LIMIT 50).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q14: Does SOSL search every field type?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No, it searches text fields in the index, such as Name, Email, Phone and text fields. However, it does not search number or date fields directly.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Are long text area fields searched? Yes, with ALL FIELDS, because they are in the index.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q15: Why might a new record not appear in SOSL results right away?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The search index updates asynchronously. So a record saved seconds ago may not be searchable yet.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: this index lag is behind many trick questions. Mention it whenever a scenario involves new records.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q16: Can SOSL run in triggers?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, triggers have allowed SOSL since Spring &#8217;11. However, the index lag means new records may not match, so SOQL is usually safer there.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q17: Does SOSL count toward the SOQL query limit?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No. SOSL has its own limit of 20 searches per transaction, separate from the 100 SOQL queries. Rows returned by SOSL do not count toward the 50,000 SOQL row limit either.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q18: Does SOSL respect sharing?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, in <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-sharing-keywords-with-without-inherited\/\">with sharing classes<\/a> users see only records they can access. Also, add WITH USER_MODE for field and object security.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Intermediate SOSL Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">These SOSL Interview Questions cover dynamic search, testing and design choices.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Dynamic SOSL<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q19: How do you run a dynamic SOSL search?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use Search.query(searchString), which returns List&lt;List&lt;SObject&gt;&gt;. So you can build the term at run time.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: always add how you keep the term safe when you mention dynamic search.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q20: What does Search.find return?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It returns a Search.SearchResults object with extra details, such as snippets. Also, use it with WITH SNIPPET.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Which method gives snippets? Search.find with WITH SNIPPET, reading getSnippet() from each result.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q21: What is WITH SNIPPET?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It returns short text pieces that show where the term matched. For example, it is used for Knowledge article search.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q22: How do you keep dynamic SOSL safe?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Escape user input with <a href=\"https:\/\/swapnilzambare.com\/blog\/dynamic-soql-in-apex-injection\/\">String.escapeSingleQuotes<\/a> before building the string. Also, limit the objects and fields you return.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q23: How do you search only one field group, like email addresses?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use IN EMAIL FIELDS, like FIND &#8216;gmail.com&#8217; IN EMAIL FIELDS RETURNING Contact(Name, Email). It is faster and gives cleaner results than ALL FIELDS.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q24: How do you build a SOSL search for a lookup component?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Search NAME FIELDS for the typed term with a * wildcard and a small LIMIT. So results come back fast as the user types.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Testing SOSL<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q25: What does SOSL return in a test by default?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">An empty result, even if the test inserted matching records.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Test records are not added to the search index, so SOSL finds nothing. Use Test.setFixedSearchResults to tell Salesforce which records the next search should return.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q26: How do you control SOSL results in a test?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Call <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-test-class-basics-code-coverage\/\">Test.setFixedSearchResults<\/a> with a List of record Ids. Then the next SOSL returns those records.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: say the FIND term is ignored with fixed results. It shows you know what the test really checks.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q27: Do fixed search results ignore the WHERE and LIMIT in the search?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No, the filters in RETURNING still apply to the fixed Ids. However, the FIND term is ignored.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q28: How do you test that a search method returns only active records?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Insert active and inactive records, pass all their IDs to Test.setFixedSearchResults, and call the method. The WHERE filter in RETURNING still applies, so assert that only the active ones come back.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q29: Can you test dynamic SOSL with fixed results?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, Test.setFixedSearchResults works for Search.query too. So you test the logic, not the index.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on SOSL vs SOQL Choices<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q30: When is SOSL better than SOQL?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">When you search a word across many objects or many text fields. For example, a global search bar.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: What powers the global search bar? SOSL style search on the same index.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q31: When is SOQL better than SOSL?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">When you know the object and exact filters, or need relationship and aggregate queries. Also, SOQL sees records the moment they are saved.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: name aggregates and relationships. Those are the things SOSL cannot do.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q32: Is LIKE in SOQL a good substitute for SOSL?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Only for small objects, because a leading % wildcard <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-large-data-volumes\/\">cannot use an index<\/a>. So SOSL is faster for text search on large data.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q33: Can SOSL search inside files and attachments?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, global search can find text inside some file types stored as Salesforce Files, and SOSL can return ContentVersion records. Large files and some formats are not fully indexed, so do not rely on it for every document.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q34: Can SOSL query relationships?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Partly, you can read parent fields in RETURNING, such as Contact(Name, Account.Name). However, it has no subqueries.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Advanced SOSL Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">These SOSL Interview Questions cover dynamic SOQL, a topic interviewers pair with search.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Dynamic SOQL Basics<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q35: What is dynamic SOQL?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A SOQL query built as a String at run time and run with Database.query.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Point<\/th><th>Static SOQL<\/th><th>Dynamic SOQL<\/th><\/tr><\/thead><tbody><tr><td>Written as<\/td><td>Square brackets in code<\/td><td>A String<\/td><\/tr><tr><td>Checked<\/td><td>When you save the code<\/td><td>Only when it runs<\/td><\/tr><tr><td>Field names<\/td><td>Fixed<\/td><td>Can come from settings or users<\/td><\/tr><tr><td>Injection risk<\/td><td>None<\/td><td>Yes, if input is joined in<\/td><\/tr><tr><td>Use for<\/td><td>Most queries<\/td><td>Generic utilities, user built filters<\/td><\/tr><\/tbody><\/table><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q36: When do you need dynamic SOQL?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">When fields, objects or filters come from user choices or settings. For example, a report builder or a generic utility.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q37: What does Database.query return?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A List&lt;SObject&gt;. So you cast results, such as (List&lt;Course__c&gt;) Database.query(q).<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Can Database.query return one record? Yes, if exactly one row comes back you can assign it to a single sObject.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q38: How do you count records dynamically?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use Database.countQuery(q), which returns an Integer. The string must use SELECT COUNT().<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: Integer n = Database.countQuery(&#8216;SELECT COUNT() FROM Course__c WHERE Level__c = :level&#8217;); It is handy for showing a total before loading the records.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q39: How do you use a dynamic query in Batch Apex?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Return <a href=\"https:\/\/swapnilzambare.com\/blog\/batch-apex-start-execute-finish\/\">Database.getQueryLocator<\/a>(q) from start. Then the batch can process up to 50 million records.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q40: Can dynamic SOQL use bind variables?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Yes, simple variables in scope, such as :minFee. However, field access like :acc.Name does not work in Database.query.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: the acc.Name binding limit is a classic. Give the queryWithBinds fix with it.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q41: What is Database.queryWithBinds?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It runs a dynamic query with a Map of bind names and values. So binds no longer depend on local variable scope.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q42: What is the difference between Database.query and Database.getQueryLocator?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Database.query runs the query now and returns a List, so it is limited to 50,000 rows. Database.getQueryLocator returns a locator that Batch Apex uses to read up to 50 million records in chunks.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q43: How do you run a dynamic query in user mode?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Pass <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-crud-and-fls-user-mode\/\">AccessLevel.USER_MODE<\/a>, such as Database.query(q, AccessLevel.USER_MODE). Then sharing, object and field security apply.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on SOQL Injection<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q44: What is SOQL injection?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It is when user input changes the meaning of a dynamic query. For example, input that adds OR Name != null returns every row.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Can injection also affect SOSL? Yes, the same rules apply to Search.query strings.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q45: How do you prevent SOQL injection?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use bind variables first, because input never becomes query text. Also, escape strings with String.escapeSingleQuotes when binding is not possible.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q46: Does escapeSingleQuotes make every dynamic query safe?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No, it only escapes quotes in string values. So you still must allowlist field names, object names and sort directions.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: say escaping is a fallback, and binds come first. That order is what security reviewers look for.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q47: How do you safely accept a sort field from the user?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Check the field against a Set of allowed names or Schema describe results. Then reject anything else.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q48: How do you check that a field exists before adding it to a query?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/\">Schema.getGlobalDescribe<\/a> or SObjectType.getDescribe().fields.getMap().containsKey(name). So bad names never reach the query.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q49: How do you make a dynamic object name safe?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Check it against Schema.getGlobalDescribe().containsKey(name.toLowerCase()) or a fixed allow list before using it. Never join an object name from user input into a query without that check.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q50: Which tool flags injection risks in code?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-code-analyzer-pmd\/\">Salesforce Code Analyzer<\/a> flags unsafe dynamic SOQL. Also, security reviews for AppExchange check it.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Advanced Dynamic Patterns<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Advanced SOSL Interview Questions often end with a design pattern for generic queries.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q51: How do you build a query from a field set?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Read the field set members with Schema, join the API names and add them to the SELECT. So admins change fields without code.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q52: How do you query all fields of an object?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use FIELDS(ALL) with a LIMIT of 200 or less, or build the list from describe results. However, select only what you need in real code.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q53: What are FIELDS(STANDARD) and FIELDS(CUSTOM)?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">They return standard or custom fields without listing them. Also, FIELDS(ALL) and FIELDS(CUSTOM) need a LIMIT of 200 or less.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Can FIELDS(ALL) be used in Apex without LIMIT? No, it must have LIMIT 200 or less.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q54: How do you write a generic method that queries any object by Id?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Get the object from id.getSObjectType(), build the string and run Database.query with a bind. So one method serves many objects.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: mention binding the ID instead of joining it into the string, even in a generic method.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q55: Is dynamic SOQL slower than static SOQL?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Not at run time, because both use the same engine. However, static SOQL gets compile-time checks.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q56: Why do teams prefer static SOQL when possible?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Static SOQL catches field typos at compile time and blocks deletion of fields it uses. Also, injection is impossible.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Follow-up you may get: Does dynamic SOQL protect fields from deletion? No, Salesforce cannot see field names inside a String.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q57: How do you add an optional filter to a dynamic query only when the user fills it in?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Build a list of conditions, add each one only if its value is not blank, and join them with AND. Put the values in a bind map for Database.queryWithBinds, so the query stays safe and readable.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q58: How do you debug a dynamic query?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Print the final string with <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-debug-logs-replay-debugger\/\">System.debug<\/a>, then run it in the Query Editor. So you see exactly what Salesforce runs.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Scenario-Based SOSL Interview Questions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Scenario-based SOSL Interview Questions ask you to design or fix a search on the spot.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Design Scenarios<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q59: Build a search that finds a student by name, email or phone across Contact and Lead.<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use FIND :term IN ALL FIELDS RETURNING Contact(Name, Email), Lead(Name, Email) LIMIT 20. So one search covers both objects.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q60: A user picks filter fields on a screen. How do you query?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Build dynamic SOQL with allowlisted field names and Database.queryWithBinds for values. Then run it in user mode.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: list the three safety steps in order: allowlist names, bind values, user mode.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q61: Search must also find records created a few seconds ago. What do you do?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Use SOQL for the newest records, because the search index lags behind saves. Then merge both results.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: run the SOSL search as usual, plus a SOQL query on records with CreatedDate in the last few minutes that match the name with LIKE. Combine them in a Map by ID so no record appears twice.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q62: An admin wants to change searched fields without code. How?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Store the field list in <a href=\"https:\/\/swapnilzambare.com\/blog\/custom-metadata-in-apex\/\">Custom Metadata<\/a> and build the query at run time. Also, validate each field with describe.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q63: Search must return results the user cannot edit but can read. Is that a problem?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">No. SOSL returns records the user can read under sharing. Edit access is checked only when they try to save, so show the results normally and let the save handle permissions.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q64: You need typo-tolerant search on course names. What do you use?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">SOSL with wildcards is the closest built in option, but it does not correct real spelling mistakes.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A term like apex* finds Apex Basics and Apex Advanced, because it matches word starts. For true typo tolerance, users can use Einstein Search in the global search bar, or you add common misspellings as search synonyms in Setup. SOQL LIKE needs the exact letters, so it helps even less.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Questions on Fixing Code<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q65: A test for a search method always fails with zero results. Why?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">SOSL returns nothing in tests by default. So add Test.setFixedSearchResults before the call.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q66: Code builds WHERE Name = &#8216; + input + &#8216;. What is wrong?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">It allows SOQL injection, because the user&#8217;s text becomes part of the query.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A value like x&#8217; OR Name != &#8216; changes the filter and returns every row. Use a bind variable instead: WHERE Name = :input, which treats the input as data only.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q67: Database.query fails with &#8220;Variable does not exist: acc.Id&#8221;. Why?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Dynamic SOQL cannot bind field access. So copy the value to a local variable, or use queryWithBinds.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Interview tip: name both fixes, a local variable or queryWithBinds, to show you know the newer API.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q68: A trigger uses SOSL to find duplicates but misses records from the same load. Why?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The search index lags, so records saved in the same transaction are not searchable yet. So use SOQL with exact filters for duplicate checks.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q69: A search returns only 2,000 rows when more exist. What do you do?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Add filters and a LIMIT per object, because 2,000 is the cap. Then guide users to narrow their search.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q70: A dynamic query sometimes fails with &#8220;unexpected token&#8221;. How do you find the cause?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Print the final string with System.debug and run it in the Query Editor. Usually a value with a quote was joined in, a comma is missing between fields, or a blank filter left a dangling AND.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><strong>Q71: A dynamic ORDER BY takes user input directly. How do you fix it?<\/strong><\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Allowlist the field and the direction, ASC or DESC. Then reject any other value.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Example: String dir = (input == &#8216;DESC&#8217;) ? &#8216;DESC&#8217; : &#8216;ASC&#8217;; and only use the field if allowedFields.contains(field). Any other value falls back to a safe default.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">A Real SOSL Interview Questions Answer<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">A classic live task is &#8220;write a safe search method for a course finder, then test it&#8221;. Here is a strong answer.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code>public with sharing class CourseSearch {\r\n    public static List&lt;Course__c&gt; find(String term) {\r\n        if (String.isBlank(term) || term.length() &lt; 2) {\r\n            return new List&lt;Course__c&gt;();\r\n        }\r\n        String safe = String.escapeSingleQuotes(term) + '*';\r\n        List&lt;List&lt;SObject&gt;&gt; res = Search.query(\r\n            'FIND \\'' + safe + '\\' IN NAME FIELDS ' +\r\n            'RETURNING Course__c(Id, Name, Fee__c ORDER BY Name LIMIT 20)',\r\n            AccessLevel.USER_MODE\r\n        );\r\n        return (List&lt;Course__c&gt;) res[0];\r\n    }\r\n}\r\n\r\n@IsTest\r\nstatic void findsCourse() {\r\n    Course__c c = new Course__c(Name = 'Apex Basics', Fee__c = 300);\r\n    insert c;\r\n    Test.setFixedSearchResults(new List&lt;Id&gt;{ c.Id });\r\n    System.assertEquals(1, CourseSearch.find('Apex').size());\r\n}<\/code><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Explain that the method checks the length first, then escapes the term. Next, user mode applies security, and the test fixes the results. So the search is safe and testable.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Common Mistakes with SOSL Interview Questions<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Using SOSL where a simple SOQL filter would do.<\/li>\r\n\r\n<li>Forgetting that SOSL returns empty results in tests.<\/li>\r\n\r\n<li>Building dynamic queries with raw user input.<\/li>\r\n\r\n<li>Trusting escapeSingleQuotes for field or object names.<\/li>\r\n\r\n<li>Forgetting the 20 search and 2,000 row limits.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Best Practices for Answering SOSL Interview Questions<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Start by saying whether the task needs search or query.<\/li>\r\n\r\n<li>Show bind variables before any escaping.<\/li>\r\n\r\n<li>Mention user mode for both SOSL and dynamic SOQL.<\/li>\r\n\r\n<li>Add a test with fixed search results in your answer.<\/li>\r\n\r\n<li>Keep RETURNING lists short and limited.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.soql_sosl.meta\/soql_sosl\/sforce_api_calls_sosl_syntax.htm\" target=\"_blank\" rel=\"noopener noreferrer\">SOSL Syntax (SOQL and SOSL Reference)<\/a><\/li>\r\n\r\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_dynamic_soql.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Dynamic SOQL (Apex Developer Guide)<\/a><\/li>\r\n\r\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/pages_security_tips_soql_injection.htm\" target=\"_blank\" rel=\"noopener noreferrer\">SOQL Injection (Apex Developer Guide)<\/a><\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>SOSL Interview Questions cover search syntax, limits, testing and dynamic queries.<\/li>\r\n\r\n<li>Search words across objects with SOSL, while SOQL filters one object.<\/li>\r\n\r\n<li>Each transaction allows 20 searches and 2,000 rows per search.<\/li>\r\n\r\n<li>Use Test.setFixedSearchResults in tests.<\/li>\r\n\r\n<li>Prefer bind variables and user mode in dynamic SOQL.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Next, continue with <a href=\"https:\/\/swapnilzambare.com\/blog\/dml-interview-questions-database-class\/\">DML and Database class interview questions<\/a>, Part 9 of the series.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>SOSL Interview Questions test whether you know when to search and when to query. Interviewers also mix in dynamic SOQL, because both build flexible&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1830,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[250,8,90],"tags":[98,26,91,105],"swapz_series":[],"class_list":["post-1833","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developer-interview-questions","category-salesforce","category-salesforce-interview","tag-apex","tag-intermediate","tag-interview-questions","tag-soql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SOSL Interview Questions and Dynamic SOQL Answers<\/title>\n<meta name=\"description\" content=\"SOSL Interview Questions with answers: FIND, RETURNING, search groups, limits, Search.query, Database.query, queryWithBinds, injection and scenarios.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SOSL Interview Questions and Dynamic SOQL Answers\" \/>\n<meta property=\"og:description\" content=\"SOSL Interview Questions with answers: FIND, RETURNING, search groups, limits, Search.query, Database.query, queryWithBinds, injection and scenarios.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-12T07:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-22T05:31:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"SOSL Interview Questions and Dynamic SOQL (60+ Q&amp;A)\",\"datePublished\":\"2026-10-12T07:30:00+00:00\",\"dateModified\":\"2026-11-22T05:31:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/\"},\"wordCount\":3728,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/sosl-interview-questions-dynamic-soql-featured.png\",\"keywords\":[\"Apex\",\"Intermediate\",\"Interview Questions\",\"SOQL\"],\"articleSection\":[\"Developer Interview Questions\",\"Salesforce\",\"Salesforce Interview\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/\",\"name\":\"SOSL Interview Questions and Dynamic SOQL Answers\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/sosl-interview-questions-dynamic-soql-featured.png\",\"datePublished\":\"2026-10-12T07:30:00+00:00\",\"dateModified\":\"2026-11-22T05:31:25+00:00\",\"description\":\"SOSL Interview Questions with answers: FIND, RETURNING, search groups, limits, Search.query, Database.query, queryWithBinds, injection and scenarios.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/sosl-interview-questions-dynamic-soql-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/sosl-interview-questions-dynamic-soql-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"SOSL Interview Questions featured image: title card with a sample interview question and answer\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/sosl-interview-questions-dynamic-soql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SOSL Interview Questions and Dynamic SOQL (60+ Q&amp;A)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SOSL Interview Questions and Dynamic SOQL Answers","description":"SOSL Interview Questions with answers: FIND, RETURNING, search groups, limits, Search.query, Database.query, queryWithBinds, injection and scenarios.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/","og_locale":"en_US","og_type":"article","og_title":"SOSL Interview Questions and Dynamic SOQL Answers","og_description":"SOSL Interview Questions with answers: FIND, RETURNING, search groups, limits, Search.query, Database.query, queryWithBinds, injection and scenarios.","og_url":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-10-12T07:30:00+00:00","article_modified_time":"2026-11-22T05:31:25+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"SOSL Interview Questions and Dynamic SOQL (60+ Q&amp;A)","datePublished":"2026-10-12T07:30:00+00:00","dateModified":"2026-11-22T05:31:25+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/"},"wordCount":3728,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-featured.png","keywords":["Apex","Intermediate","Interview Questions","SOQL"],"articleSection":["Developer Interview Questions","Salesforce","Salesforce Interview"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/","url":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/","name":"SOSL Interview Questions and Dynamic SOQL Answers","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-featured.png","datePublished":"2026-10-12T07:30:00+00:00","dateModified":"2026-11-22T05:31:25+00:00","description":"SOSL Interview Questions with answers: FIND, RETURNING, search groups, limits, Search.query, Database.query, queryWithBinds, injection and scenarios.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/sosl-interview-questions-dynamic-soql-featured.png","width":2400,"height":1260,"caption":"SOSL Interview Questions featured image: title card with a sample interview question and answer"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/sosl-interview-questions-dynamic-soql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SOSL Interview Questions and Dynamic SOQL (60+ Q&amp;A)"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1833"}],"version-history":[{"count":2,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1833\/revisions"}],"predecessor-version":[{"id":3510,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1833\/revisions\/3510"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1830"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1833"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}