New answers tagged

0

The general rule for SOQL queries is "5 up, 1 down". Querying data on related records You can query up to 5 levels upwards in a hierarchy (e.g. Opportunity to Account is going "up" the hierarchy. An Opportunity is only related to a single Account, but an Account can be related to many Opportunities). You can query up to 1 level downwards in a hierarchy (e....


0

This Salesforce help article explains all the info from the query plan tool. For sObject cardinality it says: The approximate record count for the queried object. So you seem to have approximately 20 records in that object. The two notes mean The field IsDeleted is not indexed and thus the query cannot be optimized by leveraging this filter field. The ...


1

You need to use ALL rows for querying archived records ContentDocument[] cd=[SELECT Id, Title FROM ContentDocument where isArchived = true ALL ROWS]; system.debug([SELECT id FROM ContentDocumentLink where ContentDocumentId=:cd[0].id and LinkedEntityId='0060o00001ChnVeAAJ' ALL ROWS]); you have to do something like this


1

if( opp.RecordTypeId == customerOpportunityRecordTypeId && opp.Invoice_ID__c != '') { You should compare to null or use String.isBlank(). Empty strings are not stored in the database. custOpps = [SELECT Id, name, Opportunity__c, Invoice_ID__c FROM Invoices__c WHERE Invoice_ID__c = : custInvoiceIds ]; Here, you need to create a Map<String, ...


1

I managed to do it using 1 API request: /services/data/v46.0/query/?q=SELECT Id, ParentId, SetupEntityId FROM SetupEntityAccess WHERE SetupEntityId IN (SELECT Id FROM CustomPermission WHERE NamespacePrefix = '{{NAMESPACE_PREFIX}}') AND ParentId IN (SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId = '{{USER_ID}}')


0

This is the best I came up with myself: public SObject queryAllAccessible(Id recordId) { SObjectType type = recordId.getSObjectType(); List<String> allFields = new List<String>(type.getDescribe().fields.getMap().keySet()); String soql = String.format('SELECT {0} FROM {1} WHERE Id = :recordId', new ...


1

@Brian Miller is right, there is no such thing for Apex, you need to implement it yourself. Here is an example of how you can accomplish your needs (note, I have used 28 days for month and 365 days for year, I haven't converted months to years because it can fail the accuracy of calculations): public without sharing class DateTimeUtil { public static ...


1

To build on the jsForce response. This can also be done via the tooling API: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_installedsubscriberpackage.htm conn.tooling.sobject('InstalledSubscriberPackage').find({ },[ "SubscriberPackage.NamespacePrefix", "SubscriberPackageVersion.MajorVersion", "...


3

You can get that in the Tooling API. Here's a query you can use to get started: SELECT Id, SubscriberPackageId, SubscriberPackage.NamespacePrefix, SubscriberPackage.Name, SubscriberPackageVersion.Id, SubscriberPackageVersion.Name, SubscriberPackageVersion.MajorVersion, SubscriberPackageVersion.MinorVersion, SubscriberPackageVersion....


2

You're basically there. What you're doing now is returning a list of PermissionSetAssignment. You want to return a boolean. Since your query is so specific (either there is or there isn't a value), you can simply add this to your return statement return !userPermSets.isEmpty(); You can see this method in the List Class documentation. You're checking if ...


1

You cannot do this with SOQL. SOQL supports only sorting and aggregation. You can theoretically SORT by Country and Total Quantity, but you'll need some code to separate them anyway


3

The main problem at hand is determining which fields to include in a query. Since this is, by necessity, a runtime calculation, we'll still need to use dynamic soql (i.e. Database.query(querystring)) The WITH_SECURITY_ENFORCED keyword for SOQL appears to throw an exception if an inaccessible field is requested. Exceptions as flow control are a bad idea, ...


2

You need to bulkify it. Did litle tweak your code. Below might help you, public class SpecialBurgerHelper{ public void burgerSetup(List<Burger__c> newBurgers){ set<id> set_OppIds = new set<id>(); set<id> set_Burger = new set<id>(); BurgerHelper burgerHelper = new BurgerHelper(); ...


1

Looking at the docs for ALL ROWS, you have to place it at the end of your query, and is 2 keywords. For it to work, update your query to: SELECT Id, Title, FileType, ContentSize FROM ContentDocument WHERE isArchived = true ALL ROWS Please note the query editor does not support an ALL ROWS query, so use anonymous apex to validate.


-1

Try it : java -cp C:\Salesforce\tools.jar;antlr-4.7.2-complete.jar;js.jar;ST-4.3.jar;force-wsc-47.0.0.jar com.sforce.ws.tools.wsdlc wsdl.xml enterprise.jar I hope it will help you.


0

You can use this chrome extension to export the picklist matrix. This supports both classic and lightning. https://chrome.google.com/webstore/detail/salesforce-dependent-pick/fpieolagnlkejcpejlbjgbdpaglffacj The csv file when opened in excel has first column as controlling field and second column as dependent field. you can then filter as required.


0

Your first attempt will not work with Custom Metadata and Objects as well, because like accepts only one argument at a time. In the case of Objects, you can use an OR operator. The second attempt works with Objects and unfortunately does not work with Custom Metadata. But as it's a custom metadata object you can write two queries to get the data and ...


0

Yes, It's possible. The synced quote as per screenshot got deleted but field "Synced Quote" at Opp still having reference. This would lead to any further updates on Opportunity with Invalid Cross Reference Field Exception.


2

For 1GP packages, I think that first Id never changes - looks to me as if it is actually the Id of the package in the packaging org (i.e. the Id in the URL when you got to create packages in the packaging org). I looked in a few customer/test orgs I have access to, and the Id is that same Id in each org. So I am thinking you can just add the Id to a ...


3

After a bit more searching I found a similar question to mine by Jake Saul: Workbench: Matrix Grouping. That included a useful screenshot showing where the missing column and row inputs for the Matrix view used to appear (via Sushil Pandey): From there it was easy enough to use the Chrome dev tools to take the display:none css off the two rows in question ...


0

I'm not sure what sObject you can query (this has always been a bit troublesome), but there's an easy alternative: SFDX. $ sfdx force:package:installed:list -u user-alias ID Package ID Package Name Namespace Package Version ID Version Name Version ────────────────── ────────────────── ──────────── ─────────────── ─...


1

trigger SMSTrigger on Message__c (before insert) { for(Message__c msg : Trigger.new){ if(!String.isEmpty(msg.to_WhatId__c) && msg.to_WhatId__c != null){ Id neededId = Id.valueOf(msg.to_WhatId__c); String objectAPIName = neededId.getSobjectType().getDescribe().name; if(objectAPIName == 'Gear__c'){ ...


4

You do not have to convert the string to lookup field, the lookup Id is a string: Id neededId = Id.valueOf(msg.to_WhatId__c); String objectAPIName = neededId.getSobjectType().getDescribe().name; if(objectAPIName == 'Gear__c'){ // assign the lookup value msg.Gear__c = neededId; } If for some business purpose, you need to refactor the code to avoid ...


0

If API limits are a concern, sObject Get Updated and Deleted may be the right way to go since only 5 QueryAll requests can be joined together in a composite call and 25 getUpdated requests can be joined.


1

Data replication systems need two use cases: Initial loads or syncs, where you obtain all data for some object to persist. Incremental or real-time updates during use. You've identified some of the features that suit those use cases. sObject Get Updated and Get Deleted are solutions for (2). It is their design purpose to be used for polling in data ...


0

The Metadata API will NOT return all the Object Names and Field Names. Instead, it provides a specific "view" of Custom Objects and Fields that are relevant to Metadata connections. Salesforce calls these "channels." You need to use the SOAP Describe API to globally list all of the objects, and then Describe all of the fields. This will provide what you are ...


1

You just need to get rid of AND CreatedDate < LAST_N_DAYS:3. CreatedDate = LAST_N_DAYS:2 should be enough for your requirement. Here is the documentation for your reference: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm


2

This is simply part of how Salesforce handles relationships. OwnerId, the field, indicates a relationship to the Owner object (well, the field is owner, the actual object is User). It's also not just any relationship, but a standard relationship (i.e. one that Salesforce provides, not a custom field) To get at data on the related object for a standard ...


0

Another alternative it to turn this into a dynamic query: Integer dynamicDate = Integer.valueOf(date.today().addMonths(3).month()); Id userRecordId = userRecord.Id; jpActivityRecordsLIST = Database.query( 'SELECT ID ' + 'FROM JourneyPlanActivity__c ' + 'WHERE (date__c = LAST_MONTH ' + 'OR date__c = THIS_MONTH ' + '...


1

You can't, but you could calculate those yourself: Integer dynamicDate = Integer.valueOf(date.today().addMonths(3).month()); Date startDate = Date.today().toStartOfMonth().addMonths(-1), endDate = Date.today().addMonths(dynamicDate).toStartOfMonth().addDays(-1); jpActivityRecordsLIST = [SELECT ID, FROM ...


0

I have used relationship name only in my nested SOQL query:


1

On the assumption that you have a custom object, Subscription__c, and that the Subscription__c has a (possibly master detail child) lookup field that references Contract, the important details are provided in the lookup field. For example, I have a "Shift_Break__c" custom object that has a lookup to "Shift__c". The field details are as follows: It is the ...


2

In my little Developer Edition org, I wasn't able to see or query the standard Type field either. I could see that it is a standard field, and I could add it to my layouts, but it did not appear when I went to a task/event/call/what-have-you. Looking at the FLS (field-level security) settings, this field was not marked as being visible (read-only implies ...


1

If using Advanced Currency Management, the dated exchange rates don't apply to objects other than those related to Opportunities Dated exchange rates are used for opportunities, opportunity products, opportunity product schedules, campaign opportunity fields, opportunity splits, and reports related to these objects and fields. Dated exchange rates are not ...


4

You can't do this in Query activity, however it is possible in AmpScript (e.g. in an email or CloudPage). You can a.o. fetch all leads where their region is set to 'west': %%[ var @rs Set @rs= RetrieveSalesforceObjects('Lead', 'Id, FirstName,LastName', 'region', '=', 'west') ]%% If you really need to do this as part of an automation, you can use an SSJS ...


5

While I was composing this question I figured it out. Since it took me longer to figure out than I would have liked, I will share what I learned in case it helps someone else down the road. It turns out that the connection between CustomPermission and the PermissionSet is made via the object called SetupEntityAccess. You can look up if a custom ...


0

You were close! You should remove that custom field and use an order by clause to select the first one. accList = [select Id,County__c,Name,Client_State__c,AssignedBanker__c,Owner.Name, (select Id,WhatId,ActivityDate,Description,Subject,Account.Name,Account.AssignedBanker__c from Tasks where ActivityDate != null AND ...


2

You cannot make a field to field comparison in SOQL i.e. as mentioned in the question, you cannot compare X.Parent.AccountId != X.AccountId. There is other workaround by which you can do this i.e. by creating a new formula field which evaluates to true when X.Parent.AccountId = X.AccountId and false when it is not same. The formula for your new field ...


2

SOQL queries are inherently single-object. You are correct that there is no way to implement this requirement as written without using iteration. However, this requirement itself is rather suspect. If you have a need to perform the same query across multiple objects, you should at least evaluating using SOSL rather than SOQL. If you simply need to perform ...


1

I had exactly the same error and the same scenario: worked in workbench did not work in Java. As suggested above, I removed the manual URL Encoding step. Java seems to be automatically encoding. Here's the final code that worked. response = client.send(HttpRequest.newBuilder() .uri(UriComponentsBuilder ...


3

You need to have a look into getRecordTypeInfosByDeveloperName Here is the sample code that fetche recordTypeId for account, where developer name of recordtype is Broker. Map<String, Schema.RecordTypeInfo> developerNameVsRecordTypeInfos = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName(); System.debug(developerNameVsRecordTypeInfos.get('...


0

The reason of this issue is that query field on parent returns [Object object] which is unable to capture it and equate with String type value(s). The work-around can be that use inner SOQL from Parent metadata to Child metadata, like List<Parent__mdt> lstEntitlementMetadata = [SELECT Id, Type__c, (SELECT Id FROM Child_relationship_name__r) FROM ...


0

Save the file as a CSV, then go to the Data Import Wizard, which allows you to map by Account Name.


Top 50 recent answers are included