I'm trying to write an update trigger on custom orders
object. There is a field Ship_To__c
in orders
object which is a text value. Another table SUBSCR_SYSTEMS__c
holds data LEGACY_CUST_NUM__c
that is same as Ship_To__c
. These two fields have no relation.
So I'm updating another field account__c
in orders__c
object by querying the same from SUBSCR_SYSTEMS__c
.
I checked the debug logs, I see that the before update event fires off but there is no change in account__c field in orders. What am I doing wrong?
This is what I have tried so far:
trigger updateAccountName on orders__c (before insert, before update) {
List<orders__c> ord = new List<orders__c> ();
List<SUBSCR_SYSTEMS__c> partnerAcc =new List<SUBSCR_SYSTEMS__c>();
for(orders__c go: Trigger.new)
{
if(go.Ship_To__c==''){
partnerAcc=[select Account__c from SUBSCR_SYSTEMS__c where LEGACY_CUST_NUM__c=: go.Ship_To__c];
go.account__c=partnerAcc[0].Account__c;
ord.add(go);
}
}
update ord;
}
Thanks.