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
Glenn at MvistaGlenn at Mvista 

Using IF statement in trigger on specific object type

I am trying to create a trigger action based on the type of object as the Attachment.ParentId.  Specifically a custom object, Agreement, that always starts with a0g in the ID.

 

I want to write this type of logic:

 

trigger TRIGGNERNAME on Attachment (after insert) {

    for (Attachment a: trigger.new) {
        
        if(a.ParentId LIKE 'a0g%') {

              TRIGGER ACTION
             }
       }
}

 However, the LIKE option is not support and I cannot figure out what to substitute.   Any ideas?

Best Answer chosen by Admin (Salesforce Developers) 
SeAlVaSeAlVa

What about...

 

trigger TRIGGERNAME on Attachment (after insert) {
  for(Attachment a: trigger.new){
    if(((String)a.ParentId).startsWith('a0g')){
      // TRIGGER ACTION
    }
  }
}

 Regards

All Answers

SeAlVaSeAlVa

What about...

 

trigger TRIGGERNAME on Attachment (after insert) {
  for(Attachment a: trigger.new){
    if(((String)a.ParentId).startsWith('a0g')){
      // TRIGGER ACTION
    }
  }
}

 Regards

This was selected as the best answer
Glenn at MvistaGlenn at Mvista

That worked - thanks so much for the quick soution.