Hot answers tagged

5

You can implement Comparable interface for your custom class and determine your rule in compareTo method. public class ListItem implements Comparable { public Integer first {get; set;} public String second {get; set;} public ListItem(Integer first, String second){ this.first = first; this.second = second; } ...


5

Given the code you have, no, acc.Contacts will not return any Contacts. To get related Contacts, you need to query for them. Since you haven't queried for them, you get an empty list (honestly, I'm a little surprised that you didn't get an error about "SObject row was retrieved via SOQL without querying the requested field"). You can use an inner ...


4

This is where you should use a Map. By having a key, you can then dynamically retrieve the values i.e find me the list values of map entry called lstStrng. Here is a broken down version of adding two entries to aMap<String, List<String>> (although I do not recommend keying by String for uniqueness reasons) and then finding the values of a dynamic ...


4

At the very least, you would want to store the results of one of your queries in a map. Given a public Map<String, Object> myMap {get; set;} in a controller or controller extension, you can access the value of a map in Visualforce using []. <apex:repeat var="key" value="{!mapKeysList}"> <apex:outputText value="{!...


3

Personally, I would suggest that the solution is to be aware of the pitfalls of changing the Developer/API name of anything on the platform, and then not to do it. Change the label by all means, but not the API name, as only problems will ensue. There are plenty of examples where Salesforce themselves have changes the name of something (Wave -> Einstein ...


3

You can't add store an Object in an Account, nor a List of Object in a List of Account. If, and only if, you're sure it's the correct type, you can "cast" to override: accList.addAll((List<Account>)objList); If the type is invalid at runtime, you'll get a TypeException. You note that sometimes your method will return a Boolean, so this would ...


3

You'd start with a list of lists: List<List<sObject>> allLists = new List<List<sObject>> { Alist, Blist, Clist }; for(List<sObject> xx: allLists) { doTheThing(xx); } You can also do that inline: for(List<sObject> xx: new List<List<sObject>> { Alist, Blist, Clist }) { doTheThing(xx); }


3

The easiest is to create a Set<Object[]>, something like the following: Set<Object[]> alreadySeen = new Set<Object[]>(); List<Schedules__c> uniqueSchedules = new List<Schedules__c>(); for (Schedules__c schedules : SchedulesToProcess) { Object[] key = new Object[]{ schedules.Month__c, schedules.Year__c }; if (!...


3

The key problem here is that your types are wrong throughout your code. It's definitely confusing, but if I can be very direct: if you don't feel completely comfortable with your understanding of the Apex type system, you're not going to be successful writing this type of code. Here's some key identities to keep in mind: A JSON list deserializes to a List&...


3

A map always has unique key values. Where you have multiple objects that could share the same key, you must make the map's values allow for this. For example, here I would make your Map<string,object> FinalMap actually Map<string,List<Object>> finalMap. Now you would populate it thus: for (Object obj : arr) { List<Object> entries ...


3

Iterate GroupMember records and group UserOrGroupId by unique Group.DeveloperName List<GroupMember> groupMemebrs = [ SELECT Id, GroupId, Group.DeveloperName, UserOrGroupId FROM GroupMember LIMIT 50000 ]; Map<String, List<Id>> groupMemebersByGroupDeveloperName = new Map<String, List<Id>>(); for(GroupMember ...


3

Looks like your syntax is the issue from what you've shared. Nested collections like a List of Lists are possible within Apex, but it would be defined like this: List<List<Contact>> or even something like List<List<Set<Integer>>>. Your SOSL query will return a List<List<SObject>>. I would recommend assigning your ...


3

acc.Contacts will return all Contacts related to the Account if you query for them first. (That is assuming that there are Contacts associated to the Account - if there are no related Contacts, then obviously any attempt to query for them or reference them will not show anything.) If you change your first line to: Account acc = [SELECT ID, NAME, (SELECT Id ...


2

Map<String, Object> fieldMapLevel_0 = (Map<String, Object>)fieldMap.get('Accts'); The value of the key Accts in your JSON is a List, not a Map: String jsonPayLoad = '{"Accts":[{"Name":"ABC","Exp":25,"Languages":[{"Name":"Apex","version": []},{"Name":&...


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


2

isBlank can't be used in a SOQL query. You should do something like: List<Order> orderList = [SELECT Id FROM Order WHERE CreatedDate = TODAY AND Submitted_Date_Time__c != NULL ];


2

Yes, you can. The generic sObject can hold any type of database record, such as: sObject[] results = new sObject[0]; results.addAll([SELECT Title FROM ContentDocument]); results.addAll([SELECT Subject FROM Task]); results.addAll([SELECT Subject FROM Event]); results.addAll([SELECT Subject From EmailMessage]); results.addAll([SELECT Title FROM Note]); If you ...


2

There is no simple one-line method (as in JavaScript, where we can e.g. Array.prototype.flat), its most simple form would be: List<Contact> allContacts = new List<Contact>(); for(List<Contact> contacts: accountWithContacts.values()) { allContacts.addAll(contacts); }


2

You're passing oName to the wrapper constructor, but you are not storing it, so it will be lost. Moreover there is no oName field on Task, Event and ContentDocumentLink, that's why it doesn't compile due to "Variable does not exist" error. If you define the properties you need in your wrapper class, instead of relying on SObjects, you can remove ...


2

To get the value of a field dynamically you should do something like this: parameter_value = temp.get(parameterList.get(i)); which would look like parameter_value = temp.get('field1'); This is assuming temp is an object which you queried previously. You will likely have to cast these values to make them consistent for the map. Like: String parameter_value =...


2

Let's simplify this code a bit // Step 1: get account record type Account accRecTypeName = [SELECT Id, RecordType.DeveloperName FROM Account WHERE Id = :accountId]; if(accRecTypeName.RecordType?.DeveloperName != 'Patient_Account') {return;} // Step 2: Create a new Patient Journey record Patient_Journey__c> patientJourney = new ...


2

When you called the Method2 From Method 1, then it returns the List. After that the same list you can pass to Method3. public static void method1() { // call method 2 that returns a list List<objname> theListReturnedFromMethod2 = method2(); // call method 3 and pass list retuned from method 2 method3(theListReturnedFromMethod2 ); }


2

Unfortunately, since the second string is looking for a partial text match, I don't see a way to avoid looping over each element to compare them. If you had a full text element match, the inner loop could be removed in favor of a Set contains() method. You should be careful of this "loop within a loop" approach. Unless you have tight control of ...


2

Objects are passed by reference, which means that two variables can refer to the same place in memory. You can read a much longer explanation here. As a simple example: Account a = new Account(Name='Demo'); Account b = a; b.Name = 'Demo 2'; System.debug(a.Name); // Demo 2 To fix this, you must create all new objects. For Lists, we have the deepClone method: ...


1

You clearly expected caseUpdate to be a Map<Id, Case>. Remove your line where you declare it and update the line where you assign it to: Map<Id, Case> caseUpdate = new Map<Id, Case>([/*query*/]); for (Id caseId : caseUpdate.keySet()) Alternatively (and preferably as it is simpler), just stick with List<Case> and remove any references ...


1

Can you check this setting in your org. You can configure whenever you want to attach files as links or actual data in Setup > Email > Email Attachments. From following options select last option to attach file as attachments. Always as links Include as attachment up to 3 MB or as links if more Include as attachment up to Salesforce email size limit ...


1

You need to iterate the list and if the record meets the condition then print it, or save for later use. List<OpportunityTeamMember> opListId = [SELECT OpportunityId, UserEmail__c, id FROM OpportunityTeamMember WHERE OpportunityId IN :opId ]; for (OpportunityTeamMember opportunityTeamMember : opListId) { if (**your condition**) { System....


1

Best bet to achieve this would be visualforce email templates with custom controller. In custom controller you will collect list of SObjects you need and in the template then you can iterate those and display them as you wish.


1

You already have one list, so the place more development work is likely is in your Wrapper class. For example: public class Wrapper implements Comparable { public Task at {get; set;} public Event be {get; set;} public Note cn {get; set;} public wrapper(Task a) { at = a; } public wrapper(Event b) { be = b; } ...


1

To have multiple SObject types in one list, you need to use list of sobjects. List<SObject> s = new List<SObject>{ new Event(), new Task(), new Note() };


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