You need to sign in to do that
Don't have an account?
![D ROKA D ROKA](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Help with trigger
Below is the code for the trigger but i am getting error
"Error: Compile Error: expecting a semi-colon, found 'Idval' at line 2 column 8"
trigger onUpdateOfObjectB on Object_B__c (Before insert,before update) {
set Idval=new set();
set Ids=new set();
for (Object_B__c ct: trigger.new)
{
idval.add(ct.Lookup_Object_A__c);
ids.add(ct.Id);
}
List Aclist=[select Id,Priority__c from Object_A__c where Id =:Idval];
List Bclist=new List();
List Cclist=[select Lookup_Object_B__c,Status__c from Object_C__c where Lookup_Object_B__c=:ids];
for(Object_A__c ac: Aclist)
{
for(Object_C__c cc: Cclist)
{
if(ac.Priority__c=='P1' && cc.Status__c=='Closed')
{
System.debug('SDFGsdf sdfsdf');
cc.addError('Your custom error message');
}
}
}
}
Can anybody help me its urgent...
you need to define the object inside the set. e.g.:
Set<String> strSet=new Set<String>();
Set<Account> accSet=new Set<Account>();
How about trying key value pair from Map instead?
trigger onUpdateOfObjectB on Object_B__c (Before insert,before update) {
map<id,string> newMap = newMap<id, string>;
for (Object_B__c ct: trigger.new)
{
newMap.put(ct.id,ct.lookup_Object_A__c);
}
List Aclist=[select Id,Priority__c from Object_A__c where Id =:newMap.keyset()];
List Cclist=[select Lookup_Object_B__c,Status__c from Object_C__c where Lookup_Object_B__c=:newMap.values()];
for(Object_A__c ac: Aclist)
{
for(Object_C__c cc: Cclist)
{
if(ac.Priority__c=='P1' && cc.Status__c=='Closed')
{
System.debug('SDFGsdf sdfsdf');
cc.addError('Your custom error message');
}
}
}
}
You didn't specify a type for your Set objects or List objects. Collections require a data specialization in order to operate. Regardless, your code is still not optimized, as you're using an unfiltered loop inside an unfiltered loop. Instead, you're looking to use maps:
Some other observations I found while fixing the code: