You need to sign in to do that
Don't have an account?
vikas vickyy
how do i write a update trigger when to count the records in object from another object when they are not related to each other
Hi i have a two custom objects one is employe__c and another one is comapny_report __c which doesnot have any relationship.
for employe__c i have a lookup relationship with Department__c
for Departement__c i have lookup relationship with Company__c
and for company_report__c i have a lookup relationship with Department__c and Company__c
comapny__c has only one record with ABC company
and there are three Departments in Department__c
Department 1
Department 2
Department 3
for the same company which has been selected from Parent Object Company
In employee__c object i have fields
EmpName;
Department which is selected from the parent object
Joining Date
In company_report__c i have fields
Name with autonumber;
Departement ---> lookup relation with Departement__c
company ---> lookup relation with company__c
Quarter
Employee Count
Year
My requirment is if i created a record in employe__c with name departement and joining date automatically record need to be created in the comapny_report__c
I can create it.
But when i create an another record in the emp object with name and same department and same Quarter which is between 01 Jan to 31 Mar 2019 in company_report__c this existing record which has been created earlier should be updated with the count 2 previosuly which is one
for employe__c i have a lookup relationship with Department__c
for Departement__c i have lookup relationship with Company__c
and for company_report__c i have a lookup relationship with Department__c and Company__c
comapny__c has only one record with ABC company
and there are three Departments in Department__c
Department 1
Department 2
Department 3
for the same company which has been selected from Parent Object Company
In employee__c object i have fields
EmpName;
Department which is selected from the parent object
Joining Date
In company_report__c i have fields
Name with autonumber;
Departement ---> lookup relation with Departement__c
company ---> lookup relation with company__c
Quarter
Employee Count
Year
My requirment is if i created a record in employe__c with name departement and joining date automatically record need to be created in the comapny_report__c
I can create it.
But when i create an another record in the emp object with name and same department and same Quarter which is between 01 Jan to 31 Mar 2019 in company_report__c this existing record which has been created earlier should be updated with the count 2 previosuly which is one
You need to create a trigger on employee__c which will perform all these scenario.
1) Search if any company_report__c record avaliable where company_report__r.department__c = employee__r.department__c and company_report__r.joining_date__c In employee__r.quarter.
2) If you get the existing record of company_report__c then just increase count to count++, if doesn`t exist create new company_report__c.
Note: Even you can perform this functionality using flow