New answers tagged

2

You're right that SObject.clone will maintain the existing relationship(s). An option is to construct a Map<String, Object> that mimics the SObject then turn that back into an SObject, something like: Root__c root = ...; Map<String, Object> fields = root.getPopulatedFieldsAsMap(); Map<String, Object> rootOnlyMap = new Map<String, Object&...


0

Added comments as required. htmlBody = '<table border="1" class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_col-bordered" style="border-collapse: collapse"><caption><b>Report for Orders Closed Current Quarter</b></caption><tr><th></th><th>$New ...


1

The go-to SOQL technology in this sort of scenario is to use an Aggregate Query. In this case you want data grouped by Group__c. However, since you still want to get back an Account for each group you must decide the criteria for selecting the account from each group. To be able to do this in a single aggregate query you will need to restrict that decision ...


3

You can't achieve this in SOQL, which doesn't allow comparison of one field to another. You can only compare fields with a constant expression. What you can do is create a formula field on the PricebookEntry whose value is equal to the outcome of that comparison: CurrencyIsoCode = Product2.CurrencyIsoCode Then, you can reference that field in your query: ...


2

I would recommend just using papaparse. Once imported, you can have the list of objects returned from the wire call and passed directly into Papaparse, which will output a CSV for you. let csv = Papa.unparse(accountData); Since you're already using D3, I presume you're familiar with importing scripts to LWC. All you need is a bit of help, and that library ...


6

I've seen a report of a major AWS outage today in the East coast server farm. Along with reports that Heroku/Heroku Connect is also affected. It is unclear if they are related or not. A Heroku issue would well affect the hosted version of workbench that Salesforce provides. The Heroku Status page is showing an issue being investigated.


0

Do your query on the lookup object, not on Classified_Field_Log__c. SELECT Id, (SELECT Id, <some other fields> FROM Classified_Field_Log__c ORDER BY CreatedDate DESC LIMIT 1) FROM Lookup_Object__c WHERE Id IN :lookupField


0

It sounds like you would need three queries: List<Classified_Field_Log__c > Latest1 = [select Id, ... FROM Classified_Field_Log__c WHERE LookupField_1__c in : LookupField ORDER BY CreatedDate DESC LIMIT 1]; List<Classified_Field_Log__c > Latest2 = [select Id, ... FROM Classified_Field_Log__c WHERE LookupField_2__c in : LookupField ORDER BY ...


1

When you instantiate an sObject variable with the Id of an existing record: PBSI__PBSI_Item__c item = new PBSI__PBSI_Item__c(id=ol.PBSI__ITEM__c); //item Nevers seems to get instantiated It does not inherit field values from the source variable or record, so this: // all of the data below return nulls... system.debug('Item ...


2

From research: If Multiple Currencies is not enabled: The CurrencyType and DatedConversionRate Sobjects are not exposed. If Multiple Currencies is enabled: Both CurrencyType and DatedConversionRate Sobjects are exposed. But, if Advanced Currency Management (ACM) is not enabled, DatedConversionRate is not createable (by checking the Sobject's describe). ...


2

You need to change your Aggregate query to look like this: for(AggregateResult clsOrd : [SELECT SBQQ__Quote__r.Owner.Name ownerName, SBQQ__Quote__r.SBQQ__Account__r.Geo__c accountGeo, GROUPING(SBQQ__Quote__r.Owner.Name) grpOwnerName, GROUPING(SBQQ__Quote__r.SBQQ__Account__r....


1

The most re-usable approach is to add a formula field that converts the dotted numbers into one number e.g.: formulaFieldValue = 1000000 * firstDigit + 1000 * secondDigit + thirdDigit and sort by that value in queries or in default UI. There are various text functions to allow you to do that including FIND, but the formula will be fairly messy having to ...


1

You can use the clone method to clone any SObject in Apex. It takes up to 4 optional parameters, all of which are false by default: clone(preserveId, isDeepClone, preserveReadonlyTimestamps, preserveAutonumber) preserveId: keeps the ID of the SObject you're cloning. isDeepClone: This one is a bit harder to understand. If true, then the relationship fields (...


0

For me, it looks like most probably is a false positive. If you change your code to be: for(E2CAdv__Comment_Attachments__c att : [SELECT id,E2CAdv__Attachment__c, E2CAdv__CaseId__c, E2CAdv__Attachment_links__c, E2CAdv__Comment__c FROM E2CAdv__Comment_Attachments__c WHERE E2CAdv__Comment__c =:caseCommentIds]) { links.add(att.E2CAdv__Attachment_links__c); ...


0

You can't use SOSL for this purpose. You can only search the index and then limit the results by various filters (including Id). You will need to use multiple queries to get the data from multiple, unrelated records.


2

You're missing a space after FROM Account, which is a constant pitfall when building queries through string concatenation. This would be easier to see if you did not use Dynamic SOQL here, since you do not need it. Just write a static SOQL query: return Database.getQueryLocator([ SELECT Id, BillingStreet, BillingCity, BillingState, ...


1

There is a limit, looks like it's 3 times 100. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm I think it's a good way to get data, as long as the query doesn't get too slow to run.


0

I just figured out that via REST API or Apex code it's working as desired. I was building the Query via https://workbench.developerforce.com/ and the alias are not working as expected.


0

Use inner query as (SELECT Id, Status__c FROM Work_Orders__r) this will work.Replace "WorkOrder__r" with "Work_Orders__r"


2

Given the governor limits involved, you should not generally query twice for the same rows. This reduces the effective maximum from 50,000 rows to 25,000 rows, which doesn't sound too bad, but remember that the limits include all sub-transactions, so it's important not to waste them frivolously. However, you should not use a bubble sort. It has only slightly ...


3

When LWC initially came out, several operations queued at once would share governor limits. This changed in Winter '20. Each call to the server now gets the full governor limits, even when using the boxcar feature that groups calls together. See this question for more details. As far as using one query or two? Use one query and post-process in JavaScript. ...


1

The error you're getting means just that. Subqueries cannot contain aggregate functions (sum, count, max, avg, min). Only the main query (root query) can have those. Beyond that, Phil W hits it pretty close to the head (get that query out of the loop). The one point I'd like to make here is to call attention to your objective. You say you want to roll-up ...


4

There are two issues here: SOQL in a loop Incorrect use of aggregation Switch the processing round to remove the loop over the opportunities by using a query like: AggregateResult[] groupedResults = [ SELECT AccountId, SUM(Amount) sumAmount FROM Opportunity WHERE Id IN :oppsList GROUP BY AccountId ]; ...


0

For those people who come across this old but still relevant question, see the more complete community wiki answer here


0

AppTabMember is available in Salesforce API version 43 and later. See the Salesforce reference page for this object: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_apptabmember.htm You'll need to find out what API version PowerQuery is using, and if you can change it.


7

Agreed with sfdcfox that returning a List<SObject> will materialize the whole query first rather than let you do a proper SOQL FOR loop. One alternative is, you could have your factory return Database.getQueryLocator(query) which is of type Database.queryLocator. Then you can call .iterator() on that locator to return an Iterator<SObject>. Now ...


5

Yes, Salesforce requires either an inline query or a direct call to Database.query. When returning a value from a function call, all the results will be retrieved before the values can be used, similar to: Account[] records = Database.query('select id from account'); for(Account record: records); There's no way around this restriction aside from actually ...


1

Performing DML only affects the object the DML is performed on. It has no effect on related records (except for causing rollup summary fields to re-evaluate on parent records, and whatever you are doing in any Opportunity trigger, Process Builder, etc...). If you want to update the accounts, you need to perform DML directly on those Accounts. Related records ...


3

WHERE Id IN (Select ParentId From Obj__r) This is certainly wrong in at least one way, but possibly more than one since this is not the actual text of your query. A semi-join sub-select, which is what this is, is not a child subquery and would never use a relationship name (__r). Rather it would directly query the object, with either __c or no suffix if the ...


0

You can check following example code. First you have select the record and then update result set. $query = "SELECT Id, FirstName, LastName, Email,Phone from Contact where Email='myemail@mail.in'"; $response = $connection->query($query); /*Make changes in result array and then pass to update function*/ $array = array(); foreach ($response ...


0

I recently encountered this issue! Issue: In my case, Object xyz was used to group by over field xyz_1 which gave around 100 records. One day data was loaded in Object xyz exceeding its count more than 50000. Code started hitting the governor limit of 50000 rows while the query was returning just 100 records. As mentioned by Bob Buzzard in the previous ...


2

In this situation, don't. Pass the set of Ids into your batch class's constructor and store it in an instance variable: public class toInsertOrderBillPriceShares_Batch implements Database.Batchable<sObject> { private Set<Id> setIds; public toInsertOrderBillPriceShares_Batch(Set<Id> setIds) { this.setIds = setIds; } ...


3

Salesforce does automatically the filter on the sub-queries provided that you use a relationship field to fetch them (Lookup / Master Detail). Assume you have an sObject called Prod__c and also a relationship field from Prod__c to Case with Api name Case__c (and which "Child Relationship Name" is Prods (You can check chat on the detail of the ...


1

Your query as written Select id, Account.Name from ObjB where Account.Name IN(select Account__c from ObjC ). cannot source data from Object C, another child of Account. In fact, it shouldn't work at all, because you're performing a semi-join against a non-Id field. You can however start the query from the Account level and perform two child subqueries: ...


0

String query='Select id from OpportunityContactRole Where IsPrimary=true AND OpportunityId IN (SELECT Id from Opportunity where recordtype.name = 'XYZ Solutions')'; You have to escape nested single quotes in Apex. But here, you don't need Dynamic SOQL at all. Just use a static query: return Database.getQueryLocator([ SELECT Id FROM ...


0

You would need to escape the quote characters (e.g. \'XYZ Solutions\'). However, you should use an inline query instead: return Database.getQueryLocator([ Select id from OpportunityContactRole Where IsPrimary=true AND OpportunityId IN (SELECT Id from Opportunity where recordtype.name = 'XYZ Solutions') ]);


0

This is a basic error, where you are trying to access a list. Try to go through apex documentation and see how does list or collections works in apex. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections.htm list<Configuration__c> confList = [select id, name, Basket__r.id, Basket__r.Account__r.id, ...


1

Because of the sheer number of tables involved, you can't use the SetupEntity relationship; in this way, it behaves more like a "special text field" rather than a "lookup relationship" field. The documentation does not specifically call this out, but if you check the examples, you'll notice there's no example of using the SetupEntityId ...


1

If you want to encrypt a field and still use it in a query you need to change the way you query the data. Our general approach, certainly for User and Contact email addresses, was to: Switch from SOQL to SOSL, having the SOSL search for the required value in the "EMAIL FIELDS" search group using the match value for the SearchQuery. Post-filter the ...


1

Certain field are not groupable (already answered here by @DavidReed). You may check this via Describe objects & field in apex. Or, you can check this from Workbench > Info > Standard & Custom Objects > Expand Fields & then the specific field > Check the groupable attribute. Sample screenshot given below for another field.


0

I was able to get proper json formatted records from Bulk API by formatting raw records that jsforce is emitting. I used csvtojson library to listen to the stream that jsforce is returning and parsing each row as json. Once I set flatKeys and checkType properties to false and true respectively, I am getting data in the format I need and easy to work with. ...


1

The other options here are good for using logic during page render or during data processing. But if you have a lot happening at this stage of your process these could be heavy. (maybe maybe not). Another option which will alow you to filter on your situation and reduce the number of records returned. Use a BeforeTrigger when saving each record to set a ...


1

That's just an artifact of using the developer console. If you use anonymous apex to run that query, and system.debug(myEmailMessage.Parent.RecordType.Name); (system.debug doesn't print nested objects, or does so very minimally) or system.debug(JSON.serialize(myEmailMessage));, you'll see that you do in fact get the data you requested in your query.


1

If you want this done via apex, then use DescribeSObjectResult & DescribeFieldResult classes. These classes have method like isQueryable(), isFilterable(), isCreateable() and many more. Sample code snippets are already provided in the apex developer guide here & here. You can also use SOAP api. Check out DescribeSObjectResult & ...


0

I am not sure about all your environment. But the subquery is wrong: Select Id, Name, Report_ID__c, Attachment_Name__c, Email_Subject__c, Email_Body__c, Email_Recipients__c, Frequency__c, Weekly_Days__c, Monthly_Day__c, Last_Ran__c, reportname__c from Exporter__c where reportname__c in (select id from report) However, I suggest to review your query. I ...


0

The error message is very clear. You cannot add items to or remove items from a collection that is feeding a loop. The following is wrong (and basically what you have): for(Object thing :myList){ myList.add('new thing'); // <= Can't do this } Get rid of that, and just modify the loop control variable directly. That'd get you past your initial error, ...


0

https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers/apex_triggers_intro please use in your case for(Contact s : Trigger.new) { s.LastName = s.LastName + '-' + s.AccountId; } but another problem - each time contact is edited, AccountId will be appended to LastName Thanks


1

From the simple-salesforce doc, an example of format_soql with binding of a list looks like this: sf.query(format_soql("SELECT Id, Email FROM Contact WHERE LastName IN {names}", names=["Smith", "Jones"])) The value of names in the example a list of strings. In your case the list you want is a list of keys in your dict. Adapting ...


1

Address field (for example: BillingAddress, ShippingAddress etc. in Account object) is a compound field that cannot be used for filtering in SOQL WHERE clause. For such fields, you would want to use its individual component fields (for example: BillingAddress field is composed of BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, ...


Top 50 recent answers are included