• Eittay Basly 15
  • NEWBIE
  • 10 Points
  • Member since 2021

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

Hi there, 

I am trying to save this trigger after I added a condition for the Account__c filed (line 13). Unfortunately, I am getting the following 2 errors: 

#1. Error: Compile Error: Duplicate variable: obj at line 13 column 31
#2 Error: Compile Error: Duplicate variable: obj at line 20 column 39
 

1	trigger TriggerOnAcquiredLead on Purchased_Data__c (before insert, after insert) { 
2	    
3	    If(Trigger.isBefore && Trigger.isInsert){
4	    
5	    for(Purchased_Data__c obj :trigger.new){
6	    if(obj.Account__c != null){
7	        continue;
8	    }else{
9	        List<Purchased_Data__c> NewRecs = new List<Purchased_Data__c>();
10	        Map<string,Purchased_Data__c> VersionMap = new Map<string,Purchased_Data__c>();
11	        set<String> LenderCodes = new set<String>();
12	        
13	        for(Purchased_Data__c obj :trigger.new){
14	            LenderCodes.add(obj.Lender_Code__c);
15	        }
16	        system.debug('Lender codes are '+LenderCodes);
17	        if(!LenderCodes.isEmpty()){
18	            List<Purchased_Data__c> TempLst = [select Id,Name,Lender_Code__c,Version__c,CreatedDate from Purchased_Data__c where Lender_Code__c =:LenderCodes];
19	            if(!TempLst.isEmpty()){
20	                for(Purchased_Data__c obj: TempLst){
21	                    Purchased_Data__c TempObj = new Purchased_Data__c();
22	                    if(VersionMap.containsKey(obj.Lender_Code__c)){
23	                        TempObj = VersionMap.get(obj.Lender_Code__c);
24	                        if(obj.createddate > TempObj.createddate){
25	                            VersionMap.put(obj.Lender_Code__c,obj);
26	                        }
27	                    }else{
28	                        VersionMap.put(obj.Lender_Code__c,obj);
29	                    }
30	                }    
31	            }
32	            system.debug('Version Mapping is '+VersionMap);
33	            /*for(string Lcode: LenderCodes){
34	                system.debug('Current Lender code is '+Lcode);
35	                for(Purchased_Data__c obj:[select Id,Name,Lender_Code__c,Version__c,CreatedDate from Purchased_Data__c where Lender_Code__c =:Lcode ORDER BY createddate DESC Limit 1]){
36	                    system.debug('Purchased date record is '+obj);
37	                    VersionMap.put(obj.Lender_Code__c,obj);
38	                }    
39	            }*/
40	            //Now update the version numbers
41	            for(Purchased_Data__c pd: trigger.new){
42	                system.debug('New record is '+pd);
43	                if(string.isNotBlank(pd.Lender_Code__c) && VersionMap.containsKey(pd.Lender_Code__c)){
44	                    string[] tempV = VersionMap.get(pd.Lender_Code__c).Version__c.split(' ');
45	                    Integer temp = Integer.valueOf(tempV[1]);
46	                    temp = temp + 1;
47	                    pd.Version__c = 'Version '+temp;
48	                }else{
49	                    //Set Lender Code as Version 1
50	                    pd.Version__c = 'Version 1';
51	                }
52	            }    
53	        }
54	    }
55	    }
56	}
57	    
58	       
59	   
60	    //To Trigger when Acquired Lead is Created
61	    if(Trigger.isAfter && Trigger.isInsert){
62	       UpsertAcquriedLead.checkAccAndLead(Trigger.newmap.keySet());
63	    }
64	}
 

Thank you!