2

Below is the trigger code but i am getting error:

Compile Error: unexpected token: 'List' at line 12 column 2

trigger onUpdateOfObjectB on Object_B__c(Before insert,before update) {

set<String> Idval=new set<String>();
set<Integer> Ids=new set<Integer>();

  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');
         }
      }
   }
}

Please help me to resolve t

3
  • 2
    It would greatly help if you specify the error you are getting. – Samuel De Rycke Aug 21 '13 at 12:00
  • Compile Error: unexpected token: 'List' at line 12 column 2 – user1603042 Aug 21 '13 at 12:23
  • Ah, I overlooked that one, have added it to my answer below. – Samuel De Rycke Aug 21 '13 at 12:24
3

When performing SOQL and you want to filter on a list of values in the where clause, use the IN keyword. Additionally, use the ID type when you're working with IDs.

Lists and other collections are hard typed and need to be initialized for a specific type. Have a look at the documentation

set<ID> Idval=new set<ID>();//collection
set<ID> Ids=new set<ID>();

  for (Object_B__c ct: trigger.new)
 {
    idval.add(ct.Lookup_Object_A__c);
    ids.add(ct.Id);
 }

  List<Object_A__c> Aclist=[select Id,Priority__c from Object_A__c where Id IN :Idval];

  //List<??> Bclist=new List()<??>; //List<TYPE>(); 
  List<Object_C__c> Cclist=[select Lookup_Object_B__c,Status__c from Object_C__c where Lookup_Object_B__c IN :ids];

It believe this should solve your error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.