Skip to main content
Hello Guys

I have a trigger below that is partially updating the record, may anyone assist me in figuring out what is causing the second update to Fail. 

It updates Ship_From_Zone1__c  and Hub_Ship_From_Zone__c  but not the shipto and the hubshipto Ids

trigger PopulateRegion on Shipment_Order__c (before insert, before update) {

for(Shipment_Order__c shipmentorder : Trigger.new) {

List<Ship_To__c> shipto= new List<Ship_To__c>();

shipto = [Select Id from Ship_To__c WHERE Ship_To__c.Ship_From_Zone__c = :shipmentorder.Ship_From_Zone1__c AND Ship_To__c.Name =:shipmentorder.Ship_From_Country__c ORDER BY Id LIMIT 1];

List<Ship_To__c> hubshipto = new List<Ship_To__c>();

hubshipto = [Select Id from Ship_To__c WHERE Ship_To__c.Ship_From_Zone__c = :shipmentorder.Hub_Ship_From_Zone__c AND Ship_To__c.Name =:shipmentorder.Hub_Country__c ORDER BY Id LIMIT 1];

If(shipmentorder.Hub_Shipment_Formula__c == False && shipmentorder.Ship_From_Country__c != null && shipto.size() > 0 ){

string region = Country_Region_List__c.getInstance(shipmentorder.Ship_From_Country__c).Region__c;

shipmentorder.Ship_From_Zone1__c = region;

shipmentorder.Ship_to__c = shipto[0].Id;

}

If(shipmentorder.Hub_Shipment_Formula__c == True && shipmentorder.Hub_Country__c != null && shipto.size() > 0) {

string region = Country_Region_List__c.getInstance(shipmentorder.Ship_From_Country__c).Region__c;

string hubregion = Country_Region_List__c.getInstance(shipmentorder.Hub_Country__c).Region__c;

shipmentorder.Ship_From_Zone1__c = region;

shipmentorder.Hub_Ship_From_Zone__c = hubregion;

shipmentorder.Ship_to__c = hubshipto[0].Id ;

shipmentorder.From_Hub_Destination__c = shipto[0].Id ;

}

}

}

 
4 respostas
  1. 19 de out. de 2017, 14:47
    Please change the line 29 to List<Ship_To__c> hubshipto = Database.query(queryString + whereConditionHub);
0/9000