New answers tagged

2

When you need to traverse through a reference field, you can use a dot operator to get the related object's fields. In this case this would be Owner.CompanyName because this is a standard reference field. Similarly lets say if this would have been a custom reference field called Owner__c on Lead; with the relationship name as Owner__r, syntax to get the ...


2

It does escape the backslash before single quote. You should check documentation of escapeSingleQuotes(stringToEscape) Below is how apex modifies the string - run it in anonymous apex and play-around String s1 = 'a\'d'; System.debug(s1); System.debug(String.escapeSingleQuotes(s1)); System.assertEquals('a\\\'d', String.escapeSingleQuotes(s1)); System.debug('a\...


3

System.debug doesn't show parent or child relationships. Use JSON.serialize, for example, to see the values, or you can collect them manually: Set<String> uniqueValues = new Set<String>(); for(Transaction_Property__c property: loans) { for(Transaction_Property__History history: property.histories) { uniqueValues.add((String)history.newValue)...


0

You can't currently get these details via SOQL. Instead, as sfdcfox answered, you can use the checkDeployStatus Metadata API to get this data. Examples of calling this from Apex: public void checkDeployStatus(Id deployRequestId) { HttpRequest req = new HttpRequest(); req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); req....


0

Date values are always interpreted as if they were from midnight in GMT or local time zone (depending on the method you use). Use a DateTime variable instead. DateTime dateUntil = DateTime.parse('7/30/2020, 12:59 PM'); The exact format will depend on your locale; check the documentation for more information. Or, you can use the newInstance method: DateTime ...


2

Your query is generally correct. Contacts will be between 3 years and 3 years and 364 (or 365 on leap years) days old assuming you run this query annually. If you want to be more precise, consider LAST_N_DAYS instead: LastModifiedDate < LAST_N_DAYS:1095 This will generally find contacts that haven't been modified in the more usual sence of "last ...


2

The relationship name is FEEDS so the following query should work. SELECT Id, CaseNumber, CreatedDate,(SELECT Id,ParentId FROM Feeds) FROM Case If you want to view the relationships, you can use this code. List<Schema.ChildRelationship> relations = Schema.getGlobalDescribe().get('Case').getDescribe().getChildRelationships(); System.debug(JSON....


0

The VF controller needs to implement the queryMore feature for (MyObject__c obj: [SELECT ... FROM MyObject__c]) { // do something like collect into a list } SOQL for loops differ from standard SOQL statements because of the method they use to retrieve sObjects. While the standard queries discussed in SOQL and SOSL Queries can retrieve either the count of ...


0

Yes, you are right that using the Opportunities relationship on Contact you will only get the opportunity which has this contact as primary contact. This is enabled via ContactId field on the opportunity. You will need to query on OpportunityContactRole using to get all opportunities. Select OpportunityId, Opportunity.Name, ContactId from ...


0

If you use Salesforce Inspector (Chrome Extension) https://chrome.google.com/webstore/detail/salesforce-inspector/aodjmnfhjibkcdimpodiifdjnnncaafh?hl=en or other tool that allows you to query using the Tooling API, you can just query: select id, SiteName, EndpointUrl from RemoteProxy If using Salesforce inspector, make sure "Use Tooling API?" ...


0

You are using a bind variable so the line String accIdStr = '\'' + accId + '\''; is not required. This is used in dynamic query using Database.query(). Make sure that you are getting a correct 18 or 15 digit Id like 001XXXXXXXXXXXX and change your query to use accId List<Application__c> appList = [ SELECT Name__c, Industry__c, Phone__c FROM ...


1

Ok i got the answer, and it's a stupid one... It appears that as I query a list, if I debug it I don't have the debug information of the parent. I have to debug element by element to see the parent relationship. list<FLU_PaymentDeadline__c> pdl = [Select FLU_Contract__r.Name, FLU_Contract__r.FLU_ReviewAutoPay__c, SystemModstamp, FLU_PaymentMeans__c ...


0

If Profile level FLS and CRUD accesses are given, you should check the sharing settings of the contract object.


0

If you require production objects in Excel, but have no time for a deployment: Tag values as html table >> send yourself an email >> copy & paste in textfile >> save as .html >> open with browser >> copy & paste into Excel. Thanks Peter for the great example! String objectNamesAndLabels = '<table style="width:100%...


2

You can get a specific record with LIMIT X OFFSET Y. To get the second-highest Salary, for example: select salary__c from Staff_Details__c order by salary__c desc nulls last limit 1 offset 1 Note that offset is 0-based, so the second-highest is 1, while fourth-highest would be 3. There's also a limit of OFFSET 2000, so you'll need to come up with ...


0

Your question overall needs refinement. You will first of all need to define how to identify the winner account in case there are accounts with duplicate names. You can collect the Accounts in a Map possibly Map<Id,Account> mapAccounts = new Map<Id,Account>(); for(Account a:searchList) // winning account logic here mapAccounts.put(a.name,...


3

As per the documentation: Bind expressions can't be used with other clauses, such as INCLUDES. You will have to use dynamic SOQL and generate the required SOQL syntax, something like: List<String> roles = new List<String> { 'finance', 'marketing' }; String rolesAsString = '(\'' + String.join(roles, '\', \'') + '\')'; List&...


1

As you can see from Workbench, there are no relationshipNames for Product2 to OrderItem and Product2 to QuoteLineItem. Yet you can query from Product2 to PricebookEntry However, you can query from PricebookEntry to both OrderItem and QuoteLineItem so you could do: SELECT id, Product2.Name, (select Id from OrderItems), (select Id from QuoteLineItems) FROM ...


2

CombinedAttachments (note the plural) is the name of a relationship. CombinedAttachment is the name of the sObject. You'd use the relationship name when performing a subquery. When you perform a semi-join in your WHERE clause, as in your bolded text here, you must use the actual sObject API name. You've also got IN NOT instead of NOT IN, as was pointed out ...


1

If you're looking for the next open activity, your query should be: SELECT (SELECT ActivityDate FROM OpenActivities ORDER BY ActivityDate ASC NULLS LAST LIMIT 1) FROM Opportunity However, to avoid the "slow queue" for batch processing, the query should be performed in the execute method: public void execute(Database.BatchableContext BC, List<...


1

You only add __r when it's a custom relationship. Since the relationship between Task and Opportunity is a standard one, you don't add __r. The child relationship name you're looking for here is Tasks, Events, or ActivityHistories SELECT Id, (SELECT Id, Subject FROM Tasks) FROM Opportunity


1

As per the documentation, FOR UPDATE locks specific records, not the entire table (though there can be additional locks once DML is applied). I am therefore unclear why you say "other apex threads will wait ... even though the previous thread ... does not return any records" since this doesn't align with expected behaviour. If you have multiple FOR ...


2

It's a weird behavior with the compiler. Change it to Database.Batchable<sObject> instead. Notes: You don't need to copy the list before deleting it. Use an inline query. Don't query fields you don't need. global Class Batchsample implements Database.Batchable<sObject>{ global Database.QueryLocator start(Database.BatchableContext BC){ ...


1

For this type of question, a pretty simple "can I do X?", the fastest way to get an answer is usually to just go and try to do it yourself through anonymous apex. The short answer here is yes, you can do this, and in exactly the way that you laid out in your example. The longer answer is yes, and you need to keep in mind that you're going to get ...


2

Order by goes after with security_enforced. P.S. You don't need to initialize a variable twice. You can drop the new List<CAF__c>: List<CAF__c> CF = [ SELECT TYP_R__c FROM CAF__c WHERE cust__c = :AccrecId AND TYP_R__c IN ('C-D-F','C-D-D') WITH SECURITY_ENFORCED ORDER BY CreatedDate ASC NULLS LAST LIMIT 250]; ...


0

Agreed with David, the Code Builder and its features are not yet generally available. But then if you want to use SOQL Query Editor from VS Code there is an existing extension which you might want to take a look on. Extension Name :SOQL Editor


3

Like much of the functionality introduced at TrailheaDX '20, including Code Builder itself, SOQL Query Builder extension is not yet Generally Available. As far as I am aware, no GA release date for the SOQL Query Builder extension has yet been formally announced. If you're interested in joining pilots of new functionality like Code Builder, contact your AE.


2

We cannot have an SObject field on the right-hand side of an expression in SOQL, data binding nonwithstanding. The point is that things like WHERE Field1 <some comparison operator> Field2 are not syntactically valid. You'll either need to do that comparison in Apex (with the results of the query), or add a formula field in your object to do the ...


0

The issue had arisen because the ProspectId__c field was not indexed, So, If we run into a "Non-selective query against large object type" error when performing a SOQL query or it takes a long time to run, we may need to make it selective and if it filters by a Text field We need to make it as External ID. Or we can get the Salesforce support to ...


2

SOQL is not the same as SQL, so I'm afraid that what you're trying to do is impossible (with SOQL alone, at least). SOQL can't perform math operations like division (only what we're given through the aggregate functions, i.e. SUM(), MAX(), AVG(), COUNT(), etc...), doesn't have a percentile_disc() function nor a way to define/use our own functions, and doesn'...


3

I would really advise you not to do this. Apex in its current form is really not suited for parsing and - more importantly - user-generated SOQL strings is a big security red flag. I know it's probably not the answer you wanted, but my advice would be to have a user-generated object-representation of the query (for example, an object representation of the ...


1

The WITH DATA CATEGORY clause should solve your need. You just need to specify the top level data category and then the specific one you're interested in. The example from the docs is below Assuming you have a Data Category setup like below Geography__c usa__c canada__c You could find all the articles with USA as a data category like so SELECT Count(...


0

A bit late to the party, but I found another way of causing this to occur. If you have an interface with methods returning Decimal, but the implementations return Double, then instead of catching this at compile time, it can cause System.UnexpectedException: Illegal arguments at runtime. Here's a simple test which exposes the problem: @IsTest static void ...


0

The date literals can be used with > and < operators to include times outside that range. Use < for dates older than the specified range, and > for dates after the range. SELECT Id, EndDate FROM Contract WHERE EndDate >= LAST_N_DAYS:730 ORDER BY EndDate


0

Without the right code, Salesforce user can share Notes and Attachment with community user below links just follow the below setting. https://help.salesforce.com/articleView?id=networks_files_on_records_visible_to_customers.htm&type=5


0

Try this query: SELECT Name, UnitPrice, Product2.Family,Product2.Name FROM PricebookEntry WHERE Pricebook2Id = '01s5I000001FeddQAC' AND IsActive = true


0

This answer is similar to other two answers, but with some additional performance and safety check which I think should be a good practice, ie: Only run query when necessary Only do assignment when reference data exists Generally the pattern is: Build a map collection to filter the query and store the corresponding query result Iterate the trigger list ...


2

Here's a commented example of how this code could be restructured using a map to associate the id values to one another. As an aside, don't use String for Id values. It is safer to use the correct data type whenever you can. trigger Add_Event_ID on Hum_data__c(before insert) { // a place to store our results Map<Id, Id> callIdToEventIdMap = new ...


2

Try this code, here I'm assuming call__Callid__c is lookup field trigger Add_Event_ID on Hum_data__c (before insert) { List<Id> callIdList = new List<Id>(); for (Hum_data__c h : Trigger.new) { callIdList.add(h.call__callid__c); } Map<Id,Id> IdMap = new Map<Id,Id>(); for(call__Call_Detail__c cc : [...


0

Since your requirements aren't described in detail and there's no code to infer from, one option would be to populate the text area field on the record using a trigger and the string.format(string, parameters) method to create the data that will be placed in the field during insert and update operations. trigger MachineTrigger on Machine__c(before insert, ...


0

If you need to return a custom field value from parent object, simply reference the Lookup/Master-Detail field's API name and change the __c to __r. If your lookup field API name is Contact__c, then use Contact__r.somefield For example: Select Name, Contact__r.Name , Contact__r.Account.Name From Pension_Contract__c Where Signing_Status__c = 'Completed'


0

You are using the wrong relationship. Please remove Pension_Contract__c. from the relationship as mentioned below:- Select Name, Contact.Name , Contact.Account.Name From Pension_Contract__c Where Signing_Status__c = 'Completed' Refer https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/...


0

As per the following document https://help.salesforce.com/articleView?id=000325257&type=1&mode=1 Get the SOQL query and replace the list of fields with the count() operator: SELECT Count() FROM Lead WHERE ProspectId__c IN :prospectIds Check the number of active records in the table: Select count() from Lead #of records: totalLeads (for eg. take ...


3

Sharing does not affect query selectivity The records have to be located first before the sharing rules can be applied. If you think about it, record visibility includes: The Org Wide Defaults Criteria-Based Sharing Rules Manual sharing Apex sharing Record ownership Role hierarchy Territories Account/etc team membership Salesforce, in effect, uses a ...


2

It looks like an issue with the Trigger Code, it can be a code quality issue (SOQL Query in a loop, excessive use of SOQL, etc. ). I think that you can still load your data but a code review should be done to bulkify the triggers code. If the Business logic implemented in the trigger (on that object you're loading) can be bypassed, you can deactivate the ...


2

I don't know if it is a bug in the way ORDER BY is applied, but if you want it to work you have to include the ORDER BY field in the SELECT output, like: SELECT String1__c, String2__c, Number__c FROM Metadata_Type__mdt WHERE Number__c > 0 ORDER BY Number__c ASC


0

Using subqueries does not sound like it will help you accomplish your goal, and on top of that, it will still hit governor limits because each subquery counts as well. Your first approach has the right idea, but the SOQL queries are in the wrong place. We never (I repeat NEVER) want to have a SOQL query inside a for loop. We will hit our governor limits ...


2

First thing to note Right away, the isPrimary field on AccountContactRelation (ACR for short) is not writable. It is automatically set, and becomes true if the AccountId on the ACR record is the same as the AccountId field on the related Contact. An ACR record is automatically created (if a suitable ACR doesn't already exist) when you set or update the ...


5

It is interesting that the documentation that I've found doesn't explicitly state this scenario is covered, at least in the main text, where it says: The value of the IN or NOT IN operator in WHERE clauses, allowing filtering on a dynamic set of values. Note that this is of particular use with a list of IDs or Strings, though it works with lists of any type ...


Top 50 recent answers are included