Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [soql]

Salesforce Object Query Language (SOQL), modeled on SQL, for accessing information saved in the Salesforce database.

4
votes
2answers
135 views

SOQL Query Where Id “In” Versus “Equals”(=)

I just stumbled upon a soql query where somebody did the following List<String> names = new List<String>{'John', 'Moe', 'Jeanette', 'Tony'}; List<Client__c> clients = [ SELECT ...
1
vote
1answer
38 views

Select Knowledge object in SOQL query

I'm trying to get all articles which are published and online. In my user I turned on all permission set and so one to have access to Knowledge. List<Knowledge__kav> myList= [SELECT Id, ...
0
votes
1answer
26 views

Is it possible to output an aggregate query to a Map<Id, List<Contact>>

Is it possible to output an aggregate query like this: Map<Id, List<Contact>> accountContactsMap = [SELECT aggregate query ...]; Where the Map key is the AccountId and the Map value is a ...
2
votes
2answers
124 views

is it possible to put a list directly in a SOQL query?

Is it possible to put a list directly in a SOQL query form the query editor? Let's say I wanted to query over a list, is the following possible in any way? SELECT Id, Email FROM Contact WHERE ...
1
vote
1answer
34 views

How do I optimize searching 3,000 records for an email that matches one on a lead?

Scenario A New Lead is inserted, if it matches criteria, the lead ownerid is Updated based on an email field on the lead. Problem Write code that takes the email address and queries all Users for ...
2
votes
0answers
19 views

Different behaviors for nested folders between classic and lightning

As we knew, in classic view folder and report are in a two-level structure. We can not create folder under folder in classic mode. Using SOQL like (Select OwnerId,Id from Report / Select from Folder)...
2
votes
1answer
26 views

How can I correctly convert List<SObjectField> into a list of comma-separated field names to build a SOQL String?

I've created a generic selector class as follows: public inherited sharing class DAO_SObjectSelector { public List<SObject> selectFor(Query query) { return Database.query(query.toString()); ...
2
votes
1answer
48 views

ParentId field not available for SOQL queries for the Account object

We are currently using Financial Services Cloud. When we go to the Account objects through the UI, there is the field Parent Account with API name ParentId. When I described the Account object ...
0
votes
1answer
19 views

Not able to delete all contentDocuments even as an admin in salesforce through apex

I am unable to delete the contentDocument(Files) owned by some other user even as an admin. I am trying it through apex. When I write a SOQL query it only retrieves records that are owned by me, if ...
3
votes
2answers
46 views

Dash Characters in Case Sensitive Deterministic Encryption Not Returned in SOQL

I am experiencing some unexpected results when querying a on a text field that is using Case Sensitive Deterministic Encryption. The field can contain dashes - in the string, when I use an exact ...
0
votes
1answer
39 views

How can you query all objects for fields with the same name?

For example, search all objects to find those that have a field named "Phone__c", and then query those fields. The intent is to then update the "Phone__c" field on all the records that exist in those ...
1
vote
1answer
20 views

SELECT SOQL on Custom Objects on Master-Detail Relationship

I have 2 custom objects addressMaster addressDetail - has foreign key field which is linked with the id field of the master. Here is SOQL I tried: SELECT Id, Name, sumchans__totalUnits__c, (SELECT ...
-1
votes
1answer
25 views

query on user record not returning any records when logged in as partner community user

The below query is returning zero records when i log in as partner community user. This query is being execute from a helper class which is being called from a trigger. The helper class and trigger ...
0
votes
1answer
19 views

if picklist label is queried using ToLabel() for an SObject, one cant save updates to this object if picklist is restricted

I followed the article below and got the picklist label-name instead of API name for an object. How to query 'Value' of a picklist rather than the 'API NAME', using SOQL? However ...
0
votes
1answer
38 views

Can't get SOQL statement to work for related object

I have an object Tourist_Details__c which has 2 child objects Contacts and Incidents__c. I already have a list of Incidents__c called results and now I need to get a list of all Tourist_Details__c ...
-1
votes
3answers
42 views

Please fill in the knowledge gap

Can anyone explain how this query works? There is no object with the name Contacts (Although it's the plural for Contact). SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account WHERE Id = <...
1
vote
1answer
22 views

Find what apex a cronjob Triggers

Scenario: Documentation on my org has a gap regarding a scheduled batch apex. This batch code updates a related list on the lead object. This List and process is call ‘nearby references’ and ‘find ...
-3
votes
1answer
77 views

Anyone can optimized this code for better explanation and easy to understand? [closed]

The function of this apex code is when Account has no Contacts the first contact created become the primary contact and when there is existing primary contact it cannot assign a other primary contact ...
1
vote
1answer
31 views

Querying User table from Community Super User profile in Communities

I am trying to query the user table from a controller called by a lightning component in Communities. User usr = [SELECT Id, Name, Email, Phone FROM User WHERE Id IN (Select OwnerId From ...
6
votes
1answer
291 views

count() returns a different amount than a simple select

SELECT count() FROM recordtype This returns 41 SELECT count(id) FROM recordtype This returns 41 SELECT id FROM recordtype This returns 33 rows I'm running these statements in SqlXplorer. Why the ...
1
vote
2answers
62 views

Getting an error in a SOQL

I am using below query in a batch class Query='Select Id FROM Contact WHERE SyncToMarketo__c = true ' + ' AND LastModifiedDate >= :date.today().addDays(-1) '; and get an error in ...
0
votes
1answer
25 views

How to soql to get salesforce reports in some specified conditions?

I know we can use soql to filter reports, like q=SELECT Name,Id,OwnerId FROM Report where+ OwnerId = xx. But I do not know how to get some reports that I do not own the execution privilege. Or some ...
1
vote
2answers
103 views

soql query not retrieving user records for Community User

List<String> userIds = new List<String>(); for(Note n : notes) { userIds.add(n.CreatedById); } Map<String, User> userMap = SystemContextMethodsHelper.getUsers(userIds); ...
0
votes
1answer
29 views

SOQL Lookup failing to retrieve values

I have following query that I am trying to run: select X__Region__r.Name, Operating_Unit__c from X__Worker__c where (X__Worker_Status_Current_WA__c = 'Active') Where X__Region__c is a lookup to ...
4
votes
0answers
24 views

Discrepancies between downloaded Setup Audit Trail and SetupAuditTrail query

I have noticed that delegated user logins (i.e. when a managed package admin logs in via grant login access) show up in the downloaded setup audit trail, but do not show up in a SOQL query of the ...
1
vote
1answer
32 views

SOQL query to get cases with case comment for open(processing) cases

here is our requirement we need to get cases with case comments where case comment done 3 days ago for open cases(we are considering Processing, work in progress and pending closure cases as open ...
1
vote
1answer
25 views

How to Query for logged in username [Python:SimpleSalesforce]?

Tried to do user=sf.query("SELECT Id, Name FROM User WHERE Id = :UserInfo.getUserId()" but getting error: content = [{u'errorCode': u'MALFORMED_QUERY', u'message': u'\nSELECT Id, Name from User ...
2
votes
1answer
23 views

Schedule Apex to Update Leads based on Tasks

Problem: I have two fields on my lead object that I need to back fill information into. These fields are filled by looking through each of tasks off the lead; grabbing date/times off these records ...
1
vote
1answer
285 views

SAQL vs SOQL vs SOSL vs SQL? [closed]

I have recently come across SAQL and I'd like to understand the differences between all the different ways to query against Salesforce APIs. The new einstein branding is too complex to get my head ...
0
votes
0answers
21 views

How to access Salesforce tables from unix shell script?

I have requirement to retrieve Salesforce source table counts via unix shell script. This shell script can be called in Informatica workflow as command task. Can someone please provide me with sample ...
0
votes
2answers
30 views

SOQL Query Causing For Loop to Not Function

pretty simple question that I just can't figure. The first snippet updates a record just fine, but the second snippet does nothing, even though it compiles just fine. Many thanks. Why does this work: ...
0
votes
2answers
32 views

Dynamic Batch apex with sobject iteration

I have a batch apex which takes the record from source object (can vary like Opportunity, Opportunity line item etc) and paste the record into target object i.e Opportunity_Prod_Batch_Record__c (fixed)...
3
votes
2answers
63 views

SUM of time field in SOQL

following is my SOQL I want total time spent on the same date. But sum is not supported for time field. is there any other option to do that. Select id,Case__c,SUM(Time__c),Date__c from ...
3
votes
2answers
59 views

LAST_N_MONTHS:N in SOQL

Has anyone ever faced an issue with LAST_N_MONTHS:N in SOQL? As per salesforce doc: For the number n provided, starts 00:00:00 of the last day of the previous month and continues for the past n ...
0
votes
1answer
19 views

apex query error with local variable

This my query : Date todayDate = date.today(); PropositionCommerciales = [SELECT Id, Compte__c.Id AccountId, ...
4
votes
2answers
60 views

Hitting the governor limit of SOQL in recursion, how can I avoid this in recursion of getTreeData method?

public class BOM_Container_TreeController { @AuraEnabled public static String getTreeData(String acId){ List<HS_Sales__Bill_Of_Materials__c> boms = [Select Id , Name from ...
1
vote
2answers
48 views

SOQL governor reached using multiple strike_lookup

I'm developing a custom lighting component, in which I have a table with 2 columns, each cell is composed by a strike_lookup Everything works as expected until I have too many rows, thus too many ...
1
vote
1answer
32 views

How to get level change date

I have a field on Account named Level. It contains values viz., Manager, Assistant Manager, etc. I need to retrieve accounts with their level in Jan 2017 and Dec2018. How to get the data. I tried ...
0
votes
2answers
33 views

SOQL to get previous months records till date

I have a requirement where I need to fetch records from Previous 3 months to Today. When I tried using Last_n_Months :2 binding, I can only retrieve previous months records excluding current month. ...
0
votes
1answer
32 views

Extending WHERE clause with condition from another query

I have two different queries which give the results, however is there a way to combine 2 queries and extend the WHERE clause as below: Query 1 SELECT Id, Name, (Select ID, Name, Object_C__r.Name ...
0
votes
0answers
14 views

Pass Variable to Endpoint from External Data Object Filter - Salesforce Connect

I have an endpoint that I am utilizing for External Data Objects in Salesforce Connect. I pass a value from the SOQL filter (WHERE clause), but as we know this is only applicable if there is a field ...
0
votes
1answer
33 views

How to get real data from AccountHistory?

when I get data from AccountHistory, including "deleted and archived records", I get all my tracking history. The problem is that the column Id doesn't match any id in my org. For example, these two ...
-2
votes
1answer
34 views

Write an aggregate query to return the sum of Closed Won opportunities for the current year (Close Date = THIS YEAR) grouped by the account [closed]

AggregateResult[] groupedResults = [SELECT AVG(Amount)aver FROM Opportunity]; Object avgAmount = groupedResults[0].get('aver');
-3
votes
1answer
35 views

how can i write code to avoid same email of listed contacts [closed]

List <contact> con = new list<contact> map<id,contact> cont = new map<id,contact> For (cont em : con) { con.put(em.email,em) } You have a list of Contacts. From this list, ...
2
votes
1answer
29 views

SOQL join in a Parent Child for same table (Account)

I want to write this simple soql query where in Account there is a ParentId and with it would want to bring the name of this parent (Hierarchy field) Something like: select Id, Name, (select Name ...
0
votes
1answer
14 views

How to query parent record picklist field value in dynamic WHERE clause

I want to develop a WHERE clause for a dynamic SOQL query in a utility class. The WHERE clause should lookup a parent record picklist field value.The relationship between Shared_Contact__c and Contact ...
0
votes
0answers
35 views

How can I alias a column in SOQL for an object that doesn't support field aggregates?

We want to alias the count() value in a SOQL query for FeedItem however it seems that column naming can only be done when a field is present in count(). Select count() from FeedItem works fine, but ...
2
votes
1answer
27 views

SOQL Query for Date = THISYEAR

I'm trying to write a SOQL query that uses " WHERE Date__c = THISYEAR() " but that isn't working... I think what i'd need to do is create a variable: Integer currentyear = System.Today().year() ...
2
votes
1answer
41 views

Maximum number of records retrieved by one SOQL query in a lightning Apex backend controller

What is the maximum number of records retrieved by one SOQL query in a lightning Apex backend controller? According to this: Total number of records retrieved by SOQL queries | 50,000 But for me ...
2
votes
1answer
46 views

Too many SOQL queries - wanting to store in a map and check

I need to maintain a record for each month up to 10 years away, so 120 records ahead. This might be extended in the future! The code global with sharing class AccountingPeriodCreationService { ...