You need to sign in to do that
Don't have an account?
Harpreet Kaur 45
How to compare one filed of objects in list of objects and based on that only display the different values
for example , List<Class__c> c = [Select CurrentRates__c,.... from Class__c];
List<List<Class__c>> abc = new List<List<Class__c>>();
abc.add(c); // Suppose we added 3 Classes. Could be more
So, Based on CurrentRates field I want to compare all the classes in abc and and if CurrentRates field value is different then, I want to add all other fields. This what i have in my List of Objects. I ant to comapre for example Life current rates and combine them. if same only display onceand if different then display both in rows and add the values.
Please help
List<List<Class__c>> abc = new List<List<Class__c>>();
abc.add(c); // Suppose we added 3 Classes. Could be more
So, Based on CurrentRates field I want to compare all the classes in abc and and if CurrentRates field value is different then, I want to add all other fields. This what i have in my List of Objects. I ant to comapre for example Life current rates and combine them. if same only display onceand if different then display both in rows and add the values.
Please help
Still I dont see the need of having List<List<class__c>>structure when you use a single query to retrieve the records and all the records in same structure. Please clarify if my understanding has a gap.
If you have to compare one record with other records, here is the logic (Not complete code)
for(integer i = 0; i < ClassSize; i++)
for (integer j = i+1; j<ClassSize; j++) // J initial value is i+1 - this is to avoid duplicate checks
{
{
Hope this helps!
All Answers
Sorry your question is not very clear.
- do you have different objects (like Class A, Class B, Class C) with the same field name current_rates__C?
- what do you have to compare with?
can you please explain your requirement with some example?
if(ClassSize > 0) {
classInfo = new List<List<Class__c>>();
for(Integer i=0; i<ClassSize; i++)
{
List<Class__c> ClassRates = new List<Class__c>();
ClassRates = getPricingSheetInfo(i); // This fucntion has SQL query.It returns rates for each class.
if(ClassRates[0].Title_for_Rate_Sheet__c != NULL)
{
classInfo.add(ClassRates);
}
}
So in classInfo, I have 3 classes with rates. I want to compare only current rates for 3 classes. Suppose if current rates for 1st 2 classes are same then i want to display only i record and if current rates are different then display both and add the rates
Still I dont see the need of having List<List<class__c>>structure when you use a single query to retrieve the records and all the records in same structure. Please clarify if my understanding has a gap.
If you have to compare one record with other records, here is the logic (Not complete code)
for(integer i = 0; i < ClassSize; i++)
for (integer j = i+1; j<ClassSize; j++) // J initial value is i+1 - this is to avoid duplicate checks
{
{
Hope this helps!