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

DML statements Query
Hi all,
in which triggers, we cant use DML Statments.could anyone please explain me
in which triggers, we cant use DML Statments.could anyone please explain me
You need to sign in to do that
Don't have an account?
May I suggest you please check with below links from the community forums with a similar discussion which might help.
- https://developer.salesforce.com/forums/?id=906F0000000fyY5IAI
- https://developer.salesforce.com/forums/?id=906F0000000Az72IAC
- https://developer.salesforce.com/forums/?id=906F00000008vvfIAA
Please let us know if this helps.Thanks,
Nagendra
1. in BEFORE TRIGGER you need not to use DML operations.
because it will trigger before the data save and automatically DML operation happens next so you need not specify explicitly.
2. in AFTER TRIGGER you need to specify DML operation because it will trigger after data save and you need to apply your business logic and save the data again so you need DML operation here.
I am getting below Error. When I have wrriten below code
trigger AccountAddressTrigger on Account (before insert,before update) {
for(Account a:Trigger.new)
{
if(Trigger.isInsert)
{
if(a.Match_Billing_Address__c==True)
{
a.ShippingPostalCode=a.BillingPostalCode;
}
update a;
}
else
{
a.ShippingPostalCode=a.BillingPostalCode;
insert a;
}
}
}
/////// iF I remove any of the above statements Update a or Insert a...its working fine ..No errors am getting, but when I have both statements am getting below Error. Could you please explain me why it so?
Challenge Not yet complete... here's what's wrong:
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountAddressTrigger: execution of BeforeInsert caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old Trigger.AccountAddressTrigger: line 11, column 1: []