You need to sign in to do that
Don't have an account?
NJH-GD
Updating custom field on parent case when child case is created
Hello -
I am trying to figure out the best way to update a custom field on the parent level case everytime an Action Item (child case) is created with the Action Item's (child case) Contact Name. I tried to use Process Builder to do this, but to no avail. Any thoughts? Would a trigger do this? If so, what would it look like?
I am trying to figure out the best way to update a custom field on the parent level case everytime an Action Item (child case) is created with the Action Item's (child case) Contact Name. I tried to use Process Builder to do this, but to no avail. Any thoughts? Would a trigger do this? If so, what would it look like?
- Create a Trigger that triggers after the Action Item is inserted
- Within that Trigger I would get the related parent using SOQL
- Change the value of the parent object's custom field (remember the __c rule) with the Contact Name
- Call a DML command to update the parent record
Hope it helps!
You can achieve this via trigger. Just follw the steps descrribed by Thiago.
Let me know if you need any help in this.
I have a custom field "Contact" on "Case", and updating this field on Parent Case when a child case with "Contact" is created.
Please replacae this code with respective fields in your org.
//contact__c - your custom field on Case
//Parent_Case_c - lookup field on case, that links parent case to child case
Trigger updateParentCase on Case(after insert)
{
set<Id> setOfParentCaseIds = new Set<Id>();
Map<Id, Id> mapOfParnetCaseIdAndContact = new Map<Id, Id>();
for(Case objCs : Trigger.new)
{
System.debug('contact--'+objcs.Contact__c +'parent case--'+objcs.Parent_Case__c);
if(objcs.Contact__c != null && objcs.Parent_Case__c != null)
{
setOfParentCaseIds.add(objcs.Parent_Case__c);
//creating a map of parent case Id and associated contact
mapOfParnetCaseIdAndContact.put(objcs.Parent_Case__c, objcs.Contact__c);
}
}
System.debug('setofcaseids--'+setOfParentCaseIds +'map--'+mapOfParnetCaseIdAndContact);
if(setOfParentCaseIds != null && !setOfParentCaseIds.isEmpty())
{
List<Case> lstOfParentCases = new List<Case>();
//get list of parent cases
lstOfParentCases = [select Contact__c from Case where id in : setOfParentCaseIds];
System.debug('lstOfParentCases --'+lstOfParentCases );
if(lstOfParentCases != null && !lstOfParentCases.isEmpty())
{
for(Case objcs : lstOfParentCases)
{
System.debug('parent case--'+mapOfParnetCaseIdAndContact.get(objcs.id));
if(mapOfParnetCaseIdAndContact != null && mapOfParnetCaseIdAndContact.containsKey(objcs.id))
objcs.Contact__c = mapOfParnetCaseIdAndContact.get(objcs.id);
}
//update parent case
update lstOfParentCases;
}
}
}
Let me know if it works for your.