You need to sign in to do that
Don't have an account?
Dilip Kulkarni 12
trigger for lookup relation
Employee object is in lookup relation with account,When we will create Event Record with Condition (Event Status = Closed) and once we click on save ,it should create Employee record automatically.What will be the trigger for it?
Trigger should be written on Event not account. Also you can get this done with process builder as well, If you prefer.
Please mark as best answer if the above helps ..!!!
All Answers
Hi Dilip,
May this will help you!
I have one question the event is in activities object, so should we write trigger on account or on event?
Trigger should be written on Event not account. Also you can get this done with process builder as well, If you prefer.
Please mark as best answer if the above helps ..!!!
I am facing error at line if (newEmployee.Event_Status = Closed) as Variable does not exist: Closed at line 9 column 40
Your trigger works. Can you please provide me test class for the same.
Please find the below test class
@IsTest
public class AutoCreateEmployee_Test
{
@IsTest static void Testmethod1() // This condition will cause the trigger to execute
{
Event ev = new Event (Event_Status = 'Closed', specify any required field with API names); // Also make sure Event_Status is a correct API name
list<Employee__c> em = [select id from Employee__c where createddate = today()]; // If there is any relation between employee and event them retrieve the employee record based on that relation . For example I am retrieving the employees created today.
system.asserEquals(em.size(),1);
}
@IsTest static void Testmethod2() // This condition will not cause the trigger to execute
{
Event ev = new Event (Event_Status = 'New', specify any required fields with API names);// Also make sure Event_Status is a correct API name
list<Employee__c> em = [select id from Employee__c where createddate = today()]; // If there is any relation between employee and event them retrieve the employee record based on that relation . For example I am retrieving the employees created today.
system.asserEquals(em.size(),0);
}
}
Please mark as best answer if the above helps ..!!!
Thanks. Can I use upto testmethod1 ? Also I am getting error 'unexpected syntax: 'mismatched input '(' expecting RSQUARE' at line 7 column 78' at line list<Employee__c> em = [select id from Employee__c where createddate = today()];
Please help.
@IsTest static void Testmethod1() // This condition will cause the trigger to execute
{
Event ev = new Event (Event_Status = 'Closed', specify any required field with API names); // Also make sure Event_Status is a correct API name
Insert ev;
// Test the results by retrieving employee
list<Employee__c> em = [select id from Employee__c where createddate = Today()]; // If there is any relation between employee and event them retrieve the employee record based on that relation . For example I am retrieving the employees created today.
system.assertEquals(em.size(),1);
}
I am getting error unexpected syntax: 'mismatched input '(' expecting RSQUARE' at line list<Employee__c> em = [select id from Employee__c where createddate = Today()];
Please help.
I saved and run the test for class, but it failed in test.What is required here?
Regards.
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [DurationInMinutes]: [DurationInMinutes]
Class.AutoCreateEmployee_Test.Testmethod1: line 8, column 1
Event ev = new Event (Event_Status = 'Closed'); // specify required fields and their values seperated by comma