New answers tagged

2

You can just use a Map to do this, perhaps like this: Map<Id, ContentDocument[]> docsByAuthor = new Map<Id, ContentDocument[]>(); for(ContentDocument doc: [SELECT CreatedById FROM ContentDocument]) { ContentDocument[] docs = docsByAuthor.get(doc.CreatedById); if(docs == null) { docsByAuthor.put(doc.CreatedById, docs = new ContentDocument[...


0

You need to get the value from the aggregate result - you can only use a (list of) IDs/strings or SObjects when specifying a binding for the IN SOQL keyword. Since you haven't named (using aliases) the fields you return in the aggregate result you will need to do something like: Id theId = (Id) groupedResults[0].get('expr0'); to get the first field (the ...


0

Since it is a dateTime field, is it possible that you are dealing with records with the same date, but different times? If this is the case, the easiest solution would probably be to add a formula field on the obejct that would take the dateTime field and change it into a date, then order by that: DATEVALUE( SRA_Date_Time__c)


0

You can use aggregate MAX SOQL function. You can use below query to get maximum values per account: SELECT CustomAccount__r.Name AccountName, MAX(Account_Range__c) MaxRange FROM Custom_Month__c WHERE Account_Range__c != 0 AND CustomAccount__r.UpDate__c = TRUE AND Date__c >= LAST_MONTH GROUP BY CustomAccount__r.Name Note that you should either ...


0

SELECT CustomAccount__r.Name, CustomAccount__r.Country__c, Month__c, Account_Range__c FROM Custom_Month__c WHERE Account_Range__c != 0 AND CustomAccount__r.UpDate__c = TRUE AND Date__c >= LAST_MONTH ORDER BY Account_Range__c DESC, Account_Range__c DESC Use above query and the first record will the largest.


0

When calling an Apex server-side controller, you're required to enqueue an asynchronous action, with a callback to consume the result. In the code that you shared, theresult is not the result of the Apex call, but a reference to the action that your JavaScript controller may enqueue. From the documentation, here's a schematic and rather verbose example of ...


0

In general, the way you would do this is to add a subquery in your where clause. For example, if you are interested only in Accounts that have at least one contact you would write something like: [SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM Contact)] Unfortunately, you cannot use the OR operator in a sub select where statement, so ...


1

Take a look at this question from sfdcfox: The number of rows aggregated count against the 50,000 record limit. The "Rows" value you're seeing are the number of aggregate rows that were returned; this has a limit of 2,000 rows per query; if you exceed that, you'll get a different sort of error. Without knowing more, it's hard to tell what you'll need to do, ...


1

Answer 1: You can filter by FileType of SNOTE WHERE FileType != 'SNOTE' Answer 2: Use the AttachedConentDocuments related list on the object. Below is an example of how you might use this inside of a trigger: List<Opportunity> opportunities = [ SELECT Id, ( SELECT ContentDocumentId, LinkedEntityId FROM AttachedContentDocuments ...


0

You are not even calling your searchAccounts method, you should include a method invocation sentence within your test @isTest public class AccountSearchControllerTest5{ static testMethod void TestMethod1(){ Retail_Account__c rta1 = new Retail_Account__c(name = 'ABC',address__c = 'main st', city__c = 'Tampa', state__c ='FL', zip_code__c = '34609'...


2

Yes, after winter20 release we can query metadata decencies using tooling API. So while running this query, "Use Tooling API" checkbox must be checked in developer console. SELECT MetadataComponentName, MetadataComponentType FROM MetadataComponentDependency WHERE RefMetadataComponentType = 'ApexClass' AND MetadataComponentId = '00NXXXXXXXXXXXXXXX'


0

The schema you are dealing with is: Contact -> AccountContactRelation -< AccountId where AccountContactRelation has a field Role or Contact -> AccountContactRole -< Account where AccountContactRole has a field Roles (multi-picklist) Since you are trying to display a list of Contacts and their roles on a single line of VF , you are gong to ...


0

ContentDocumentLink is a junction object establishing a many-to-many relationship between ContentDocument (not ContentVersion) and arbitrary sObjects. The only approach you'd have to place linked sObject Ids on ContentVersion objects would be an Apex trigger. It is not possible to do this via a formula field. However, since the relationship is many-to-many, ...


2

This happens when you have additional spaces in between the words i.e. between Admin and Raymond. This space doesn't show up in the page layout nor in the developer console but when you edit that record it will display the additional spaces which prevents this records being caught in the LIKE query of the above mentioned SOQL. So taking your same example, ...


0

Your iteration of the counts was wrongly structured in the VF page. That said, it strikes me as far better to leverage presentation of the actual Lead__c instances, obtained in one query, like this: Controller: public without sharing class LeadAlertController { private static final Integer maxLeadsShown = 30; // Think about UX. Don't show too much data ...


0

I think you have an error in your SOQL. It should looks like the following in Apex: String str = '%admin, ray%' List<Cust_obj> accts = [ SELECT Id, Name FROM Cust_obj WHERE Name LIKE :str];


0

The only single query that will work is Select Id, (Select ... From OpportunityLineItems), (Select .... From Property__r) From Opportunity Where Id = :oppId This will return the Opportunity, the child OLI, and the child Properties. The Conga invoice template can thus show a header and two distinct tables of line items and properties.


1

for (SObject cont : conts) { System.debug('Cont is ' + ((Contact)cont).Name; } or for (Contact cont : (Contact[])conts) { System.debug('Cont is ' + cont.Name; } or for (SObject cont : conts) { System.debug('Cont is ' + cont.get('Name')); } You need to cast the SObject to a concrete object to resolve specific field names for the compiler (...


1

Yes you can. We are doing it right now and it works like a charm. If you do Database.insert, you can capture duplicate rule exceptions in your APEX code and do something when that happens. Moreover, if you use a custom object as a 'test object', you create the matching rule using this object against some other object (like account if you want to check for ...


2

First thing, I noticed you're using "lead__c" in your query? This should be a standard object so it should simply be "lead". Assuming your query works, your query is returning a list of Leads that actually contains the Id and RecordTypeId even though you didn't specify it. The VF page, when you simply reference the entire list, doesn't know how to display ...


3

Since StartDate__c is not unique, then you have one of two choices: Use a unique key (Id, or other field) Change your map to handle many records per one key Since you seemed to suggest that doing #1 led to CPU time limits, I'd suggest changing your map to hold a list of Gear or Tool objects. Example for tool below assuming that StartDate and your EndDate ...


0

Why use row numbers on _customobjectkey, when it already increments by one for each row? I’d suggest finding the min and max values for _customobjectkey and using that in your WHERE.


1

First, You need to split this into two seperate SQL Queries. Afterwords, you have multiple ways to split your data. Not knowing the attributes of your data extensions, this would be a generic solution to what you're trying to do : 1st Query : (Let's say this goes into a Data Extension named [Target_DE_1] for the 0.9M records) Select Top 45 Percent A, B, ...


0

You cannot do this in a single query because IN with a subselect only references the ID field of the subselection; you can't reference other ID fields in the object. This means you have to collect all the content document IDs into a set by looping through a ContentDocumentLink query first, then you do another query on ContentVersion using the ID set. Set&...


3

I was just about to post an answer, but Adrian Larson kind of mentioned it a bit in his answer. Custom Metadata are a subset of Custom Objects, so they will be accessed through there. However, going through the global describe will just give you the SObjectType, not all the audit information you're looking for. I would take the SObjectTypes that you get ...


3

If you want to get all of your custom metadata types, you can loop through the global describe and inspect the API Names to see if they end in the metadata suffix. List<String> metadataTypes = new List<String>(); for (String sObjectType : Schema.getGlobalDescribe().keySet()) if (sObjectType.endsWith('__mdt') metadataTypes.add(...


0

Sarvesh and Zach are good anwsers, you can also achieve the same result with the next query. SELECT Id, Name FROM Campaign WHERE Status != 'draft' AND Status != 'cancel'


0

Andy, You should be able to query the UserLicense object via Apex. Try the following in Execute Anonymous to see the current values: for(UserLicense ul : [SELECT Name,TotalLicenses,UsedLicenses FROM UserLicense WHERE TotalLicenses > 0]){ system.debug(ul.Name + ' - '+String.valueOf(ul.UsedLicenses)+' of '+String.valueOf(ul.TotalLicenses)+' used.'); } ...


2

Query editor does not support bind variables, thus OwnerID in :taskUsers would make it invalid. Fix would be use individual owner SELECT Count(Id), ownerId from Task where createdDate = Today and Type != 'Other Task' and OwnerID in ('00558000000EVMh' ,'00588000000EVMh') group by OwnerID Order By Count(Id) Asc


2

CreatedBy.Name gives the Name of the User CreatedById is for the Id of the user. Your query becomes select Title, CreatedBy.Name FROM Dashboard


1

You need to query the field from the ApexClass object first, as seen here https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_apexclass.htm Also If there is not a cached version of SymbolTable, it will be compiled in the background and the query might take longer than expected. The SymbolTable returned from ...


5

SOQL in Apex does not, by default, honor profile permissions. To do so, add WITH SECURITY_ENFORCED. As the documentation says: Apex generally runs in system context; that is, the current user's permissions, field-level security, and sharing rules aren’t taken into account during code execution. Although performing field- and object-level security checks ...


0

Are there any workflows, process builders, or triggers on the update of Deal__c records? You mentioned there's 10,000 records pulled in that query. You could look at having your scheduled class call a batchable apex class and control the batches to process a smaller amount of records at a time. https://developer.salesforce.com/docs/atlas.en-us.apexcode....


1

The important part of that error message is this: System.QueryException: List has no rows for assignment to SObject Class.OpportunityTriggerHandler.afterUpdate: line 126, column 1 Which would seem to refer to this line in your trigger handler: SS_Integration_Setting__mdt tokenSetting = [SELECT Token__c FROM SS_Integration_Setting__mdt WHERE MasterLabel =...


3

Use Quoted String Escape Sequences character Database.query('SELECT ID,Name FROM Campaign where status NOT IN (\'draft\',\'cancel\')')


4

You should make a Set<String> and add the status to it. Like this Set<String> stringSet = new Set<String>{'draft','cancel'}; Then you can update the query to: String campQuery = 'SELECT ID,Name FROM Campaign where status NOT IN: stringSet';


3

Salesforce, for one reason or another, doesn't allow us to make relationship fields that target OLI (OpportunityLineItem). We can hold an OLI Id in a text field, but that won't allow you to traverse the relationship in SOQL. Your options here are to break this into two queries (one to pull your Custom_Object__c records based on the Ids of the OLIs you are ...


1

Perhaps something like this would work: SELECT Id, OpportunityId, <Other fields> FROM OpportunityLineItem WHERE OpportunityId IN: (SELECT <Opportunity Id Lookup Field> FROM myobject__c)


1

Use Map<String, Object> getPopulatedFieldsAsMap() method on the sobject. It gives you a map of fields and values that got queried. Please refer to this release notes for more information: (http://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_apex_sobject_getmap.htm)


1

You have a capitalization error: @{refContactData.records[0].id} In the response body to a Query REST call, each record contains a field called Id, not id: "records" : [ { "attributes" : { "type" : "Contact", "url" : "/services/data/v46.0/sobjects/Contact/0031R000025XXXXQAA" }, "Id" : "0031R000025XXXXQAA" }, I was able to ...


0

You can use DAY_IN_MONTH month function to retrieve day in the month of a date field. Query will be like as SELECT DAY_IN_MONTH(CreatedDate), Account.Type, Owner.Division, CALENDAR_YEAR (CreatedDate) year, CALENDAR_MONTH(CreatedDate) month, COUNT (Id) Contacts FROM Contact where CALENDAR_YEAR (CreatedDate) > 2017 GROUP BY Account.Type, Owner.Division, ...


9

You're pretty close to a solution with your parent-child subquery. The big thing to realize is that, similar to how adding parent__r.someField__c gives you a real SObject instance nested in your query results, a parent-child subquery gives you a List<SObject> nested in your query results. About the only thing I'd add is to limit the subquery rows to ...


13

You can use a HAVING clause: AggregateResult[] results = [SELECT COUNT(Id) sum, Tool__c Id FROM Gear__c WHERE Tool__c = :tools GROUP BY Tool__c HAVING COUNT(Id) > 1]; This will give you a list of AggregateResult objects where the sum and Tool__c Id are given. You can even use the Map trick to get the count per record easily: Map<Id, AggregateResult&...


Top 50 recent answers are included