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
Dhana t 1Dhana t 1 

How to Updating child value to its parent object when its checked ?

HI.. I have scenario that i have Master-detailed object , in child object when i checked the check box ,associated textfield will be hilated and then enter the value in textfield, the the value of textfield must be updated in parent field...

plz help me how to write code for this...
Gaurav KheterpalGaurav Kheterpal
This does not sound right.

In a M-D Relationship, there can be multiple ObjectX records related to a single Account record. This means if you have 2 ObjectX records, both have this textfield field and the Account only has a single textfield field. Systematically, Salesforce does not know which ObjectX record to pull the value from.

If that's the case, you should be using a lookup instead of a M-D relationship.

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others and improve the overall quality of Discussion Forums.

Gaurav Kheterpal
Certified Force.com Developer| Salesforce Mobile Evangelist| Developer Forums Moderator| Dreamforce Speaker
 
Dhana t 1Dhana t 1
 i have two objs one is master and 2nd one is child obj, My requirement is suppose opportunity is child obj ,in this i have one checkbox field and input text field(  ex: Status ). when checkbox is checked the status field must be hailted and then we should enter data in this field. then the value of the status field  must be updated in Status field of parent object.

i want it programatically either in apex or vf pages,  this requirement is in workflow like field update from child to parent...
 
David ZhuDavid Zhu
I would suggest add a trigger to implement this.

Trigger will be run after insert ,after update, and after delete.

This is the pseudo code:

for (childobj c : trigger.new)
{
    if (c.checkboxfield = true)
    {
        masterobj m = {select id from masterobj where id = :c.masterid}
        m.statusfield = ".......";
    }
}
Dhana t 1Dhana t 1
Thank you....!