New answers tagged

0 votes

SOQL: Count number of child records

SELECT AccountId,Account.Name, COUNT(Id) ContactCount FROM Contact GROUP BY AccountId,Account.Name HAVING COUNT(Id) > 10
0 votes

How to Query Child records of the lookup record in a single query

The question is confusing, because you state that Organization__c is a child of School__c, but still want to "start" your logic from the organization. Since you're saying that both ...
  • 1,350
1 vote

Problem with SOQL multilevel relationship query returning one column for two fields

This is both the result of design desicions made by Salesforce, and an artifact of whatever approach you're using to turn the data into a string. Some background If you have experience with other ...
  • 50.6k
1 vote

query only recalled record for approval process

For the records that are recalled you will have status as "Removed" you can use the below SOQL to get the records that are recalled. SELECT Id, Status, TargetObject.type, CompletedDate FROM ...
2 votes

How to get count of opportunities related with an account in SOQL query?

You can only use aggregate expressions in root Queries. for getting the count if opportunities on each account you have to use the below SOQL query. SELECT count(id), AccountId FROM Opportunity GROUP ...
0 votes

SOQL Query to find out users assigned custom Apps salesforce

The code in the other answer only shows apps for the current User. If you want to check which Users have Access to which Apps, just make a small test class and run this code @isTest public static void ...
2 votes
Accepted

SOQL aggregate query issue with number fields

Certain fields are not groupable. For number fields, they are groupable if they are standard and are integer deep at the API level. For all other numbers they are decimals and are not groupable. Can ...
0 votes

I want to add no of count of task on lead

To get the exact count you can try writing a trigger for all the three cases. After insert, after update and after delete. So that if a task is created under a lead or updated/deleted under lead it ...
0 votes

Aggregate soql query to retrieve all accounts with at least one opportunity and contact

SELECT Id, Name FROM Account WHERE Id IN (Select AccountId from Contact) AND Id IN (Select AccountId from Opportunity)
2 votes

Why does SF retrieves an extra Id column when querying on standard objects?

You might have printed in System.debug and you may be able to see this value. But it is not available for use. If you try to use this in Apex code. You will receive an error Error on line 3, column 1: ...
0 votes

Comparing trigger.newmap.keyset() vs trigger.new in SOQL query

Yes, you can always use a List<sObject> as a filter assuming that the type of the sObject matches the lookup field's sObject type, and assuming that you want to use the Id field.
  • 445k
0 votes

SQUERY SALESFORCE

Please try to correct the where clause: String sQuery = 'Select id,Investment_Capability_Reference__c,Investment_Strategy__c,Source__c,Rating__c,Asset_Class__c,Global_Fund_Code__c,Fund_Name__c, ...
1 vote

SQUERY SALESFORCE

It's tough to know what you're trying to achieve. Based on what you posted, I assume the criteria you're trying to get is: WHERE Account_Fund_Ratings__c != NULL AND Source__c = 'On Panel' AND ...
1 vote

SQUERY SALESFORCE

Setting aside whether this should be a dynamic SOQL query at all (it doesn't look like it should be), your filters (the WHERE clause) are incorrectly trying to concatenate string literals. That is, ...
  • 50.6k
7 votes
Accepted

Any Reason NOT to Use FOR UPDATE?

General If you have FOR UPDATE on your query, you cause the record(s) (and potentially related records too) to be locked at the time of the query execution in the transaction against the Salesforce ...
  • 28.7k
4 votes
Accepted

How to resolve SOQL SOSL Injection security error

You have two options: Use a merge variable. Simple, compact, easy to read. String query = QUERY_PART1 + ' where Id = :avlId and Event_Status__c!=NULL '; Escape the input. String query = QUERY_PART1 +...
  • 144k
0 votes
Accepted

Is there a Public Link Sharing list?

I had this same question and just found the answer. This blog post by forcepanda really helped - https://forcepanda.wordpress.com/2021/05/04/generating-public-url-for-salesforce-files/ You need to ...
  • 16
7 votes

Any Reason NOT to Use FOR UPDATE?

A lock is always necessary to update a record, but a transaction might already have a lock on the record you want to update, so you don't necessarily need FOR UPDATE in every query. Performing a DML ...
  • 445k
0 votes

No such column 'IqScore' on entity 'Opportunity'

In my case it seems to be a difference between a production org and a (developer) sandbox org. In my sandbox org, the Opportunity object has the IqScore field (visible to all profiles), but in Setup '...
0 votes

How to retrieve all this year reports metadata using workbench?

You can write an SOQL to get all the reports which were created this year by using the below. SELECT Id, Name, DeveloperName, FolderName.DeveloperName,CreatedDate FROM Report WHERE CreatedDate = ...
0 votes

How to retrieve all this year reports metadata using workbench?

Using the above query from SaliPraveen you can retrieve the report folder name and developer name. From here you have two options. retrieve all the report metadata and than extract the reports based ...
0 votes

insert & Database.insertImmediate not immediate?

Guest user can't own a record, so a guest user sharing rule would need to be configured to provide read access to the record
  • 151
0 votes
Accepted

SOQL WHERE + Integer on Auto Number

Auto-number fields are strings, as they can contain letters, too. To make things easier, consider changing the "Display" to something like 0000000000, which will generate numbers like ...
  • 445k
2 votes

How to check in Apex if a user has sharings to a given record?

You should use the UserRecordAccess object. SELECT RecordId, MaxAccessLevel FROM UserRecordAccess WHERE UserId = 'id_1111111111' AND RecordId = 'id_2222222222' Valid values are: None Read Edit ...
  • 4,819
2 votes

Can you use a boolean in ORDER BY to sort all Objects that have this field true to the top of the query result?

This is one of those things that would generally be faster to test for yourself, assuming you have access to an org. Anyway, the answer is that we are able to include Checkbox (i.e. Boolean) type ...
  • 50.6k
2 votes

Why is an API User with R/W access to a lookup field, getting an INVALID_FIELD error?

I believe it is a key: They do not have access to the Contact object The user will require at least 'Read' access to the object in which the lookup field is referencing to see the lookup field. ...
  • 1,322
3 votes

Whenever I write SOQL code it is giving me yellow highlighted line error

It is just an Apex PMD extension. Yellow is not an error, it's a warning. When you hover over it you will see more details (screenshot below). Apex always works in System Mode. It means that all SOQL ...
  • 1,322
1 vote
Accepted

Querying parent's related list from the child object

Two queries would be needed to achieve this One to get the parent details from Child1__c and the other to get Child2__c record with the same parent record To get records from more than one unrelated ...
  • 90
1 vote
Accepted

Group by 30min interval SOQL

Use a Text formula field on the object that calculates the half hour bucket for a given record's CreatedDate. Formula values would be 0000-0029,0030-0059, ... IF (HOUR(CreatedDate) = 0 && ...
  • 63.8k
0 votes

How to replicate the functionality of delivered "File Engagement" lwc card?

Try this solution: Component: <aura:component description="test" implements="flexipage:availableForAllPageTypes" access="global"> <aura:handler name=&...
2 votes

How can I select two rows with the same account?

Try something like 1 or 2: 1. SELECT AccountId FROM Asset WHERE Status = 'X' GROUP BY AccountId SELECT Id, (SELECT Id FROM Assets WHERE Status = 'X') FROM Account
  • 1,322
5 votes
Accepted

How can I select two rows with the same account?

You can use an aggregate SOQL query for this, and then only return accounts that have more than 1 asset with that status: SELECT AccountId , count(Id) FROM Asset WHERE Status = 'X' GROUP BY AccountId ...
2 votes
Accepted

Remove duplicate values in a list

The code you have right now should work ...assuming that Sold_to_Broker_1_Desc__c only contains a single value. Adjusting your code so that anyone can run it via anonymous apex Map<String, Account&...
  • 50.6k
0 votes
Accepted

Default value for new lookup fields

Ran the query I the developer Console instead of in my IDE. It works now, the query have not been changed. I have no explanation.
-1 votes

Remove duplicate values in a list

You can try something like this to remove duplicates Set<SoldToBrokers__c> setBr = new Set<SoldToBrokers__c>([SELECT Sold_to_Broker_1_Desc__c, Sold_to_Broker_1_Commission_Rate__c, ...
  • 1
1 vote
Accepted

Update an object that is indirectly related to another object in a list

DML operations will not update Child records in the records whihc you pass to it, So you need to create another list for Net_Prospect_Score__c object and update this list. Also you need to add another ...
2 votes
Accepted

What I'm I doing wrong in Dynamic Query

The issue here is that you don't have recordId declared in the scope where you're actually executing this query. Your query filter is literally ' where id =:recordId' when your query string is ...
  • 50.6k
1 vote
Accepted

System.EmailException: SendEmail failed. First exception on row 0; first error: LIMIT_EXCEEDED, System.LimitException: Too many future calls: 1: []

I guess: Production has a trigger on EmailMessage, which does not exist in your dev environment. EmailMessageTrigger fires @future method. As you can see in the image below, @future cannot be executed ...
  • 1,322
1 vote

Joining Contacts Table with Account

A core misconception you may have is that your field path in any given field expression can originate from any joined table. Not so in SOQL. Each field expression must reference a field path ...
  • 144k

Top 50 recent answers are included