You need to sign in to do that
Don't have an account?
sagarshah
Trigger to match fields in another object
I have 2 custom objects
Timecard (pse__Timecard_Header__c)
Period (c2g__codaPeriod__c).
They don't have relationship.
Timecard fields:- Start date (pse__Start_Date__c), Close date (pse__CloseDate__c), Project (pse__Proj__c). Now here, inside project is one field Region (pse__Region__c).
Period fields:- Start date (c2g__StartDate__c), Close date (c2g__Closed__c), Region (c2g__Region__c ), status (checkbox).
If the status is checked and start date, close date and region are matching with the start date, close date and region of Timecard object then I want Timecard to be rejected.
I started with the following code but then get lost realising I don't have direct access to region inside project.
Timecard (pse__Timecard_Header__c)
Period (c2g__codaPeriod__c).
They don't have relationship.
Timecard fields:- Start date (pse__Start_Date__c), Close date (pse__CloseDate__c), Project (pse__Proj__c). Now here, inside project is one field Region (pse__Region__c).
Period fields:- Start date (c2g__StartDate__c), Close date (c2g__Closed__c), Region (c2g__Region__c ), status (checkbox).
If the status is checked and start date, close date and region are matching with the start date, close date and region of Timecard object then I want Timecard to be rejected.
I started with the following code but then get lost realising I don't have direct access to region inside project.
trigger TimecardRejection on pse__Timecard_Header__c (before update) { List tcdata = new List (); for(pse__Timecard_Header__c tc: Trigger.new) { tc.pse__Start_Date__c tc.pse__End_Date__c tcdata.add(tc); } }Any help would be appreciated. Thanks in advance.
you have to run the SOQL(Example below) to get the region on the Project (pse__Proj__c). You can use the relationship name (pse__Proj__r) to query.
Map<id,pse__Timecard_Header__c> timeCardMap = new Map<id,pse__Timecard_Header__c>([select id,pse__Proj__r.pse__Region__c from pse__Timecard_Header__c where id in :trigger.new]);