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

Bug in order trigger while updating
Hi All,
I have written a trigger on Order.
I am giving errors in two scenarios. I have one custom field Blocked__c in account. If I have blocked__c = Y, I dont want to create order.
This condition is not working properly.
This is my code. Please tell me where is bug
Please help me.
Line Number 13 is not working properly. Please suggest me changes.
Thanks in Advance
I have written a trigger on Order.
I am giving errors in two scenarios. I have one custom field Blocked__c in account. If I have blocked__c = Y, I dont want to create order.
This condition is not working properly.
This is my code. Please tell me where is bug
trigger orderTrigger on Order (before insert) { List<Order> ordLs = [Select Id, F1__c,Status,AccountId,Account.Blocked__c from Order where createdDate=today ]; for (Order ordNew : Trigger.new) { for(Order oa: ordLs) { if(oa.AccountId == ordNew.AccountId && oa.F1__c == ordNew.F1__c && oa.status == 'confirmed') { ordNew.AccountId.addError('Some messge'); } if(oa.Account.Blocked__c=='Y') { ordNew.AccountId.addError('Blocked'); } } } }
Please help me.
Line Number 13 is not working properly. Please suggest me changes.
Thanks in Advance
When I have Blocked__c != Y in Account, eventhough order is not creating
Even when I am creating new order, First it should check 'Blocked__c', then order should get create.
This is not working all the time
use below code let me inform if it helps you
thanks
Hi Piyush,
Its not working
If Blocked == 'Y' also order is creating
SFDC Coder 8
try ordNew.account.addError('Error Message'); //not accountID
Or throw an error on the record itself
try ordNew.addError('Error Message');
Please mark as best answer if this is the solution
Hi Anurags
Its not working. I dont know what is error
even if Blocked == 'Y' also order is creating