function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AnidevAnidev 

Comparing Lists

Hi All,

 

Could anyone please help with the error below:

 

trigger createminutes on Event (after insert, after update)
{
List<Event> elist = [select id,Meeting_Unique_No__c from Event where Meeting_Status__c='Closed'];
List<Minute__c> milist = [select id, Meeting_Unique_No__c from Minute__c];
Set<String> eSet = new Set<String>();
Set<String> miSet = new Set<String>();

//For(string s1:elist)
{
//eSet.put(s1);    
}
//For(string s2:milist)
{
//miSet.put(s2);
}
If(miSet.containsall(eSet))
{
System.debug('');
}
else
{
System.debug('Please create notes');
}
}

 

Many thanks in advance.

 

Regards,

Anidev

Doublehead SoftwareDoublehead Software
What is the actually error being reported?
davidjgriffdavidjgriff

My guess is that it has something to do with the fact that you are trying to iterate over a list of Events but using a String for loop (s1)...


I assume you'll probably want to do:

 

for(Event e : elist){
    eSet.put(e.Meeting_Unique_No__c);
}
for(Minute__c mi : miList){
    miSet.put(mi.Meeting_Unique_No__c);
}

 

AnidevAnidev

 

Error: Compile Error: Method does not exist or incorrect signature: [SET<String>].put(String) at line 10 column 1

 

Code:

 

trigger createminutes on Event (after insert, after update)
{
List<Event> elist = [select id,Meeting_Unique_No__c from Event where Meeting_Status__c='Closed'];
List<Minute__c> milist = [select id, Meeting_Unique_No__c from Minute__c];
Set<String> eSet = new Set<String>();
Set<String> miSet = new Set<String>();

For(Event e:elist)
{
eSet.put(e.Meeting_Unique_No__c);    
}
For(Minute__c mi:milist)
{
miSet.put(mi.Meeting_Unique_No__c);
}
If(miSet.containsall(eSet))
{
System.debug('');
}
else
{
System.debug('Please create Notes');
}
}


--------------------------------------------------------------------------------------------

Hi David,

Thanks so much for replying.

I have attached the screenshot above, it's still not working.

----------------------------------------------------------------------------------------------

Hello 'Doublehead Software',

Thanks to you as well.

Reply to your question too.

Regards,

Anidev

 

AnidevAnidev

Hi All,

 

The following code is saving but the desired output is not showing:

 

trigger createminutes on Event (before insert,before update,after insert, after update)
{
List<Event> elist = [select id,Meeting_Unique_No__c from Event where Meeting_Status__c='Closed'];
List<Minute__c> milist = [select id, Meeting_Unique_No__c from Minute__c];
Set<String> eSet = new Set<String>();
Set<String> miSet = new Set<String>();

For(Event e:elist)
{
eSet.add(e.Meeting_Unique_No__c);    
}
For(Minute__c mi:milist)
{
miSet.add(mi.Meeting_Unique_No__c);
}
If(eSet.containsall(miSet))
{
system.debug('Thanks for creating Notes');
}
else
{
system.debug('Please create Notes');
}
}

 

Notes:

 

What has to happen is that on saving a record in event object, the above trigger should fire.

Each event has an unique ID - Meeting_Unique_No__c (datatype "auto number").

The same is used "Minute__c" object as well (datatype here is "text").

So when the trigger fires it lists all event records with the "Meeting_Unique_No__c"

Then it lists all minute_c records with "Meeting_Unique_No__c"

compares both the list, if they donot match, the error messages are displayed as shown above.

 

Problems:

 

1) So, now what is happening is, the error message is not being displayed, even though both lists donot match

2) This is a crude code as it is not bulkified and hence may easily hit governor limits(methinks, i may be wrong).

 

Kindly advice

 

Many thanks in advance.

 

Regards,

Anidev