function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
freddyloufreddylou 

almost figured out apex triggers - need help combining dataloader with trigger

okay on got this code to run without any governor errros - whenever i save a record with a hexadecimal it outputs the corresponding binary number and updates fields based on the binary.

 

the issue is when i do a apex data loader upsert - the hexadecimal numbers update - but in those cases the updating of the binary numbers and the updating of fields related to binary do not occur.

 

I then manually have to go into each contact edit it save it and then everything updates.

 

any suggestions how to fix this - tried update a; that didn't work or upsert a; at the end of my code.

 

trigger updateappsagain on Contact (before insert, before update) {

//contact[] a = trigger.new;

 List<contact> contacts = new List<contact>{};
 
   //Loop through all records in the Trigger.new collection
   for(Contact a: Trigger.new){


   
system.debug(a.clientparams__c.length());
 if (a.clientparams__c.length()==18)
 {
  string buildbinary='';
    Integer i = 2;
 
    integer count = 18;
   
    do  {
            
    if (a.clientparams__c.substring(i,i+1) == '0') {
    buildbinary=buildbinary+'0000';
    } if (a.clientparams__c.substring(i,i+1) == '1'){
    buildbinary=buildbinary+'0001';
    } if (a.clientparams__c.substring(i,i+1) == '2'){
    buildbinary=buildbinary+'0010';
    } if (a.clientparams__c.substring(i,i+1) == '3'){
    buildbinary=buildbinary+'0011';
    } if (a.clientparams__c.substring(i,i+1) == '4'){
    buildbinary=buildbinary+'0100';
    } if (a.clientparams__c.substring(i,i+1) == '5'){
    buildbinary=buildbinary+'0101';
    } if (a.clientparams__c.substring(i,i+1) == '6'){
    buildbinary=buildbinary+'0110';
    } if (a.clientparams__c.substring(i,i+1) == '7'){
        buildbinary=buildbinary+'0111';
    } if (a.clientparams__c.substring(i,i+1) == '8'){
    buildbinary=buildbinary+'1000';    } if
    (a.clientparams__c.substring(i,i+1) == '9'){
    buildbinary=buildbinary+'1001';
    } if (a.clientparams__c.substring(i,i+1) == 'A'){
    buildbinary=buildbinary+'1010';
      } if (a.clientparams__c.substring(i,i+1) == 'B'){
    buildbinary=buildbinary+'1011';
        } if (a.clientparams__c.substring(i,i+1) == 'C'){
    buildbinary=buildbinary+'1100';
        } if (a.clientparams__c.substring(i,i+1) == 'D'){
    buildbinary=buildbinary+'1101';
    } if (a.clientparams__c.substring(i,i+1) == 'E'){
    buildbinary=buildbinary+'1110';
    } if (a.clientparams__c.substring(i,i+1) == 'F'){
    buildbinary=buildbinary+'1111';    }
    i++;  system.debug(i);
    } while (i<count);
    integer s=64;
if (buildbinary.substring(s-3,s-2)=='1')  a.Basket_Trader_On__c=true;                           
else a.Basket_Trader_On__c=false;                           
if (buildbinary.substring(s-4,s-3)=='1')     a.Market_Maker_On__c=true;                             
else a.Market_Maker_On__c=false;                        
if (buildbinary.substring(s-5,s-4)=='1')    a.Spread_Trader_On__c=true;                           
else a.Spread_Trader_On__c=false;                           
if (buildbinary.substring(s-6,s-5)=='1')    a.Trade_Ripper_On__c=true;                            
else a.Trade_Ripper_On__c=false;                        
if (buildbinary.substring(s-7,s-6)=='1')    a.Time_Slicer_on__c=true;                             
else a.Time_Slicer_on__c=false;                         
if (buildbinary.substring(s-8,s-7)=='1')    a.Managed_Order_Admin_On__c=true;                             
else a.Managed_Order_Admin_On__c=false;                         
if (buildbinary.substring(s-9,s-8)=='1')    a.Exempt_from_short_locate_id_On__c=true;                             
else a.Exempt_from_short_locate_id_On__c=false;                         
if (buildbinary.substring(s-10,s-9)=='1')    a.Order_Ticket_On__c=true;                           
else a.Order_Ticket_On__c=false;                        
if (buildbinary.substring(s-11,s-10)=='1')    a.Wave_Grid_On__c=true;                             
else a.Wave_Grid_On__c=false;                           
if (buildbinary.substring(s-12,s-11)=='1')    a.News_Viewer_On__c=true;                           
else a.News_Viewer_On__c=false;                         

 
    
  
    a.testbinary__c = buildbinary;
   
    }
 }


 }

SurekaSureka

Hi,

 

The below trigger is a before insert/update trigger. So you don't have to use Update statement separately.

 

Since your logic is very long, I would recommend you to test it line by line..


Thanks

freddyloufreddylou

yes - with or without the update command it does the same thing so I if I elminated that it doesn't change anything.

 

using the apex data loader upserts records resets hex number - BUT the only way I can get the hex number converted to binary and the logic run if I goto each contact record one by one and edit and save the record which is ineffcient and clearly not the purpose.

 

I am not an expert on testing - just not sure why it works on a one-off basis but not work when I use the dataloader (upsert).

ScoobieScoobie

 


freddylou wrote:

yes - with or without the update command it does the same thing so I if I elminated that it doesn't change anything.

 

using the apex data loader upserts records resets hex number - BUT the only way I can get the hex number converted to binary and the logic run if I goto each contact record one by one and edit and save the record which is ineffcient and clearly not the purpose.

 

I am not an expert on testing - just not sure why it works on a one-off basis but not work when I use the dataloader (upsert).


If you are using upsert, what key are you matching on?