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
AlanLamAlanLam 

Apex Trigger Not Firing

Hi,
I have been working for the last 3 days on a couple of trigger and test classes in the Sandbox. Which I got 100% and was working all fine in Sandbox. Now when I move it too production it doesn't work. 
I did a refresh of the sandbox before moving it so the fields / val rules are the same. 
I have turned on the debug logs (I am no expert) but can not even see them firing. 
I tried to edit the code in sandbox by just removing white space in case thats why it wasn't working and now it is isn't working in the sandbox either. 
Even when I put the original code back. 

Can any help?

 

trigger cloneElecAMsignOff on Electricity_Meter__c (before update) {


     List<Electricity_Meter__c> myList = new List<Electricity_Meter__c>();
      

     for(Electricity_Meter__c a: trigger.new) {

        // insert Elec meter if Deal Done
        if (
        a.Account_Manager_Sign_Off_Date_Time__c != Null &&
        a.Clone_Date_Time_Stamp__c == Null && 
        (
        a.Deal_Done_Not__c == 'Deal Done (Existing client / Existing meter)' ||
        a.Deal_Done_Not__c == 'Deal Done (New Meter, New Client)' || 
        a.Deal_Done_Not__c == 'Deal Done (New Meter, Exisiting Client)')) {
        
        Electricity_Meter__c b = new Electricity_Meter__c();                
        b.Name = a.Name; 
        b.Site_name__c = a.Site_name__c;
        b.Contract_arranged_under_the_name_of__c = a.Winning_Contract_Arranged_Under_Name_of__c;
        b.Account__c = a.Account__c; 
        b.Linked_Basket__c = a.Linked_Basket__c;
        b.Linked_Monitor_Line__c = a.Linked_Monitor_Line__c;
        b.Current_Supplier__c = a.Winning_Supplier__c;
        b.Previous_Supplier__c = a.Current_Supplier__c;
        b.Meter_Status__c = '(2) Active (Not yet live)';
        b.COT_Disc_Deenerg_Date__c = a.COT_Disc_Deenerg_Date__c;       
        b.Auto_Manual_Term__c = a.Auto_Manual_Term__c;
              
        b.Linked_Affiliate_1__c = a.Linked_Affiliate_1__c;    
        b.Aff_1_Profit_Split__c = a.Aff_1_Profit_Split__c;
        b.Linked_Affiliate_2__c = a.Linked_Affiliate_2__c;    
        b.Aff_2_Profit_Split__c = a.Aff_2_Profit_Split__c;        
        b.Linked_Affiliate_3__c = a.Linked_Affiliate_3__c;    
        b.Aff_3_Profit_Split__c = a.Aff_3_Profit_Split__c;
        
        b.Site_Address_New__c = a.Site_Address_New__c;
        b.Site_Postcode__c = a.Site_Postcode__c;
        b.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c = a.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c;
        b.Billing_Address_New__c = a.Billing_Address_New__c;
        b.Billing_Postcode__c = a.Billing_Postcode__c;
        b.Number_of_employees__c = a.Number_of_employees__c;
        b.Annual_turnover_Euros__c = a.Annual_turnover_Euros__c;
        
        b.Profile_Class__c = a.Profile_Class__c;
        b.MTC_LLF__c = a.MTC_LLF__c;
        b.Meter_Details__c = a.Meter_Details__c; 
        b.MOP_CED__c = a.MOP_CED__c;
        b.Voltage_HV_LV_LVS__c = a.Voltage_HV_LV_LVS__c;
        
        b.Contract_start_date__c = a.Winning_Contract_Start_Date__c;
        b.Contract_expiry__c = a.Winning_Contract_End_Date__c;
        b.Payment_Method__c = a.Payment_Method__c;
        b.DD_Type__c = a.DD_Type__c;
        b.VAT__c = a.VAT__c;
        b.Monthly_Quarterly_Billing__c = a.Monthly_Quarterly_Billing__c;
        b.Copy_of_the_bills__c = a.Copy_of_the_bills__c;
        b.AQ__c = a.Winning_Supply_AQ__c;
        b.Total_KVA__c = a.Total_KVA__c; 
        b.Commission_p__c = a.Winning_Commision_p_kwh__c;
        b.Commission_per_year__c = a.Winning_Commission_year__c;
        b.Commission_Percent__c = a.Winning_Commission_Contract__c;  
        myList.add(b);  
        
        }


               
        // insert Elec meter if Deal Not Done
        else if (a.Account_Manager_Sign_Off_Date_Time__c != Null && 
        a.Clone_Date_Time_Stamp__c == Null && 
        (
        a.Deal_Done_Not__c == 'Deal not done / Not responding - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Not responding - Client lost' ||
        a.Deal_Done_Not__c == 'Deal not done / Went direct with supplier - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Went direct with supplier - Client lost' ||
        a.Deal_Done_Not__c == 'Deal not done / Went with another consultant - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Went with another consultant - Client lost' ||
        a.Deal_Done_Not__c == 'Deal not done / Meter removed - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Meter removed - Client lost')) {
        
        Electricity_Meter__c c = new Electricity_Meter__c();                
        c.Name = a.Name; 
        c.Site_name__c = a.Site_name__c;
        c.Contract_arranged_under_the_name_of__c = a.Winning_Contract_Arranged_Under_Name_of__c; 
        c.Account__c = a.Account__c; 
        c.Linked_Basket__c = a.Linked_Basket__c;
        c.Linked_Monitor_Line__c = a.Linked_Monitor_Line__c;
        c.Current_Supplier__c = a.Winning_Supplier__c;
        c.Previous_Supplier__c = a.Current_Supplier__c;
        c.Meter_Status__c = '(5) Active';
        c.COT_Disc_Deenerg_Date__c = a.COT_Disc_Deenerg_Date__c;        
        c.Auto_Manual_Term__c = a.Auto_Manual_Term__c;
              
        c.Linked_Affiliate_1__c = a.Linked_Affiliate_1__c;    
        c.Aff_1_Profit_Split__c = a.Aff_1_Profit_Split__c;
        c.Linked_Affiliate_2__c = a.Linked_Affiliate_2__c;    
        c.Aff_2_Profit_Split__c = a.Aff_2_Profit_Split__c;        
        c.Linked_Affiliate_3__c = a.Linked_Affiliate_3__c;    
        c.Aff_3_Profit_Split__c = a.Aff_3_Profit_Split__c;
        
        c.Site_Address_New__c = a.Site_Address_New__c;
        c.Site_Postcode__c = a.Site_Postcode__c;
        c.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c = a.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c;
        c.Billing_Address_New__c = a.Billing_Address_New__c;
        c.Billing_Postcode__c = a.Billing_Postcode__c;
        c.Number_of_employees__c = a.Number_of_employees__c;
        c.Annual_turnover_Euros__c = a.Annual_turnover_Euros__c;
        
        c.Profile_Class__c = a.Profile_Class__c;
        c.MTC_LLF__c = a.MTC_LLF__c;
        c.Meter_Details__c = a.Meter_Details__c; 
        c.MOP_CED__c = a.MOP_CED__c;
        c.Voltage_HV_LV_LVS__c = a.Voltage_HV_LV_LVS__c;
        
        c.Contract_start_date__c = a.Winning_Contract_Start_Date__c;
        c.Contract_expiry__c = a.Winning_Contract_End_Date__c;
        c.Payment_Method__c = a.Payment_Method__c;
        c.DD_Type__c = a.DD_Type__c;
        c.VAT__c = a.VAT__c;
        c.Monthly_Quarterly_Billing__c = a.Monthly_Quarterly_Billing__c;
        c.Copy_of_the_bills__c = a.Copy_of_the_bills__c;
        c.AQ__c = a.Winning_Supply_AQ__c;
        c.Total_KVA__c = a.Total_KVA__c; 
        c.Commission_p__c = a.Winning_Commision_p_kwh__c;
        c.Commission_per_year__c = a.Winning_Commission_year__c;
        c.Commission_Percent__c = a.Winning_Commission_Contract__c;
        myList.add(c);           
        
        }

   

        
    }
       

        
        
}
Best Answer chosen by Admin (Salesforce Developers) 
vishal@forcevishal@force

I think, based on certain conditions you are only creating more Electricity_Meter__c records (the goal here).

 

However, if we see the code, the new object instances you're creating inside the conditional loops (the if statements), you are simply adding them to a list : Refer 

 

 myList.add(b);  and  myList.add(c);

 

After that, nothing is done on myList. Maybe you'll want to insert them?

 

if(myList.size() > 0){

     insert myList;

}

 

All Answers

MartinHaagenMartinHaagen

Hi Alan,

 

Make sure the triger / triggers are active. This can be done in two ways 1) look in to .meta file if you are using Eclipse 2) under setup > Develop> APEX Triggers -find the trigger and make sure the status is set to active. 

 

AlanLamAlanLam

Hi Martin,

 

Thanks for the reply. They are both set to active. Really odd.

 

cloneElecAMsignOff 

 
  27.0Active6,254100% (91/91) Not Checked
  cloneGasAMsignOff 
 
27.0Active5,818100% (81/81) 

LakshmanLakshman

Try running the test class for the respective trigger(s) again and let us know if that helps.

 

Regards,

Lakshman

Vinit_KumarVinit_Kumar

Alan

 

You trigger is running on Update event ,also you are checking some condition.Pleae make sure you fulfill it to invoke the Trigger.

MartinHaagenMartinHaagen

Hi Alan,

 

I was also thinking along the same lines as Vinit. How do you know it's not firing? It that you don't see the expected result or can't you see the entry / exit statements in the debug logs? If the former you could add some 

 

system.debug('Your text here!');

// or

system.debug('Your variable: ' + YourVariable);

 I hope this takes you in the right direction?

vishal@forcevishal@force

I think, based on certain conditions you are only creating more Electricity_Meter__c records (the goal here).

 

However, if we see the code, the new object instances you're creating inside the conditional loops (the if statements), you are simply adding them to a list : Refer 

 

 myList.add(b);  and  myList.add(c);

 

After that, nothing is done on myList. Maybe you'll want to insert them?

 

if(myList.size() > 0){

     insert myList;

}

 

This was selected as the best answer
AlanLamAlanLam

Hey guys,

 

Thanks for all the replies and suggestions really appreciate. So I have been trying different scenerios and getting intermittent results.

 

1. Went back into my Sandbox and simplified the trigger for object electricity_meter__c.I took and all if statements and removed one of the 2 record inserts. Ok so this worked the first time. And produced a record on update of a record as expected. 

2. I then put just one of the field if conditions back in and it stoppped working again. Obviously making sure that this condition was met. @Vishal I tried adding if(myList.size() > 0){insert myList;} and that didn't work either. I still need to try adding both lists as you suggested myList.add(b);  and  myList.add(c);

3. I then took it out again to revert back to the trigger with no if conditions at all. Now this is not working even without any if conditions.

4. I then tried moving to the other trigger object gasmeter__c to try and simplify the trigger. This didn't work without and if conditions.

5. I then turn on the debug logs and see if the trigger is being initialised. And yes I can now see the trigger. Debug snippet below

27.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
07:41:26.056 (56222000)|EXECUTION_STARTED
07:41:26.056 (56279000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
07:41:26.056 (56301000)|CODE_UNIT_STARTED|[EXTERNAL]|01qe00000004Fg6|cloneGasAMsignOff2 on GasMeter trigger event BeforeUpdate for [a0Me00000009SRz]
07:41:26.057 (57553000)|SYSTEM_CONSTRUCTOR_ENTRY|[4]|<init>()
07:41:26.057 (57601000)|SYSTEM_CONSTRUCTOR_EXIT|[4]|<init>()
07:41:26.057 (57821000)|SYSTEM_METHOD_ENTRY|[7]|LIST<GasMeter__c>.iterator()
07:41:26.058 (58075000)|SYSTEM_METHOD_EXIT|[7]|LIST<GasMeter__c>.iterator()
07:41:26.058 (58112000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
07:41:26.058 (58151000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
07:41:26.059 (59723000)|SYSTEM_METHOD_ENTRY|[56]|LIST<GasMeter__c>.add(Object)
07:41:26.059 (59766000)|SYSTEM_METHOD_EXIT|[56]|LIST<GasMeter__c>.add(Object)
07:41:26.059 (59780000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
07:41:26.059 (59797000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
07:41:26.074 (59825000)|CUMULATIVE_LIMIT_USAGE
07:41:26.074|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 39 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

07:41:26.074|CUMULATIVE_LIMIT_USAGE_END

07:41:26.059 (59891000)|CODE_UNIT_FINISHED|cloneGasAMsignOff2 on GasMeter trigger event BeforeUpdate for [a0Me00000009SRz]

 6. Now I decide to move to production and see what kind of results I am getting there on object electricity_meter__c. I turn on the debug logs. The trigger is once again being initialised but not producing the results. Debug log snippet below.

27.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
07:46:40.107 (107588000)|EXECUTION_STARTED
07:46:40.107 (107650000)|CODE_UNIT_STARTED|[EXTERNAL]|TRIGGERS
07:46:40.107 (107685000)|CODE_UNIT_STARTED|[EXTERNAL]|01qa0000000Yi1U|cloneElecAMsignOff on Electricity_Meter trigger event BeforeUpdate for [a0Ja000000FgrKe]
07:46:40.109 (109442000)|SYSTEM_CONSTRUCTOR_ENTRY|[4]|<init>()
07:46:40.109 (109532000)|SYSTEM_CONSTRUCTOR_EXIT|[4]|<init>()
07:46:40.109 (109762000)|SYSTEM_METHOD_ENTRY|[7]|LIST<Electricity_Meter__c>.iterator()
07:46:40.110 (110103000)|SYSTEM_METHOD_EXIT|[7]|LIST<Electricity_Meter__c>.iterator()
07:46:40.110 (110148000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
07:46:40.110 (110196000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
07:46:40.112 (112084000)|SYSTEM_METHOD_ENTRY|[64]|LIST<Electricity_Meter__c>.add(Object)
07:46:40.112 (112145000)|SYSTEM_METHOD_EXIT|[64]|LIST<Electricity_Meter__c>.add(Object)
07:46:40.112 (112169000)|SYSTEM_METHOD_ENTRY|[7]|system.ListIterator.hasNext()
07:46:40.112 (112195000)|SYSTEM_METHOD_EXIT|[7]|system.ListIterator.hasNext()
07:46:40.398 (112232000)|CUMULATIVE_LIMIT_USAGE
07:46:40.398|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Number of code statements: 44 out of 200000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10

07:46:40.398|CUMULATIVE_LIMIT_USAGE_END

07:46:40.112 (112291000)|CODE_UNIT_FINISHED|cloneElecAMsignOff on Electricity_Meter trigger event BeforeUpdate for [a0Ja000000FgrKe]

7. @Lakshman - In production: I ran the trigger class and tried the trigger again. And nothing still. (Did also try this before)

8. @Martin I did not attempt the system.debug statements as of yet. Are you able to suggest if I should put this in the trigger or test class, Thanks? 

9. @Vinit - I have checked that I am trying to get the trigger to fire on update of a record and also the if conditions. As you will see from my steps above I have tried to strip the trigger down to no if conditions at all and not working.

vishal@forcevishal@force

Can you post the latest trigger code please? I'd like to have a look. Also let me know what are you doing to test it?

MartinHaagenMartinHaagen

Hey,

 

it is pefectly safe to add the debug statements to both the trigger and the test case -- it will not interfere with anything in production either. I usually keep a couple of debug statments in my triggers and classes even after they work as expected. If you run into issues later on it is good to have them there when you enable debug logs.

 

Looking at the log you pasted it looks like the triggers are executed and they are doing something. The lines

 

07:41:26.059 (59723000)|SYSTEM_METHOD_ENTRY|[56]|LIST<GasMeter__c>.add(Object)
07:41:26.059 (59766000)|SYSTEM_METHOD_EXIT|[56]|LIST<GasMeter__c>.add(Object)

tells me that there is an object added to the list. But as mentioned before in the thread -- do you do  anything with this list later in the trigger. However, your a object changes should still exist since they are acting on the current trigger object and it is a before update. 

AlanLamAlanLam

Hi Vishal,

 

I have added

myList.add(a);

 

the latest code with all if conditions commented out looks like:

I am testing it in multiple ways. Going via list views, custom VF page and on individual records. None are working.

 

trigger cloneElecAMsignOff4 on Electricity_Meter__c (before update) {

     List<Electricity_Meter__c> myList = new List<Electricity_Meter__c>();
      
        for(Electricity_Meter__c a: trigger.new) {

        //if (a.Account_Manager_Sign_Off_Date_Time__c != Null ){
        //&& a.Clone_Date_Time_Stamp__c == Null && ) {
        //if (h.Deal_Done_Not__c == 'Deal Done (Existing client / Existing meter)' ||
        //h.Deal_Done_Not__c == 'Deal Done (New Meter, New Client)' || 
        //h.Deal_Done_Not__c == 'Deal Done (New Meter, Exisiting Client)' ){
        //if(myList.size() > 0){
        //insert myList;
        
        
        Electricity_Meter__c b = new Electricity_Meter__c();                
        b.Name = a.Name; 
        b.Site_name__c = a.Site_name__c;
        b.Contract_arranged_under_the_name_of__c = a.Winning_Contract_Arranged_Under_Name_of__c;
        b.Account__c = a.Account__c; 
        b.Linked_Basket__c = a.Linked_Basket__c;
        b.Linked_Monitor_Line__c = a.Linked_Monitor_Line__c;
        b.Current_Supplier__c = a.Winning_Supplier__c;
        b.Previous_Supplier__c = a.Current_Supplier__c;
        b.Meter_Status__c = '(2) Active (Not yet live)';
        b.COT_Disc_Deenerg_Date__c = a.COT_Disc_Deenerg_Date__c;       
        b.Auto_Manual_Term__c = a.Auto_Manual_Term__c;
              
        b.Linked_Affiliate_1__c = a.Linked_Affiliate_1__c;    
        b.Aff_1_Profit_Split__c = a.Aff_1_Profit_Split__c;
        b.Linked_Affiliate_2__c = a.Linked_Affiliate_2__c;    
        b.Aff_2_Profit_Split__c = a.Aff_2_Profit_Split__c;        
        b.Linked_Affiliate_3__c = a.Linked_Affiliate_3__c;    
        b.Aff_3_Profit_Split__c = a.Aff_3_Profit_Split__c;
        
        b.Site_Address_New__c = a.Site_Address_New__c;
        b.Site_Postcode__c = a.Site_Postcode__c;
        b.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c = a.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c;
        b.Billing_Address_New__c = a.Billing_Address_New__c;
        b.Billing_Postcode__c = a.Billing_Postcode__c;
        b.Number_of_employees__c = a.Number_of_employees__c;
        b.Annual_turnover_Euros__c = a.Annual_turnover_Euros__c;
        
        b.Profile_Class__c = a.Profile_Class__c;
        b.MTC_LLF__c = a.MTC_LLF__c;
        b.Meter_Details__c = a.Meter_Details__c; 
        b.MOP_CED__c = a.MOP_CED__c;
        b.Voltage_HV_LV_LVS__c = a.Voltage_HV_LV_LVS__c;
        
        b.Contract_start_date__c = a.Winning_Contract_Start_Date__c;
        b.Contract_expiry__c = a.Winning_Contract_End_Date__c;
        b.Payment_Method__c = a.Payment_Method__c;
        b.DD_Type__c = a.DD_Type__c;
        b.VAT__c = a.VAT__c;
        b.Monthly_Quarterly_Billing__c = a.Monthly_Quarterly_Billing__c;
        b.Copy_of_the_bills__c = a.Copy_of_the_bills__c;
        b.AQ__c = a.Winning_Supply_AQ__c;
        b.Total_KVA__c = a.Total_KVA__c; 
        b.Commission_p__c = a.Winning_Commision_p_kwh__c;
        b.Commission_per_year__c = a.Winning_Commission_year__c;
        b.Commission_Percent__c = a.Winning_Commission_Contract__c;  
        myList.add(a);  
        myList.add(b); 


    }

        
}
AlanLamAlanLam

Hi Martin,

 

I checked to see if the records have been inserted without a relationship and just floating about but nothing.

 

I will look more into system.debug as new to this. 

 

Thanks for the tips.

AlanLamAlanLam

I have also tried to copy the trigger code out of this trigger and put it into a new trigger. Deactivating the old trigger.

 

This is mind boggling

AlanLamAlanLam
Guys, I can't believe I totally missed this!
I had my insert statement inside of a try and catch block. Because of time and lack of knowledge I wasn't able to test against this. Which in turn made my trigger 98% instead of 100%. I commented the try catch block out! and this obviously had my insert statement. Thanks for looking at this. Guilty of overlooking the basics!
AlanLamAlanLam

For the interest of knowledge share: The final trigger looks like...

 

trigger cloneElecAMsignOff on Electricity_Meter__c (before update) {


     List<Electricity_Meter__c> myList = new List<Electricity_Meter__c>();
      

     for(Electricity_Meter__c a: trigger.new) {

        // insert Elec meter if Deal Done
        if (
        a.Account_Manager_Sign_Off_Date_Time__c != Null &&
        a.Clone_Date_Time_Stamp__c == Null && 
        (
        a.Deal_Done_Not__c == 'Deal Done (Existing client / Existing meter)' ||
        a.Deal_Done_Not__c == 'Deal Done (New Meter, New Client)' || 
        a.Deal_Done_Not__c == 'Deal Done (New Meter, Exisiting Client)')) {
        
        Electricity_Meter__c b = new Electricity_Meter__c();                
        b.Name = a.Name; 
        b.Site_name__c = a.Site_name__c;
        b.Contract_arranged_under_the_name_of__c = a.Winning_Contract_Arranged_Under_Name_of__c;
        b.Account__c = a.Account__c; 
        b.Linked_Basket__c = a.Linked_Basket__c;
        b.Linked_Monitor_Line__c = a.Linked_Monitor_Line__c;
        b.Current_Supplier__c = a.Winning_Supplier__c;
        b.Previous_Supplier__c = a.Current_Supplier__c;
        b.Meter_Status__c = '(2) Active (Not yet live)';
        b.COT_Disc_Deenerg_Date__c = a.COT_Disc_Deenerg_Date__c;       
        b.Auto_Manual_Term__c = a.Auto_Manual_Term__c;
              
        b.Linked_Affiliate_1__c = a.Linked_Affiliate_1__c;    
        b.Aff_1_Profit_Split__c = a.Aff_1_Profit_Split__c;
        b.Linked_Affiliate_2__c = a.Linked_Affiliate_2__c;    
        b.Aff_2_Profit_Split__c = a.Aff_2_Profit_Split__c;        
        b.Linked_Affiliate_3__c = a.Linked_Affiliate_3__c;    
        b.Aff_3_Profit_Split__c = a.Aff_3_Profit_Split__c;
        
        b.Site_Address_New__c = a.Site_Address_New__c;
        b.Site_Postcode__c = a.Site_Postcode__c;
        b.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c = a.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c;
        b.Billing_Address_New__c = a.Billing_Address_New__c;
        b.Billing_Postcode__c = a.Billing_Postcode__c;
        b.Number_of_employees__c = a.Number_of_employees__c;
        b.Annual_turnover_Euros__c = a.Annual_turnover_Euros__c;
        
        b.Profile_Class__c = a.Profile_Class__c;
        b.MTC_LLF__c = a.MTC_LLF__c;
        b.Meter_Details__c = a.Meter_Details__c; 
        b.MOP_CED__c = a.MOP_CED__c;
        b.Voltage_HV_LV_LVS__c = a.Voltage_HV_LV_LVS__c;
        
        b.Contract_start_date__c = a.Winning_Contract_Start_Date__c;
        b.Contract_expiry__c = a.Winning_Contract_End_Date__c;
        b.Payment_Method__c = a.Payment_Method__c;
        b.DD_Type__c = a.DD_Type__c;
        b.VAT__c = a.VAT__c;
        b.Monthly_Quarterly_Billing__c = a.Monthly_Quarterly_Billing__c;
        b.Copy_of_the_bills__c = a.Copy_of_the_bills__c;
        b.AQ__c = a.Winning_Supply_AQ__c;
        b.Total_KVA__c = a.Total_KVA__c; 
        b.Commission_p__c = a.Winning_Commision_p_kwh__c;
        b.Commission_per_year__c = a.Winning_Commission_year__c;
        b.Commission_Percent__c = a.Winning_Commission_Contract__c;  
        myList.add(b);  
        
        }


               
        // insert Elec meter if Deal Not Done
        else if (a.Account_Manager_Sign_Off_Date_Time__c != Null && 
        a.Clone_Date_Time_Stamp__c == Null && 
        (
        a.Deal_Done_Not__c == 'Deal not done / Not responding - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Not responding - Client lost' ||
        a.Deal_Done_Not__c == 'Deal not done / Went direct with supplier - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Went direct with supplier - Client lost' ||
        a.Deal_Done_Not__c == 'Deal not done / Went with another consultant - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Went with another consultant - Client lost' ||
        a.Deal_Done_Not__c == 'Deal not done / Meter removed - Client retained' ||
        a.Deal_Done_Not__c == 'Deal not done / Meter removed - Client lost')) {
        
        Electricity_Meter__c c = new Electricity_Meter__c();                
        c.Name = a.Name; 
        c.Site_name__c = a.Site_name__c;
        c.Contract_arranged_under_the_name_of__c = a.Winning_Contract_Arranged_Under_Name_of__c; 
        c.Account__c = a.Account__c; 
        c.Linked_Basket__c = a.Linked_Basket__c;
        c.Linked_Monitor_Line__c = a.Linked_Monitor_Line__c;
        c.Current_Supplier__c = a.Winning_Supplier__c;
        c.Previous_Supplier__c = a.Current_Supplier__c;
        c.Meter_Status__c = '(3) Active';
        c.COT_Disc_Deenerg_Date__c = a.COT_Disc_Deenerg_Date__c;        
        c.Auto_Manual_Term__c = a.Auto_Manual_Term__c;
              
        c.Linked_Affiliate_1__c = a.Linked_Affiliate_1__c;    
        c.Aff_1_Profit_Split__c = a.Aff_1_Profit_Split__c;
        c.Linked_Affiliate_2__c = a.Linked_Affiliate_2__c;    
        c.Aff_2_Profit_Split__c = a.Aff_2_Profit_Split__c;        
        c.Linked_Affiliate_3__c = a.Linked_Affiliate_3__c;    
        c.Aff_3_Profit_Split__c = a.Aff_3_Profit_Split__c;
        
        c.Site_Address_New__c = a.Site_Address_New__c;
        c.Site_Postcode__c = a.Site_Postcode__c;
        c.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c = a.Co_Reg_FULL_Partnership_LLP_Sole_Trader__c;
        c.Billing_Address_New__c = a.Billing_Address_New__c;
        c.Billing_Postcode__c = a.Billing_Postcode__c;
        c.Number_of_employees__c = a.Number_of_employees__c;
        c.Annual_turnover_Euros__c = a.Annual_turnover_Euros__c;
        
        c.Profile_Class__c = a.Profile_Class__c;
        c.MTC_LLF__c = a.MTC_LLF__c;
        c.Meter_Details__c = a.Meter_Details__c; 
        c.MOP_CED__c = a.MOP_CED__c;
        c.Voltage_HV_LV_LVS__c = a.Voltage_HV_LV_LVS__c;
        
        c.Contract_start_date__c = a.Winning_Contract_Start_Date__c;
        c.Contract_expiry__c = a.Winning_Contract_End_Date__c;
        c.Payment_Method__c = a.Payment_Method__c;
        c.DD_Type__c = a.DD_Type__c;
        c.VAT__c = a.VAT__c;
        c.Monthly_Quarterly_Billing__c = a.Monthly_Quarterly_Billing__c;
        c.Copy_of_the_bills__c = a.Copy_of_the_bills__c;
        c.AQ__c = a.Winning_Supply_AQ__c;
        c.Total_KVA__c = a.Total_KVA__c; 
        c.Commission_p__c = a.Winning_Commision_p_kwh__c;
        c.Commission_per_year__c = a.Winning_Commission_year__c;
        c.Commission_Percent__c = a.Winning_Commission_Contract__c;
        myList.add(c);           
        
        }

        
    }
       
        try {
        insert myList; 
    } catch (system.Dmlexception e) {
        system.debug (e);      
    }
        
        
}