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

Update Parent field on update of child using Apex trigger
I'm writing my first Apex trigger and am running into an error which I am sure is simple to resolve but I can't seem to figure out.
Problem: I need to update a field (checkbox) on a parent (Account) record called PFlg when the child's Contract record field, CFlg, is checked.
My Solution: Since workflow field update doesn't allow multiple objects, I thought to use an Apex trigger.
trigger Flag on Contract (after update) {
sObject c = new Contract();
Contract d = (Contract)c;
if (trigger.new.CFlg__c.equals(TRUE) )
{
sObject s = new Account();
Account f = (Account)s;
f.PFlg__c = TRUE;
}
}
This results in an error:
Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:Contract at line 6 column 5
<SCRIPT type=text/javascript>function initSelectionInEditor() { setSelectionInEditor('Body', 118, 118) }setContentWindow(window);initSelectionInEditor();</SCRIPT>
Then I changed it to:
trigger UpdateDocExpressFlag on Contract (after update) {
sObject c = new Contract();
Contract d = (Contract)c;
Contract d = (Contract)c;
for (Contract ddd:Trigger.new)
{
{
if (ddd.CFlg__c(TRUE) )
{
sObject s = new Account();
Account f = (Account)s;
f.PFlg__c = TRUE;
}
}
}
which resulted in the following error:
Compile Error: Method does not exist or incorrect signature: [SOBJECT:Contract].CFlg__c(Boolean) at line 8 column 5
Any thoughts as to what I'm missing?
Message Edited by jyoti on 12-31-2007 07:34 AM
if (ddd.CFlg__c(TRUE) )
Also, you need to say which account your trying to update, and actually do the update of the accounts, and i'm not sure why you're doing the sojbect/concrete type casting stuff.
try something like this.
trigger UpdateDocExpressFlag on Contract (after update) {
List ac = new List();
for (Contract c:Trigger.new)
{
if (c.CFlg__c)
{
Account a = new Account();
a.PFlg__c = TRUE;
a.AccountId = c.AccountId;
ac.add(a);
}
}
update(ac);
}
By the way, I believe Account.Id is not an editable field in Apex. Is that not correct?
Message Edited by David Greenberg on 01-03-2008 07:17 PM
{
List<Account> acctList = new List<Account>();
if (contract.CRT_REC_DOCEXPRESS__c == TRUE ) {
// Set the DocExpress Flag to TRUE
a.Rec_d_By_DocExpress__c = TRUE;
update acctList;
}
}
Message Edited by jyoti on 01-09-2008 07:55 AM