You need to sign in to do that
Don't have an account?
Ramu kolli
Update parent object's, based on date field in child object
I was trying to pick up date field in child object(start date and end date). if the period falls in between October month then, i need to set parent object's checkbox to true. i wanted to perform this operation while inserting/updating records in child object. shall i use a trigger to perform this operation or simple class to be called from trigger. please help me
Update parent object's, based on date field in child object intwo ways
1.Using Trigger to update parent object value with child value
example of trigger:
public class UpdateParent
{
public static void updateChild(List<Case> newTrigger) {
Set<Case> caseUpdate = new Set<Case>();
for (Case c : newTrigger) {
if(Trigger.oldMap.get(c.Id).get('Datetime_Required__c') != c.Datetime_Required__c && c.ParentId != NULL) {
Case newCase = new Case( Datetime_Required__c = c.Datetime_Required__c, Id = c.ParentId );
caseUpdate.add(newCase);
}
}
List<Case> caseList = New List<Case>(caseUpdate);
update caseList;
}
}
2.using the Workflow Field Update parent object value with child value
Use this code and this fill solve your isssue.
if this is the solution of your problem so please choose this as the Best Anser.
Thanks
Gyani.
Slightly change in this trigger i miss one validation in the trigger so please modify the code with the following code.
Sorry for inconvience please you this code.
Thanks
Gyani.
regarding Workflow field update, I think we can't update parent based on the child values. because while we are creating workflow, if we select child object, we can make changes in child object only.
please clarify if i am wrong.
Thanks,
Ramu.
Workflow field updates can update fields on the parent object also, provided the parent has a master-detail (and not lookup) relationship with the child object.
In workflow we can update parent field from the child object but we can not make any changes in child from parent object. When you create workflow on the child object the you have the lookup object and you can select any field from the parent object.
Thanks
Gyani.
I was trying to execute the below code, but getting below mentioned error.
trigger UpdateCheckbox on Account_Child__c(after insert, after update) {
Map<ID, Account> parentOpps = new Map<ID, Account>();
List<Id> listIds = new List<Id>();
for (Account_Child__c childObj : Trigger.new) {
listIds.add(childObj.Account__c);
}
parentOpps = new Map<Id, Account>([SELECT id, Active__c, (SELECT ID,Start_date__c,End_date__c FROM Account_Child__r where Start_date__c<= this_month and End_date__c >= this_month) FROM Account WHERE ID IN :listIds]);
for (Account_Child__c ChildObject: Trigger.new){
Account myParentOpp = parentOpps.get(ChildObject.Account__c);
myParentOpp.Active__c = true ;
}
update parentOpps.values();
}
Error is :
Compile Error: Didn't understand relationship 'Account_Child__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 17 column 37
User Child relationship name here of your object and if you have any other doubt then show me your code.
Thanks
Gyani.