You need to sign in to do that
Don't have an account?
LoveLace
Update a parent field once a child is inserted or updated - Custom Object
Hello there,
I have two custom object (Employee__c[Credit__c field] and Time_Off__c{Days__c field]) with a master detail relationship (Employee__c the parent , Time_Off__c the child) once o time off is added with a number of days (Days__c) this number of days must be retreived on the employee credit (Credit__c)
Here is the apex classe I developped in order to call it in a trigger before insert/update
List<Employee__c> emp = [SELECT Name, (SELECT Name FROM Times_Off__r) FROM Employee__c ];
List<Employee__c> upEmpl = new List<Employee__c>();
List<Time_Off__c> TO = new List<Time_Off__c>();
public void MAJSolde(){
//List<Employee__c> empl = [SELECT Credit__c FROM Employee__c WHERE ID := Id];
for (Employee__c em: emp){
for (Time_Off__c toof: Employee__c.Times_Off__r){
if(em.Credit__c == 0)
System.debug('No credit left');
}
else
em.Credit__c -= em.Times_Off__r.Days__c;
}
}
Where is the probleme
I have two custom object (Employee__c[Credit__c field] and Time_Off__c{Days__c field]) with a master detail relationship (Employee__c the parent , Time_Off__c the child) once o time off is added with a number of days (Days__c) this number of days must be retreived on the employee credit (Credit__c)
Here is the apex classe I developped in order to call it in a trigger before insert/update
List<Employee__c> emp = [SELECT Name, (SELECT Name FROM Times_Off__r) FROM Employee__c ];
List<Employee__c> upEmpl = new List<Employee__c>();
List<Time_Off__c> TO = new List<Time_Off__c>();
public void MAJSolde(){
//List<Employee__c> empl = [SELECT Credit__c FROM Employee__c WHERE ID := Id];
for (Employee__c em: emp){
for (Time_Off__c toof: Employee__c.Times_Off__r){
if(em.Credit__c == 0)
System.debug('No credit left');
}
else
em.Credit__c -= em.Times_Off__r.Days__c;
}
}
Where is the probleme
Ramu_SFDC
Hi, what is the problem you are seeing? If you are getting any error please provide the details of the error.
LoveLace
Here's the error Variable does not exist: Employee__c.Times_Off__r obviously the relationship Times_Off__r is unknown although it exist