New answers tagged

5

Change: public static List<Loan_Application__c> getLoanApplications() { @AuraEnabled(cacheable=true) to: @AuraEnabled(cacheable=true) public static List<Loan_Application__c> getLoanApplications() {


3

Keep in mind that there's a maximum response size even if you didn't hit the heap limits (in fact, the response size is limited by heap size). As such, what you've got going on is probably the best way to approach your problem. That's presuming, of course, the external system can't just call a Salesforce API directly, which would be more ideal.


2

With SOQL alone, it is not possible to query two unrelated objects in a single query. Relationship fields (lookup, master-detail) are the interface we're given to access data on other records from SOQL. If you can't add a relationship field, then you'd need to need to handle this using a tool besides SOQL. That could be Apex or, if you're using LWC/Aura, ...


0

You can make this simpler (and avoid requerying the Students to add the GPAs) // insert 300 students for (Integer i = 0;i<300; i++) { students.add(new Student__c(Last_Name__c = 'Account'+ i, First_Name__c = 'Test', School_Year__c = '2010-11;2011-12', GradeClass__c = '01', School_Orphanage_Org__c = 'AEMSA SM'))...


1

When generating CSVs, Use the escapeCsv method on all string cells as you won't know in advance whether any database data might or might not have an embedded " or line-break String s = 'abc "def" ghi'; System.debug(LoggingLevel.INFO,s.escapeCsv()); |USER_DEBUG|[2]|INFO|"abc ""def"" ghi" RFC4180 defines valid CSV ...


0

Because in the string recordString = ... line you are surrounding everything by double quotes, then you need to escape any double quotes that exist in your field value. Assuming that c.RepairDetailDescription__c is the field (potentially) containing double quotes, you could do something like this: for(case c : Database.query(Query)){ String ...


1

You can do this in the SOQL: SELECT ... FROM MyObject__c WHERE CALENDAR_YEAR(DateTime_Field__c) <= 2021 AND CALENDAR_YEAR(DateTime_Field__c) > 2011 AND CALENDAR_MONTH(DateTime_Field__c) = 6 AND DAY_IN_MONTH(DateTime_Field__c) = 14 Other options are available, too; see the Date Functions for more information.


0

Since you have tagged this question with Apex, it should be relatively straightforward. You can simply generate a List<Date> and populate it with the values you need, then filter on that. List<Date> dates = new List<Date>(); for (Integer i = 0; i < 6; i++) dates.add(Date.today().addYears(-i); List<MyObject__c> records = [ ...


0

I would first try to simply filter on Owner.Country: SELECT ... FROM SF_Application__c WHERE SF__Job_Id__c IN (SELECT Id FROM SF__Job__c WHERE Owner.Country IN (...) Failing that, the go to solution for limitations in SOQL is to add a formula. It should be relatively straightforward to introduce an Owner_Country__c field and filter on that instead.


0

The wrapper to send Opportunity and its associated is one Item and you will need to build the list of this Item to send as multiple Items. something like an array of objects which contains two items each - Oppty and associated approval process. Pseudo and non-tested code below. Additionally added a comment for the other issues in your code query inside for ...


0

An another answer to the question is the wrapper class. But, more important to say, it is very BAD practice to do SOQL query in the for loop. You should avoid it anytime, anywhere and anything! And, in your case, it might not need to merge the 2 lists. Why not using the relationship query to do the same thing? It is a re-writing and try to do the same thing ...


2

You could merge the 2 lists with code like below outside of the for loop: List<SObject> FinalList = new List<SObject>(); FinalList.addAll(OppData); FinalList.addAll(ApprovalList); Also, check out similar thread here


0

If you're using lists, you'll see lots of duplication. There's a row for every instance of a subscriber in each list they're members of. To your point: SELECT x.* FROM ( SELECT ROW_NUMBER() OVER(PARTITION BY s.EmailAddress ORDER BY s.DateJoined ASC) AS RowNumber, s.* FROM _Subscribers s WITH (NOLOCK) ) AS x ...


1

In this loop... for(Student__c s : students) ...the code is looping through the students List that was created and inserted before any of the Student_GPA__c data was created. So while the objects in this list variable did get their id values returned after insertion, they do not hold any reference to any data created after them. So try changing the loop ...


4

Both of the answers currently posted are incorrect. There is no limit on the records selected by the antijoin subquery. From the SOQL and SOSL Reference: There’s no limit on the number of records matched in a subquery [note, specifically referring to a semijoin or antijoin]. Standard SOQL query limits apply to the main query. So this query incurs the ...


0

The limit is 50k records (except for read only attribute). Only the records fetched the main query have the limit of 50K records. If you exceed this limit you will get a LimitException. In a SOQL query with parent-child relationship subqueries, each parent-child relationship counts as an extra query. These types of queries have a limit of three times the ...


0

This are the limits: https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm I don't know anything about 20k, but as per the official documentation you can retrieve 50.000 record with an SOQL query


0

Derek F's answer was correct (and marked as the accepted answer). For future readers, here was my final code: Apex Class: @RestResource(urlMapping='/Accounts/*/contacts') global with sharing class AccountManager { @HttpGet global static Account getAccount(){ RestRequest request = RestContext.request; String accountId = request....


2

This appears to be an issue with your url mapping. Your class uses /Account/*/contacts Trailhead specifies that your mapping should be /Accounts/*/contacts (notice that the requested mapping uses "Accounts", plural) Beyond that, using @isTest(seeAllData = true) is bad practice, and you should nip that in the bud before it becomes a habit. In 99.9% ...


1

When using variables in queries, you need to use colon : before the variable name. This trailhead can give you more details. @AuraEnabled(cacheable=true) public static Map<string,integer> ApprovalKPI(){ Map<string, integer> dataExportmap = new map<string, integer>(); for(Region__c RegionItem:[SELECT Id, Name FROM ...


2

in order to use a function like COUNT(), you need to follow it up with a resulting fieldname, in which the result should be returned. This column of course needs to exist in your target DE. In this example, it's called "mycount": select a.EmailAddress, COUNT(a.EmailAddress) AS myCount from _ListSubscribers a GROUP BY a.EmailAddress HAVING COUNT(...


3

UPDATE: you cannot make aggregate function in subquery, so the 1st approach isn't for you. You can use subquery from a Project__c record: SELECT Id, (SELECT Id, resource_name__c FROM Timecard__r ORDER BY CreatedDate DESC LIMIT 1) FROM Project__c UPDATE: you need GROUP BY CUBE (link to documentation GROUP BY CUBE) If the solution above is not suitable for ...


1

FIELDS(ALL) is not currently supported on Unbounded queries. You can try with FIELDS(STANDARD). Also it's recommended to only query the fields you need to improve performance. Docs: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/api/sforce_api_calls_soql_select_fields.htm


2

You're sending emails in the execute method of your Batch class, so it's going to send emails for every batch of records. Most likely, the users who are getting it multiple times are probably the users in the first batch. They get the email when the first batch executes and the again on successive batches. The users only getting the email once are probably ...


2

You can actually do a join on history tables. So this ask is pretty simple. SELECT ... FROM Account WHERE Id NOT IN ( SELECT AccountId FROM AccountHistory WHERE Field = 'Status' AND CreatedDate = LAST_YEAR )


2

You're doing an aggregate query, but trying to assign the results to a list of Users. Change User[] to AggregateResult[]. See https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_agg_fns.htm


0

Always use binding so that we don't need to worry about SQL Injection and it also makes code more clean and readable. public class LwcLookupController { @AuraEnabled(cacheable=true) public static List<sObject> findRecords(String searchKey, String objectName) { String searchText = '%' + searchKey + '%'; String query = '...


0

You seem to have removed your leading wildcard. String searchText = '\'%' + String.escapeSingleQuotes(searchKey) + '%\''; // ^ MISSING


0

The PermissionSetAssignment object lists the Permission Sets a user is assigned to. In addition, a PermissionSetAssignment exists for the user's profile. This design was meant to unify a user's permissions in to a single object so developer can easily determine what permissions a user has. As such, you can query: SELECT SystemModStamp, PermissionSet.Name, ...


1

The best way to deal with this is to make sure you have an index somehow. There's a lot of ways to potentially deal with this. Restrict By Opportunity As long as the query on the Opportunity is selective (e.g. you query for Opportunity__c where it is a specific Id value, and not null), then the null values in ParentConfiguration__c won't matter. The only ...


1

To query a child, you use: SELECT (SELECT Field1, Field2,... FROM Children) FROM Parent To query a parent, you use: SELECT Parent.Field1, Parent.Field2,... FROM Child Since Marketplace__c has a field named Channel__c that refers to the Account object, you need to use the latter version: SELECT Channel__r.Name, Channel__r.Account_Cohort__c FROM ...


1

You need to know the existing dates, you need to check possible dates against the existing dates. Easy enough to brute force. You'll also need more than one return value, to give both the list of objects and the list of missing dates, so a slightly different structure would be used. public class SomeClass { @AuraEnabled public List<...


0

Use this below query :- SELECT Id, Label, ProcessType FROM FlowDefinitionView


1

Using newInstance is kind of redundant because you don't use created SObject instance. Here are a few options which you can use I think this one is the best option: Car__c carobj = new Car__c(); carobj.Price__c = 1000000; carobj.Car_Segment__c = '0034R00003bVDo1QAG'; //need to check whether the lookup field exists before assigning values String fieldName = ...


0

It's critical to be clear about (a) what the packages involved are; (b) their mutual relationship; and (c) their namespaces, if any. You have a package called Cars with namespace car. You also have a package Tyres with namespace Tyres. What's not clear is the relationship between them: There is another package 'Tyres' which has an object 'Tyre_Quality__c'. ...


2

UserInfo.getUserName() doesn't get the User's Name. It gets the User's UserName. What you need is UserInfo.getName().


0

oppIds.add(pro.Id); Should be: oppIds.add(pro.OpportunityId); You're trying to query the Opportunities using OpportunityLineItem Ids, so nothing gets returned from the query. In addition, in an after delete trigger, Trigger.new doesn't exist, you need to use Trigger.old. trigger UpdateOppWithProd on OpportunityLineItem (after insert, after update, after ...


1

The reason you are getting rows in your query which do not have rendered children is that your WHERE join is unfiltered, despite the filters on your SELECT join. If you want the query to only return rows which have matching children, the two joins need the same WHERE filters. SELECT Id, ( SELECT ... FROM Plan_Split_Disbursements__r WHERE ... ) ...


1

you can directly pass date as a parameter in apex. And query like below code example. @AuraEnabled(cacheable=true) public static List<Exchange_Rate__c> getListExchangeRates (Date toDate , Date fromDate){ String currencys = converter(getListFieldsCurrenciesForRequest()); return Database.query('SELECT Date__c, Base_Currency__c, ' + ...


0

As per the documentations here TargetObject is a polymorphic relationship field. Below is an excerpt from the documentation on polymorphic fields In a polymorphic relationship, the referenced object of the relationship can be one of several different types of object. Some fields are relationship fields, which means they can be used to get information about ...


3

It looks like an unbounded query is not currently supported in Apex. This query in your test class is considered an unbound query, hence the error. Not sure why it doesn't fail in the dev console query editor. Maybe it uses the REST API behind the scenes (?) https://developer.salesforce.com/docs/atlas.en-us.230.0.soql_sosl.meta/soql_sosl/...


3

Looks like it is a query exception and has nothing to do with way you are passing in the attributes. Try using the below return Database.query('SELECT Date__c, Base_Currency__c, ' + currencys + ' FROM Exchange_Rate__c WHERE Date__c = :dateExchangeRates'); Note apex variables are automatically resolved for you


0

Instead of querying inside for loop add all the Job_Application__r.Id in a set of Id and then fetch all the Review__c records where Job_Application__r.Id is IN set of Id Below is the code example: set<Id> jobApplicationIds=new set<Id> (); for(Review__c rev : newList) { jobApplicationIds.add(rev.Job_Application__r.Id); } List<Review__c> ...


2

In Apex, just take away 24 hours: Date last24Hours = DateTime.now().addDays(-1); Employee__c[] employeesLast24Hours = [ SELECT My_Date__c FROM Employee__c WHERE My_Date__c >= :last24Hours ]; If you really want the last 24 hours without a variable, it should look more like: SELECT My_Date__c FROM Employee__c WHERE My_Date__c = TODAY OR (...


2

You can use SearchActivity object to perform a SOQL. Below is the sample query. You can modify the query as per your requirement. . SELECT Id,SearchTerm FROM SearchActivity Refer documentation here. Describe the object in Developer Console and check for other fields available as per your need. Adding a screenshot of available fields for your reference.


2

in the inner soql query , you have to use plural label appended with __r. go to product2 object, open the lookup field with custom object. note down child relationship name. lets say child relationship name is products, then you have to use products__r in inner query. select id, (select id from Products__r) from myObject__c


0

Snl, There are different topics here. WITH SECURITY_ENFORCED. This a good keyword to use, but it is not required that you use it for the security review. Security Review of internal apps. The issue with the review is that you avoid SOQL Injection and that your app performs secure access control logic. Good access control means that you respect the ...


1

When you debug the map it will only show the fields which has value (means which is not null). If you want to check if the empty filed is coming or not then you can debug it separately. Below is the code example: System.debug(mapSalesforceSalesAssignments.get(objSSA.Country__c).State_Province__c);


4

The UI format is just a more user-friendly format, shown in your preferred timezone, converted from GMT on the back end. The results of your query are the IS0-8601 format, how it is stored on the back end. The output of your Apex code is the default formatting of the Datetime primative data type. Additional Resource on Datetime methods on Apex: https://...


1

If you're happy to list the standard objects that are of interest, you can get these and all the custom objects using something like: Set<String> standard = new Set<String> { 'Account', 'Contact', 'Product', 'Order' }; List<String> sobjectList = new List<String>(); for (Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values())...


Top 50 recent answers are included