New answers tagged

0

How about just leaving the ids as strings? Something like: public static List <sObject> fetchLookUpValues(String searchKeyWord, String objectName, String closedCleanupId) { String searchKey = searchKeyWord + '%'; Set<String> closedStages = new set<String> {'Closed - Clean Up','Closed - Lost'}; String sQuery = 'SELECT Id, Name,...


7

In Dynamic SOQL, you need to pay attention to spaces. There should be no space between : and what follows. Bad id NOT IN : setclosedId Good id NOT IN :setclosedId Spacing is important when building dynamic query strings, as the system is far less lenient in that case.


0

Generally, when you want to update another object in trigger, you would do it in After event trigger. trigger UpdateLocation on Contact (after update) { if (trigger.isAfter && Trigger.isUpdate) { List<Boat__c> boats = new List<Boat__c>(); for (Contact c : [ SELECT location_boat__c, (SELECT Id FROM ...


0

Yes your code doesn't make sense at all. There is data type mismatch (you can't assign Opportunity list to Contact list, is that a typo?). And you are not doing anything other than just quering contact records. Try this (handle bulk updates too and each line is easy to understand, you can seach the few keywords which is used below to understand in detail) ...


0

003 is the key prefix for a Contact Id, not an Account Id. This indicates that the issue lies, as you mentioned in comments, that the problem lies in Lightning component code or markup, rather than in the SOQL/Apex layer.


2

I would recommend you to use Batch but without querying sub-records, this could lead to unpredictable errors, especially if you have 200+ of them. Try to rewrite your query in the next way: public Database.QueryLocator start(Database.BatchableContext context) { return Database.getQueryLocator([ SELECT Id FROM Child__c WHERE Parent__c IN :(SELECT Id ...


3

Lucky for you, Salesforce changed the way query aggregation counts against your limits recently, so you can drop the child query altogether. Just use aggregate queries instead. Before, every record which went into the aggregation counted against you, but now only every aggregation counts. public with sharing class MyRollupBatch implements Database.Batchable&...


3

It's a Date Literal. You need to merge it in as such. Rather than using a bind variable, you need to actually include the string so it results in your dynamic SOQL containing a Date Literal. String soql = '... WHERE CreatedDate = LAST_N_MONTS:' + x; Effectively, what you had would output: SELECT ... FROM ... WHERE CreatedDate = 'LAST_N_MONTHS:42' But ...


0

You need to bulkify your code, try not to put logic in the trigger, move the logic to a handler/helper. Also avoid doing DML operations inside a loop, you're going to hit another limit soon. // ProgTrigger ProgTriggerHandler.handleEnrollmentDeletion(Trigger.NEW); // ProgTriggerHandler#handleEnrollmentDeletion Map<Id, hed__Program_Enrollment__c > ...


4

I assume, delete dml invokes some trigger in managed package, which throws an SOQL limit exception. Overall, it is possible to use dml not for the single record, but for the collections of the records. Move delete prog; outside of the loop trigger ProgTrigger on hed__Program_Enrollment__c (before insert) { list<hed__Program_Enrollment__c> ...


1

Unfortunately, I think SOQL is no help here as Tabs and TabSets are not available for queries. This URI: https://ap2.salesforce.com/services/data/v29.0/appMenu/AppSwitcher Can you get a list of TabSets including the 'Sales' one but apart from navigating to the tab sets record page using its ID, there again isn't much you can do with this. The Apex Schema ...


-1

The best thing would be to have a selector layer that you call from wherever you need it and gives you exactly what you need. In this case one record. Example: public with sharing class AccountSelector { public static Account ById (List<String> queryFields, String accountId) { List<Account> result = Database.query('...


2

this concept is called SOQL For Loops. The main idea here is using queryMore() by saving queryLocator to retrieve another chunk of records and not to store them in a heap. Pay attention, that you can use soql for loop only for objects, that supports queryMore call. You have to use soql for loop in cases when you don't need to store selected records in ...


0

Whilst this is probably possible in whatever version of SQL you're familiar with, it's not in SOQL. Once you've retrieved the list, you need to do the concatenation yourself. I'd recommend using the String.join method for this.


0

You will not be able to GROUP BY formula fields and child relationship expressions (__r) You can actually use getDescribe() method to see which fields are groupable (isGroupable()). I think the workaround is to create text fields to copy the required values (month converted to month name/ Adjusted Production Name) using PB/WF and use them in your SOQL.


0

Below Code Block will help you out String emailStr = ''; List <contact> conLst = new List<contact>([SELECT Id, Email, AccountId FROM Contact where AccountId = '001****']); for(contact conObj : conLst){ emailStr = emailStr + ';' + conObj.email; } System.debug('emailStr -> '+emailStr);


4

Seems quite likely related to VerificationHistory. I would guess the "fields" just indicate whether or not a record exists with the given Activity specified. Notice the values for that picklist: The action the user attempted that requires identity verification. The label is User Activity. Available values are: AccessReports—The user attempted to ...


3

You can execute the query written on the Apex class by following the below step: https://trailhead.salesforce.com/en/content/learn/projects/quickstart-vscode-salesforce/use-vscode-for-salesforce


2

You can't write a SOQL query that returns results for any arbitrary report. Each report is different and would reduce to a different SOQL query. You can use the Reports and Dashboards API to programmatically execute report runs and extract the resulting data. This API is accessible in Apex or via the REST API. Alternately, you can analyze each report ...


0

EDIT You should be able to modify your query as follows: SELECT Id, FirstName, LastName, PersonEmail FROM Account WHERE IsPersonAccount = true Order BY Id, LastName, FirstName, PersonEmail This should give you the results you're looking for. BTW, any query will return the Record Id by default. You shouldn't have accounts with the same AccountId in your ...


2

Check the FLS for that field. Setup --> Object Manager --> transition__c --> response__c --> Set Field-Level Security Make sure that field is Visible to your profile


1

If you want to use APIs (to keep this very simple) you can: Create a folder using ContentFolder You can then create a Document and give it the Folder ID However if you are trying to do this programmatically - I assume you mean via Apex? In which case you can create these via Apex (there are a couple of ways to do this, here is an example of using Connect ...


4

Sure, but let's get the trigger bulkified first. I'd strongly recommend completing Bulk Apex Triggers on Trailhead. The quick summary is that here we need those SOQL queries out of the loop, and you can combine them into a single parent-child SOQL query at the top. You don't need to query the records in Trigger.new at all (you get their data for free), but ...


0

The trigger needs to collect the details differently. Try: trigger OrderActive on Order (after insert, after update) { List<Id> activatedOrderIds = new List<Id>(); List<String> accountNames = new List<String>(); // Get all the inserted/updated activated order's IDs for (Order order : Trigger.new) { if (order....


0

If you serialize the information, it will be there in the output string. Note that the information is stored on the Order variable in memory, but when you just debug your Map<String, Order>, it uses implicit type coercion to String and what you see is not necessarily what you get. system.debug(JSON.serialize(m)); // {..., "Account": {..., "Name": "...


0

Since it's possible for a delivery failure, it would be a better idea to allow the client to specify the last known timestamp so it can resume from there: @HttpGet global static Account[] getRecords(DateTime lastKnownTime) { return [SELECT ... FROM Account WHERE LastModifiedDate >= :lastKnownTime AND ...]; } The client should send the parameter to ...


1

SOQL does not allow such query, so you need to separate it into 2. 1) Gather leads and store their first names into Set. List<Lead> leads = [SELECT FirstName FROM Lead WHERE IsConverted = false]; Set<String> leadsNames = new Set<String>(); for (Lead lead_i : leads) { leadsNames.add(lead_i.FirstName); } 2) Now you can query: SELECT ...


1

You should encode your query, so it will look somehow like: SELECT+Id+FROM+PRODUCT2+WHERE+ProductCode+=+%27M5Z55UP%23ABC%27 The spaces can be parsed both with + and %20 encodings.


3

Some background When working with data that's related to an object, there's two ways it can be related: Child-to-Parent (e.g. Opportunity.Amount in a query on OpportunityLineItem) Parent-to-Child (e.g. (SELECT Id FROM Opportunities) in the SELECT clause in a query on Account) An important concept to keep in mind here is that all relationship fields in ...


3

You have to loop through your subquery list of records. Here is how you would access these fields and records: for(Account a : accList) { for(Project__c p : a.Projects__r) { System.debug(p.Client_Advisor_Email__c); } }


1

Actually, you can get parentId of the Folder just like this: SELECT ParentId FROM Folder Here is the code you need to execute to retrieve all folders where email templates are stored: List<EmailTemplate> templates = [SELECT Id, Name, FolderId FROM EmailTemplate]; Set<Id> foldersIdsToCheck = new Set<Id>(); for (EmailTemplate template_i : ...


0

ContentDocumentLink does not have a field Title. You'd need to query through the relationship to ContentDocument: SELECT ContentDocument.Id FROM ContentDocumentLink WHERE LinkedEntityId = '0WO6F000001UbmC' AND ContentDocument.Title LIKE '%SPE%' Your query should fail to execute as written.


0

ContentDocumentLink object doesn't have title field. But I get what you are trying to do: try this, works for me select id,contentDocumentId,contentDocument.title from contentdocumentlink where LinkedEntityId = 'Your own record id ' and contentDocument.title like '%SPE%'


2

the expression 'comp%' will bring everything that starts with 'comp' and ends with anything if you want to always guarantee 4 letters after 'comp' you can use it as follows LIKE 'comp____' use 4 underscore to ensure 4 characters after 'comp'


0

A possible workaround could be to create custom fields and automatically fill them in with the same text, but without accents. And then standartize the input and use SOQL query filtered on that custom field.


2

You can run a query similar to this: Select {whatever fields you need} From Note WHERE Parent.Type = 'Account' This will retrieve all Notes where the ParentId is of type Account


1

Unlike SOSL, SOQL doesn't support accented character mapping, whilst SOSL cannot perform search term matching within words (only at the start). The work falls to you, as the developer, to bridge the gaps. An option you could use is to analyse the string (iterate the entered value) to find all characters outside the ASCII character ranges and replace them in ...


3

If you're using the standard record Id API, it should be recordId, not RecordId (case-sensitive), and you should be using a reactive parameter: @api recordId; @wire(getOpportunityLineItems, {oppId: '$recordId'})


0

Ultimately, I learned that nested queries such as the one above are easily manipulated within Apex. The child-relationship's API name can be looped on as easily as one would loop through a list of lists. I hadn't realized this was possible in Apex so this issue was more caused by a lack of knowledge than by the necessity of a complex solution. :)


0

After reading your question a couple times I think I've spotted what you're running into but feel free to comment if I've interpreted your question incorrectly. The immediate problem is this query which doesn't include the email fields you're trying to use later in the for loop. List <Case> caseList = [SELECT Id, AccountId, Account.Name, Account....


0

It seems as though encryptionScheme only comes through the CustomField metadata, which means you would have to look at each field one at a time via the Tooling API query. If you did a metadata retrieve() (i.e. Package.xml), you would get the answer to both


1

As the Owner field can be a polymorphic field, you can only access those fields which are common across both objects. In such cases, you can use TYPEOF in your SOQL query and select the fields based on the Owner type. SELECT [fieldList,] [TYPEOF typeOfField {WHEN whenObjectType THEN whenFieldList}[...] [ELSE elseFieldList] ...


2

I don't have a why for you, but if you have a scenario where LIKE needs to match the API name, you could create a formula field targeting the same picklist. FFs always return API name not label.


4

This is what I think is the reason for the LIKE operator to automatically translate picklist values: The LIKE operator is used to match strings. The picklist value is translated, probably because of situations when the end-user searches for text in his own language. Consider the following situation: a custom search component for a multinational company that ...


4

With AggregateResult, you need to use the .get(String) method to access things. e.g. AggregateResultList[0].get('name'); The return value of the sobject's .get() method is an Object, which means you'll need to do a typecast to make the result usable. Something like String name = (String)AggregateResultList[0].get('name');


1

I think the problem here is that User.Owner is a polymorphic field. That is it can reference either a User object or a Group object. Personally, I just do another query on User via the OwnerId field once I've checked that this Id a User object not a group. I'm interested in finding out if there's a better way of handling this. Why does Owner.Phone work ...


0

I don't think you need to execute three queries here. You should be able to get away with only executing one. List<Project2__c> projectsWithOrgs = new List<Project2__c>(); projectsWithOrWithoutOrgs = [SELECT Name, Project_Title__c, ...


0

Try this. This query should work uniqueProjects = [SELECT Name, Project_Title__c, Category_text__c, Project_URL__c, Lead_Org_Display_on_Website__c, Project_Organizations_RT__c, Logo_URL__c FROM Project2__c WHERE ID in (SELECT Project2Id FROM Project_Organization_c WHERE Category_text__c='Awarded' OR ...


0

You can use a relationship query: [SELECT Id, (SELECT Id, Relation.Name FROM EventRelations) FROM Event] This will return Events and their Relations, if they have any. Edit: Updated to add example with relation information.


2

IsClosed is not true until the record is loaded from the database and the Status is a Closed value. This typically means that you need to use after triggers in order to reliably detect when a task has closed. I verified this behavior with the following code: trigger taskTriggerX on Task (before insert, after insert) { for(Task record: Trigger.new) { ...


Top 50 recent answers are included