0

enter image description here This is relation between two obj. I want to code a trigger which makes Enrolled field from false to true (unchecked to checked) when Student is created with College record.

K.Vodenicharov
  • 33
  • 1
  • 2
  • 7

1 Answers1

1

You don't need code for this. A formula field of type Checkbox and value !ISBLANK(College__c) would be enough.

Or workflow field update / flow / process builder with condition ISNEW() || ISCHANGED(College__c) and action Enrolled = College not equal to blank

If you're sure it needs code - this is decent start (but ideally you'd move logic to helper class, don't keep it straight in trigger)

trigger StudentTrigger on Student__c (before insert, before update){
    for(Student__c s : trigger.new){
        s.Enrolled__c = s.College__c != null;
    }
}
eyescream
  • 18,088
  • 2
  • 34
  • 46