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

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 ...


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

This is probably because the clas Name contains the definition of another inner class like this: public class name{ public class test{ } } If so, you have to specify the parent class name before referencing the test inner class. So if you want to make a list of records of type name.test, you have to use: List<name.test>


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

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

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

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

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 ...


4

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 ...


4

Generally speaking, when I have a question, the first place I look is at the documentation. Ordering by multiple columns is listed in ORDER BY in the SOQL & SOSL documentation (emphasis mine) The following factors affect results returned with ORDER BY: Sorting is case insensitive. ORDER BY is compatible with relationship query syntax. ...


4

This is due to how Type Systems work. While your ActiveContactListController.ContactsWithRoles object contains an AccountContactRelation object, it (ContactsWithRoles) is not the same as an AccountContactRelation object. The declared return type in your method needs to match (or extend) the type of the variable (or statement) that you actually return. ...


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

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

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

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

In this context, you cannot. If you were to try, you would receive System.FinalException: Cannot modify a collection while it is being iterated. In most programming languages, it is problematic to mutate a collection while you are iterating over it. Here, you will need to create a new List<Revenue__c> and add only elements matching your criteria to ...


2

Here is the solution: List<Exam__c> exams = new List<Exam__c>(); exams = [ SELECT Id, Exam_id__c, Exam_state__c, doNothingExam__c, Certification__r.Id, Certification__r.Exam_state__c, Certification__r.Name FROM Exam__c]; //here we are formatting the map to identify duplicates Map<String, List<Exam__c>> toCheck = new ...


2

Found the answer , foolish of me my apologies. I missed this Code groupedByPositionList = new Map<string,List<job_application__c>>();


2

You are getting that error because, you are trying to use the dot notation on list variable on visualforce page. As your Map structure is Map<Integer,List<Invoice_line_item__c>>,you will have to use two PageBlockTable's in order to display your Map in visualforce page, in first iteration of PageBlockTable, it will return you List<...


2

You should be checking "s" instead of mapKeys, and presumably check each value you're interested in: for(String s: mapkeys) { if(s == 'Account' || s == 'Contact' || s.startsWith('agf__')) { Note that if mapkeys came from a Schema.getGlobalDescribe(), they're always lowercased, so: if(mapKeys.contains('account')) { But, this would not do what you expect ...


2

The issue arises because you haven't inserted test data. I recommend you insert it in @TestSetup method of your TestClass. In the very basic case you can do it next way: @IsTest public with sharing class TestClass { @TestSetup static void dataSetup() { ContentVersion contentVersion = new ContentVersion(); contentVersion.PathOnClient ...


2

sObject[] records = new List<sObject>([SELECT ...]) "Waste of Resources" This should never be used. While not incorrect, you're basically copying the list in to a new list, then discarding the old list. As a real-life example, that'd be like going to the store, buying stuff, putting the items in to your car, driving home, taking all the stuff out of ...


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