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
TejTej 

how to update a field in master object based on detail objects status.

i have a master detail realtionship between two objects,

 

is it posible to update a checkbox in master object if all the detail objects are in certain status???

 

Please help.

 

TrimbleAgTrimbleAg

Yes, a cross object formula with a workflow assocaited to the results on the master.

 

PB

Jake GmerekJake Gmerek

I do not believe that a cross object workflow will work in this case since you want to check ALL detail records.  You may have to use a trigger.

TrimbleAgTrimbleAg

Yea your right, I didnt think about the ALL statement,

 

PB

QLearnQLearn

Account a = new Account(Name = 'Acme', Checkbox__c=true);

insert a;

// Inserting the record automatically assigns a

// value to its ID field

Contact c = new Contact(LastName = 'Weissman');

c.AccountId = a.Id;

// The new contact now points at the new account

insert c;

// A SOQL query accesses data for the inserted contact,

// including a populated c.account field

c = [SELECT Account.Name, Account.checkbox__c FROM Contact WHERE Id = :c.Id];

// Now fields in both records can be changed through the contact

c.Account.checkbox__c = false;

c.LastName = 'Roth';

// To update the database, the two types of records must be

// updated separately

update c; 

// This only changes the contact's last name

update c.Account;

// This updates the account checkbox__c

 

Hope this Helps you.  If I solved your issue, please mark it so.