Hot answers tagged

9

You can supply string variable values using Apex binding. When you're not using Dynamic SOQL, as you're not here, you can even use complex Apex expressions in the bind. The following options are all legit. ... WHERE Name IN (:STRING_ONE, :stringTwo) ... WHERE Name IN :new List<String>{STRING_ONE, stringTwo} ... WHERE Name = :STRING_ONE OR Name = :...


7

If you call TimeZone.getTimeZone with an invalid SID you get back the "GMT" time zone instance - this is one way to validate that your SID is supported (by checking that the SID for the object you get back is the same as the SID you provided). However, that doesn't help with getting the list of valid options. Fortunately, the Salesforce schema includes a ...


7

static methods share state (in the form of static variables) only in the context of a single transaction. Each Lightning server call to an @AuraEnabled method takes place in a separate transaction; no state is stored on the server across such invocations. Each such method will start with the same value for listIds, which is an empty list - your initializer ...


6

You have to implement a Wrapper class with comparable interface for this to happen. To implement a custom sort order for sObjects in lists, create a wrapper class for the sObject and implement the Comparable interface. The wrapper class contains the sObject in question and implements the compareTo method, in which you specify the sort logic. Eg: ...


6

It's like normal SOQL, but you put the colons before each item in the list: public class MyClass { private final String STRING_ONE = 'STRING ONE'; public MyClass(String stringTwo) { List<Object__c> objects = [ SELECT Id FROM Object__c WHERE Name IN (:STRING_ONE, :stringTwo) ]; } }


6

emailMatchingContacts.values() will return List of the values of Map from key-value pairs. That will be List<Set<Id>> This will be resolved by either 1 of them: emailMatchingContacts should be of type Map<String,Id> OR . you should do matchingContactIds.addAll(emailMatchingContacts.get(key)) emailMatchingContacts.get(key) will return ...


5

I believe I need to rely mostly on the List<X>.getSObjectType() method. At least as a first step. If it doesn't return a null Schema.SObjectType then I can use that to determine the type. If it does return null I've got more work to do. The type of each sObject in the list needs to be checked to see if they are all the same. void processSObjectList(...


5

As it says, you're trying to assign an Id (a scalar value) to a collection. You need a loop for this: Id[] voterIds = new Id[0]; for(Vote__c record: [SELECT Id FROM Vote__c WHERE Suggestion__c = :recordId]) { voterIds.add(record.Id); } Or, my favorite choice for getting a list of ID values, using a Map to get the values all at once: Set<Id> ...


5

Given that you are storing a list of numbers in a delimited string field, "24; 35; 67", you have exactly two options. One is iteration (a loop); the other is recursion. You do not have the option of using aggregate queries or roll-up summary fields because you don't have actual number fields to look at. Apex does not natively support a reduce() function, a ...


4

It's much easier to create a tiny with sharing helper class and allow the platform to handle visibility calculations for you. It could look something like this: public with sharing class QueryHelper { public static List<sObject> query(String q) { return Database.query(q); } } Then, in your main class, do query += QUERY_BASE + ...


4

This is a per-transaction limit. You'll need to break your code apart by using Batchable, Queueable or some other technique to stay under the 10,000 DML rows per transaction limit. There's way to break this limit under normal conditions. A transaction includes all the code that runs from start to finish in a single request, so if you're deleting a lot of ...


4

The order of iteration for both Map.keySet() and Map.values() are defined to be deterministic. From the Summer '15 Release Notes, Iteration Order for Maps and Sets Is Now Predictable: The order of elements in unordered collections (Map and Set) is now the same each time your code is run. Previously, the order of elements in unordered collections was ...


4

The current syntax you have is incorrect. You dereference a field when you know that your query will return only one record. This is what seems to be the case here where you are dereferencing the ID field and thus it is always assumed that there is one record returned from the query, which you are trying to assign to a List, resulting in the error. The ...


4

You cannot access related fields in trigger context, only fields on the object that is in transaction can be accessed. If you want to access related fields, you will have to query it explicitly. If you try to access relationship fields in trigger context, it will return null, hence your list is showing null. In your case, as you are accessing the ID field, ...


4

You can do this using the standard sort() method provided by the List type if your ListWrapper class implements the Comparable interface You'll have to decide for yourself how to compare two different instances of your ListWrapper, but the general pattern is going to be the same global Integer compareTo(Object o){ // typecast the argument so that you ...


3

As the error states, you cannot remove an item from a collection (in this case a List) while iterating on it. While I am not completely sure what you are trying to achieve as it seems you are first adding items to the list and then removing it. But the approach that I have used to remove an item from list during iteration is: for(Integer index = myList....


3

You can't do it without loops. There are surely dozens of ways to go about it, but here's one such: public List<Integer> getDuplicates(List<Integer> input) { Set<Integer> output = new Set<Integer>(); Set<Integer> alreadySeen = new Set<Integer>(); for (Integer value : input) { if (alreadySeen....


3

A Set<Map<String, String>> can contain and deduplicate Map<String, String> by their contents. When working with Set, keep in mind how it determines object identity: Uniqueness of all other non-primitive types is determined by comparing the objects’ fields. As an illustration, you can do Set<Map<String, String>> s = new Set&...


3

In order to have something additional related to each SObject record with purpose to show it on VF page, you want to have wrapper class. This class will store sobject record itself and related to it body list. Wrapper example: public class CustomObjWrapper{ public MyCustomeObj__c sobj {get; set;} public List<String> bodyList {get; set;} ...


3

You're missing the parameter. Try : public class ProjectStatus{ public static void Test() { // Notice I took out the bit between the () List<String> myArray = new List<String>(); // and added the variable as a local variable // Removed the "list<>" from below code for (pse__Proj__c p : [SELECT Id FROM ...


3

this is because of that query editor, anonymous apex and standard controller enforce sharing rules. Meanwhile, without explicitly mentioning sharing keyword for apex class it runs in system mode. The new feature starting with 44.0 is Inherited Sharing is preferable to use An Apex class with inherited sharing runs as with sharing when used as a Lightning ...


3

We'd have to see the return value from your Apex, but the proper code to populate this usually goes something like this: var retVal = response.getReturnValue().issues; var opts = retVal.map(opt => ({ value: opt.Id, label: opt.Name })); component.set("v.issues", opts); You would not ordinarily call toString() on the values returned from Apex, as they are ...


3

If you are checking in the debug logs, then that is how it will be displayed. It behaves the same for the normal SOQL query as well as for the dynamic SOQL i.e. with Database.Query So, if you perform a SOQL on Object1__c with field3__c as null, then the debug will always show you USER_DEBUG [2]|DEBUG|Object1__c:{Id=0010o00002GxDELAA3, field1__c=CD355119-A,...


3

This error indicates that a DML update is being performed on some List<sObject>, and the relevant list contains the same object multiple times. Scanning through updateRelationships(), the proximate cause is this line: update updateCards; which is performing an update on a List<CaptureCard__c>. The better, and more typical, pattern is to ...


3

Since StartDate__c is not unique, then you have one of two choices: Use a unique key (Id, or other field) Change your map to handle many records per one key Since you seemed to suggest that doing #1 led to CPU time limits, I'd suggest changing your map to hold a list of Gear or Tool objects. Example for tool below assuming that StartDate and your EndDate ...


3

When You say I used a list to get the values of the custom metadata fields. First of all, You should consider that [SELECT A__c, B__c, C__c FROM CustomMetadata__mdt] SOQL returns you a list of CMT records, not fields. So if You want to get a concrete record of CMT you should specify filter conditions [SELECT A__c, B__c, C__c FROM CustomMetadata__mdt ...


3

To check the list empty value, You can use these methods from List class:- isEmpty() Returns true if the list has zero elements. Example:- !opportunitiesMap.get(actualTool.Rent__r.Opportunity__c).OpportunityInfo__r.isEmpty() size() Returns the number of elements in the list. Example:- List<Integer> myList = new List<Integer>(); Integer ...


2

I know this is a bit old, but if your problem is with the svg component, you can replace it with the <lightning:icon> component. It will render the svg tag. You can find more information about the icon component in the following link: https://developer.salesforce.com/docs/component-library/bundle/lightning-icon/documentation I couldn't find any ...


2

You just need to call addAll instead. addAll(fromList) Adds all of the elements in the specified list to the list that calls the method. Both lists must be of the same type. Signature public Void addAll(List fromList)


2

There's a list maintained in the Relative Date Filter Reference. The current list is as follows: YESTERDAY TODAY TOMORROW LAST WEEK THIS WEEK NEXT WEEK LAST n WEEKS NEXT n WEEKS n WEEKS AGO LAST MONTH THIS MONTH NEXT n MONTHS LAST n MONTHS n MONTHS AGO NEXT MONTH LAST 90 DAYS NEXT 90 DAYS LAST n DAYS NEXT n DAYS n ...


Only top voted, non community-wiki answers of a minimum length are eligible