Ad
How To Set Checkbox To True With Trigger When Related Objects Are Created
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.
Ad
Answer
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;
}
}
Ad
source: stackoverflow.com
Related Questions
- → Trigger a full height container when a minimum window width is reached
- → AJAX changing content of page does not work more than once?
- → Build a nested interval loop
- → Code appended with JQuery does not fire click event on input file
- → ReactJS Update ajax call to child component from onClick method from parent
- → Event listener assigned in a loop triggers all of them
- → jQuery javascript prevent continuous input change event triggers
- → Using ReactiveVars in Meteor/React
- → Recursion triggers the error "Maximum call stack size exceeded error"
- → How to detect which React component triggers onKeyUp event?
- → Proxy Getting RangeError
- → Preventing a browser from getting stuck on an AJAX request
- → PostgreSQL trigger won't inset audit value
Ad