function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Developer99Developer99 

Update Child Field once Parent Field is Updated

have 2 objects name quote,quotelineitems here both are related with master-detail relationship, i wrote a trigger on quote(parent). whenever any field is changed in quote automatically in quoteline item i have a field Isupdated change to false.Intinally while inserting records Isupdate field is True, whenever i update any field in quote then it have to change to false, i am getting the issuse while inserting records automatically Isupdated field is taking false, without updating anything in quote. My trigger:


trigger quotetrg on Quote__c (after update)
{
    list<Quote__c> s1 = new list<Quote__c>();
    s1 = [select City__c from  Quote__c];

    list<Quote_Item__c> f1 = new list<Quote_Item__c>();
    f1 = [select Updated_del__c from Quote_Item__c];

    for(Quote_Item__c f :f1)
    {
        for(Quote__c s : Trigger.old)
        {
            f.Updated_del__c = s.City__c;

            f.Updated_del__c = 'Krish';
            update f;
        }
    }
}
Ramu_SFDCRamu_SFDC
Hi, This trigger is written on Quote__c (which i assume is parent) and will fire only when the quote item is edited. As you are saying that the quote_item__c field is changing to false at the time of insertion, I guess there is another trigger/(s) which is written for Before or After insert on Quote_item__c.
Developer99Developer99
@Ramu ,

           there is workflow rule is there on Quote_item_c which will fire when i edit the records in Quote_item_c.
Ramu_SFDCRamu_SFDC
There you go !! So based on the order of execution, first the Before and After triggers are executed and then the workflow rules hence the workflow rule might be changing he field to False. Hope this helps.
Developer99Developer99
@Ramu

           that means shall i remove that W.F on child object shall i write the trigger..?? 
Ramu_SFDCRamu_SFDC
If the WF rule that you created is for the same purpose(i.e.., updating the checkbox field to false), I suggest that you deactivate it. 
Developer99Developer99
@ramu,

           As per my requriment i want to know when ever any changes in the Quot_item_c fields so that's why i created the workflow, is there any other way when ever i change any field in the Quote_item_c i want to change the Update__c which is in Quote_-iteM__c 
Ramu_SFDCRamu_SFDC
I assume you are looking for two conditions 1. You want the Update__c to be set to false when there is a change on Quote__c (parentobject).
2. Set the Update__c on Quote_item__c to True/False when there is any change on the same object (Quote_Item__c.)

The first condition will be met by the trigger you wrote on Quote__c.

However, regarding the workaround on Quote_item__c, even if you write a separate trigger on quote_item__c, if the changes on any of the fields on quote_item__c are effecting parent object fields(Quote__c fields) it will execute parent triggers as well. Review the order of execution at the link below for more information 
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_order_of_execution.htm