You need to sign in to do that
Don't have an account?
silpa
Update Problem on Custom Object
Hi..all
I am new to salesforce, plz reply me...thanks in advance
I have the following scenario.....
I have a custom object which contains a check box field. Upon selection of this checkbox, i need to update two fields on the Account Object.
How can i do this?? any ideas. Currently we are using .NET
I thought of solving this by using Triggers. Any one plz give me an idea.........
Reply at your convienence. Thanks
Hi thankyou for your quick response.
I tried the following but still i am stuck.Can you plz tell me where i am going wrong. Thanks
trigger CustomObject1AccountUpdates on CustomObject__c (after insert, after update) {
CustomObject__c mc=Trigger.new;
if(mc.W_R==true) //Here i am checking the condition i.e,if the field in custom object = true
{
mc.C_A=true; //I am updating this checkbox fiels on the custom object (this is my requirement)
for( CustomObject__c o: newobjects ){
Account a = mc.A_P; // My Custom object contains Account record whose fields i need to update.
a.Status=XYZ; //updating field on Account
update a;
Account b = C_P_A_c;
b.A_C_P= XYZ;
update b;
}
}
else
{
mc.C_A=false;
for( CustomObject__c o: newobjects ){
Account a = mc.A_P;
a.Status=NO Value;
update a;
Account b =C_P_A_c;
b.A_C_P = No Value;
update b;
}
}
List<Account> acctList = new List<Account>();
for( Client_c o: newobjects ){
if(o.Wholesale_Relationship=='true')
{
o.Client_Authorization='true';
Account a = new Account( Id = o.Accounting_Provider);
a.Status='Wholesale';
Account b = new Account( Id = o.client_prospect_account);
b.Client_type = 'Wholesale';
acctList.add ( a );
acctList.add ( b );
else
{
o.Client_Authorization='false';
Account a = new Account( Id = o.Accounting_Provider);
a.Status='NoValue';
Account b = new Account( Id = o.client_prospect_account);
b.Client_type = 'NoValue';
acctList.add ( a );
acctList.add ( b );
}
update acctList;
}
}
You only have a single underscore between the name and the lowercase c. It should be Client__c instead of Client_c
hello i appriciate your idea. Plz reply at your convienence. Thanks
i tried placing two underscores. the trigger is getting compiled but i am getting runtime exception
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ClientAccountUpdates caused an unexpected exception, contact your administrator: ClientAccountUpdates: execution of AfterInsert caused by: System.Exception: Record is read-only: Trigger.ClientAccountUpdates: line 6, column 5
How did you resolve below error message, i am ending up with the same;
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger ClientAccountUpdates caused an unexpected exception, contact your administrator: ClientAccountUpdates: execution of AfterInsert caused by: System.Exception: Record is read-only: Trigger.ClientAccountUpdates: line 6, column 5
Hello Losintikfos
Please go through your code again. there might be some issue with your code. still if did not work paste your code. i will have a look.
You can use an object to change its own field values using trigger.new, but only in before triggers. In all after triggers,
trigger.new is not saved, so a runtime exception is thrown.