You need to sign in to do that
Don't have an account?
Anil Kumar 1257
Apex trigger to update contact stage when the intervew stage equals chedule
trigger updatestageoncontact on Interview__c(after insert, after update){
list<Id> contIds = new list<Id>();
list<Contact> Contacts = new list<Contact>();
for(Interview__c inte:trigger.new){
contIds.add(inte.Candidate__c);
}
for(contact con:[select Id, Stage__c from contact where Id IN :contIds]){
for(Interview__c inter:trigger.new){
if(inter.Status__c=='Scheduled'){
con.Stage__c='Interview Scheduled';
Contacts.add(con);
}
}
}
update contacts;
}
How to write test class this trigger
list<Id> contIds = new list<Id>();
list<Contact> Contacts = new list<Contact>();
for(Interview__c inte:trigger.new){
contIds.add(inte.Candidate__c);
}
for(contact con:[select Id, Stage__c from contact where Id IN :contIds]){
for(Interview__c inter:trigger.new){
if(inter.Status__c=='Scheduled'){
con.Stage__c='Interview Scheduled';
Contacts.add(con);
}
}
}
update contacts;
}
How to write test class this trigger
One suggestion I might make is to modify trigger to such, just add in the check for if the interview status is scheduled to add that contact Id, just so you don't run through trigger.new twice. Just a best practice.
And here would be the test class
Please let me know if this resolves your issue and mark as best answer if it does!
Regards,
Tyler