• globalsfdc
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

Hi,

 

I have spent 9 hours on this trigger and I really am unsure why I am getting these errors? The thing is this is simular to many tiggers I have wrote in the past so its hard for me to understand.


The trigger is trying to change the currency of a Lead to USD whenever the record type is NA Leads.

 

I would appreciate any help at all. Many Thanks for your time.

 

Trigger:

trigger NALeadsWeb2LeadCurrencyChange on Lead (before update) { Map<String,String> LeadMap = new Map<String,String>(); for(Lead l:trigger.new){ if (l.RecordTypeId == [ select Id from RecordType where Name = 'NA Lead' and SobjectType = 'Lead' limit 1].id){ LeadMap.put(l.id, 'USD'); } } List<Lead> recordsforupdates = new list<Lead>(); for(Lead nl : [Select Id, CurrencyIsoCode from Lead where Id IN : LeadMap.keySet()]){ if (LeadMap.containsKey(nl.Id)){ nl.CurrencyIsoCode = 'USD'; recordsforupdates.add(nl); } } update recordsforupdates; }

 

Test Case:

@isTest private class NALeadsWeb2LeadCurrencyChanger { static testMethod void myUnitTest() { // TO DO: implement unit test Lead lead = new Lead(firstname= 'TestTestTest', lastname = 'Testing', company = 'Salesforce.com', email = 't.test@salesforce.com', recordtypeid =[select Id from RecordType where Name = 'ADMIN Master Web to Lead' and SobjectType = 'Lead' limit 1].Id); insert lead; lead.RecordTypeId=[select Id from RecordType where Name = 'NA Lead' and SobjectType = 'Lead' limit 1].id; update lead; } }

 

Error:

*** Beginning Test 1: NALeadsWeb2LeadCurrencyChanger.static testMethod void myUnitTest() 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 10, column 22: SOQL query with 1 row finished in 5 ms 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 11, column 4: Insert: SOBJECT:Lead 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 11, column 4: DML Operation executed in 146 ms 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 13, column 22: SOQL query with 1 row finished in 4 ms 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 15, column 4: Update: SOBJECT:Lead *** Beginning NALeadsWeb2LeadCurrencyChange on Lead trigger event BeforeUpdate for 00QS0000003OZhJ 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 3, column 2: SelectLoop:LIST:SOBJECT:Lead 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 4, column 25: SOQL query with 1 row finished in 16 ms 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 3, column 2: Number of iterations: 1 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 13, column 2: SelectLoop:LIST:SOBJECT:Lead 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 13, column 16: SOQL query with 1 row finished in 21 ms 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 13, column 2: Number of iterations: 1 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2: Update: LIST:SOBJECT:Lead 20100218162913.823:Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2: DML Operation executed in 2 ms System.DmlException: Update failed. First exception on row 0 with id 00QS0000003OZhJMAW; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00QS0000003OZhJ) is currently in trigger NALeadsWeb2LeadCurrencyChange, therefore it cannot recursively update itself: [] Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2 Cumulative resource usage: Resource usage for namespace: (default) Number of SOQL queries: 4 out of 100 Number of query rows: 4 out of 500 Number of SOSL queries: 0 out of 20 Number of DML statements: 3 out of 100 Number of DML rows: 3 out of 500 Number of script statements: 10 out of 200000 Maximum heap size: 0 out of 1000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 Total email recipients queued to be sent : 0 Static variables and sizes: NALeadsWeb2LeadCurrencyChange:LeadMap:29 NALeadsWeb2LeadCurrencyChange:recordsforupdates:58 Stack frame variables and sizes: Frame0 l:0 nl:0 *** Ending NALeadsWeb2LeadCurrencyChange on Lead trigger event BeforeUpdate for 00QS0000003OZhJ 20100218162913.636:Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 15, column 4: DML Operation executed in 74 ms System.DmlException: Update failed. First exception on row 0 with id 00QS0000003OZhJMAW; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, NALeadsWeb2LeadCurrencyChange: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00QS0000003OZhJMAW; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00QS0000003OZhJ) is currently in trigger NALeadsWeb2LeadCurrencyChange, therefore it cannot recursively update itself: [] Trigger.NALeadsWeb2LeadCurrencyChange: line 19, column 2: [] Class.NALeadsWeb2LeadCurrencyChanger.myUnitTest: line 15, column 4 External entry point Cumulative resource usage: Resource usage for namespace: (default) Number of SOQL queries: 2 out of 100 Number of query rows: 2 out of 500 Number of SOSL queries: 0 out of 20 Number of DML statements: 2 out of 100 Number of DML rows: 2 out of 500 Number of script statements: 4 out of 200000 Maximum heap size: 0 out of 1000000 Number of callouts: 0 out of 10 Number of Email Invocations: 0 out of 10 Number of fields describes: 0 out of 10 Number of record type describes: 0 out of 10 Number of child relationships describes: 0 out of 10 Number of picklist describes: 0 out of 10 Number of future calls: 0 out of 10 Number of find similar calls: 0 out of 10 Number of System.runAs() invocations: 0 out of 20 Total email recipients queued to be sent : 0 Stack frame variables and sizes: Frame0 *** Ending Test NALeadsWeb2LeadCurrencyChanger.static testMethod void myUnitTest()