You need to sign in to do that
Don't have an account?

Auto Update a field on a different object
I want to be able to create a workflow so that when one of our contacts is marked as inactive, a field in a related custom object is updated to an inactive status as well. I can create all the workflow apart from the field update as it will not allow me access to that objects field. There is a Master-Detail relationship.
Is there a way this can be done?
Thanks.
Justyn
Hi,
There is no way to update the Child records from Parent record using Workflow.
You have to Write the before update trigger on Contact object which will query and update the Child object records with the Inactive Status.
Thanks,
Kodisana
If you are asking is there a way to achieve this using workflow no thers is no way using workflow as you can not update any other field except the field on the object it self on which the field update is created.
But Yes there is a Way that is trigger. If you want I can help you in writting trigger for this.
Might be useful for you:
http://boards.developerforce.com/t5/General-Development/Change-a-field-on-record-update/td-p/301869
Hi
Thanks for the helpful link and comments. Any help on writing the trigger would be appreciated. The scenario is:
What would be trigger coding be?
Many thanks
Justyn
try this sample code,
trigger updateactive on contact (after update){
counselling_pratice__c[] cpstoupdate = new counselling_pratice__c[]{};
for(contact c : trigger.new ){
for(counselling_pratice__c cp: [ select id,name,Currently_Active__c from counselling_pratice__c wherecontact=:c.id]){
if ( c.membership_status__c != Active && cp.Currently_Active__c ){
cp.Currently_Active__c == false;
}
cpstoupdate.add(cp);
}
}
if(cpstoupdate.size()>0)
update cpstoupdate;
}
If you need any more info, let me know.
-VPrakash
Hi
Thanks for the help. I've copied and pasted the code in but there is a error message of:
Error: Compile Error: expecting right square bracket, found '=' at line 4 column 111
Any thoughts?
Justyn
What is the relationship field in counselling_pratice__c?, if it is contact__c thenmodify the code as follows:
trigger updateactive on contact (after update){
counselling_pratice__c[] cpstoupdate = new counselling_pratice__c[]{};
for(contact c : trigger.new ){
for(counselling_pratice__c cp: [ select id,name,Currently_Active__c from counselling_pratice__c where Contact__c =:c.id] ){
if ( c.membership_status__c != Active && cp.Currently_Active__c ){
cp.Currently_Active__c == false;
}
cpstoupdate.add(cp);
}
}
if(cpstoupdate.size()>0)
update cpstoupdate;
}
Hi
Thanks for the update. The relationship field on the Counselling_Practice__c is Member__c. I've amended the code, and also correct a typo in the Object name I realised that I'd original typed Counselling_Pratice__c not Counselling_Practice__c . The latest code therefore is:
}
trigger updateactive on contact (after update){
Counselling_Practice__c[] cpstoupdate = new Counselling_Practice__c[]{};
for(contact c : trigger.new ){
for(Counselling_Practice__c cp: [ select id,name,Currently_Active__c from Counselling_Practice__c where Member__c =:c.id] ){
if (c.Membership_Status__c != Active && cp.Currently_Active__c ){
cp.Currently_Active__c == false;
}
cpstoupdate.add(cp);
}
}
if(cpstoupdate.size()>0)
update cpstoupdate;
I now get a slightly different error message which is:
I can confirm that the value does exist. The field is a picklist which I don't know if that has an impact. The list of values in that field are:
Here is your trigger
I have covered bulk handling as well in this
My bad,
This should work,
trigger updateactive on contact (after update){
Counselling_Practice__c[] cpstoupdate = new Counselling_Practice__c[]{};
for(contact c : trigger.new ){
for(Counselling_Practice__c cp: [ select id,name,Currently_Active__c from Counselling_Practice__c where Member__c =:c.id] ){
if (c.Membership_Status__c != 'Active' && cp.Currently_Active__c ){
cp.Currently_Active__c == false;
}
cpstoupdate.add(cp);
}
}
if(cpstoupdate.size()>0)
update cpstoupdate;
}
Hi
Thanks for the code. I've copied and pasted by I get the following error:
Error: Compile Error: unexpected token: 'List' at line 11 column 0
I've also amended the Custom Object name as I'd originally given an incorrect name as I'd missed out a 'c' in practice.
The amended code is:
}
trigger updateCounsellingStatus on contact (after update)
{
Set<Id> setconIds = new Set<Id>();
for(contact c : trigger.new )
{
setconIds.add(c.id);
}
MAP<ID , List<counselling_practice__c>> mapCons = new Map<ID , List<counselling_practice__c>>();
List<counselling_practice__c> consList = [select Currently_Active__c from counselling_practice__c where Member__c =:c.id]
List<counselling_practice__c> tempList = new List<counselling_practice__c>();
for(counselling_practice__c consObj : consList)
{
if(mapCons.ContainsKey(consObj.Member__c))
{
tempList = mapCons.get(consObj.Member__c);
}
else
{
tempList = new List<counselling_practice__c>();
}
tempList.add(consObj);
mapCons.put(consObj.Member__c , tempList);
}
for(contact c : trigger.new )
{
if(mapCons.ContainsKey(c.id))
{
for(counselling_practice__c conObj : mapCons.get(c.id))
{
if ( (c.membership_status__c == 'Lapsed' || c.membership_status__c == 'Deceased') && trigger.oldMap.get(c.id).membership_status__c == 'Active' && conObj.Currently_Active__c )
{
conObj.Currently_Active__c = false;
}
cpstoupdate.add(conObj);
}
}
}
if(cpstoupdate.size()>0)
update cpstoupdate;
Hi VPrakash
I get the following error now with your amended code:
Use cp.Currently_Active__c =false; instead of cp.Currently_Active__c == false;
Did you tried my code , that covers bulk handling as well. And if you will not do bulk handling then your trigger will fail with bulk data. Just try that one.
Hi Shashikant
I did try your code thanks. I got the following error when I tried to save the file:
Error: Compile Error: unexpected token: 'List' at line 11 column 0
Any thoughts?
Regards
Justyn
Hi VPrakash
Thanks for the amendment. The code works. Have you any thoughts on the Test code so that it can be deployed to the production unit?
Regards
Justyn