You need to sign in to do that
Don't have an account?
AlphaP
Blocking Help in Apex Code
Line 176 is bombing out because of the '}' I'm missing why my blocking is off on that line. Any ideas?
*/ trigger StandOffPeriod2 on Lead (before Insert, before update) { List<Opportunity> opptList = new List<Opportunity>(); List<Opportunity> tmpList = new List<Opportunity>(); List<Lead> leadList = new List<Lead>(); List<Lead> tmpleadList = new List<Lead>(); Set<String> tmpSet = new Set<String>(); Set<String> tmpPhoneSet = new Set<String>(); Set<String> tmpPartyIdSet = new Set<String>(); Map<Id, Lead> unConvertedLeadsToUpdate = new Map<Id,lead>(); Date myDate = Date.Today().addDays(-90); for(Lead lead : Trigger.new){ tmpSet.add(lead.Company_Phone__c); tmpPhoneSet.add(lead.Phone); tmpPartyIdSet.add(lead.Company); //tmpleadList.add(lead); } System.debug('tmpPhoneset = ' + tmpPhoneset); System.debug('tmpPartyIdset = ' + tmpPartyIdSet); //pull a list of all opportunities that match the company_phone__c field //tmpList = [select id, Lead_Phone_Number_ALL__c, Lead_Status_All__c, Lead_Call_Date_ALL__c,Lead_Company_Phone__c from Opportunity where Lead_Company_Phone__c in :tmpSet]; tmpList = [select id, Lead_Phone_Number_ALL__c, Lead_Status_All__c, Lead_Call_Date_ALL__c,Account.Name from Opportunity where Account.name in :tmpPartyIdSet OR Lead_Phone_Number_ALL__c in:tmpPhoneSet]; //System.debug('tmpList2 information = ' + tmpList2.size()); //pull a list of all existing leads that match the company_phone__c field //tmpLeadList = [select id, Call_Date_All__c, Company_Phone__c from Lead where Company_Phone__c in:tmpSet]; tmpLeadList = [select id, Call_Date_All__c, Company_Phone__c,Party_ID_ALL__c,Company,Phone from Lead where isConverted=FALSE AND (Phone in:tmpPhoneSet OR Company in:tmpPartyIdSet)]; //pull a list of matching Do Not Call records tmpDNCList = [select id, Name from Do_Not_Call__c where Name in:tmpPartyIdSet]; //Build a map with all retrieved lead objects System.debug('The tmpList is currently ' + tmpList.size()); for(Lead myLead : Trigger.new){ if(myLead.status == 'Open' && Trigger.new.size() > 1){ //Check the lead Dates and set the status if necessary System.debug('Lead to look at...Here is the date -=> ' + myLead.Call_Date_All__c); System.debug('Comparing to myDate -=> ' + myDate); //Checking the opportunity Boolean opptCheck = false; if(tmpList.size()>0){ for(Opportunity o : tmpList){ if((o.Account.Name == myLead.Company) || (o.Lead_Phone_Number_ALL__c==myLead.Phone)){ if(o.Lead_Call_Date_All__c == null){ System.debug('NULL Date found on the Opportunity...setting status to Open'); myLead.Status = 'Open'; opptCheck = true; System.debug('Here is the oppt id = ' + o.id); break; }else if (o.Lead_Call_Date_All__c <= myDate){ System.debug('Earlier date found on the Opportunity...setting status to Open'); myLead.Status = 'Open'; opptCheck = true; System.debug('Here is the oppt id = ' + o.id); break; }else if(o.Lead_Call_Date_All__c > myDate){ System.debug('Later date found on the Opportunity...setting status to Pending'); myLead.Status = 'Pending'; opptCheck = true; System.debug('Here is the oppt id = ' + o.id); break; } } } } if(opptCheck){ System.debug('######################################## Opportunity has set the status #####################'); continue; } Boolean leadCheck = false; if(tmpLeadList.size()>0 && myLead.id == null){ for(Lead l : tmpLeadList){ if((l.Company == myLead.Company) || (l.Phone == myLead.Phone)){ if(l.Call_Date_All__c == null){ System.debug('NULL Date found on the LEAD MATCH...setting status to Open'); myLead.Status = 'Open'; l.status='Open'; Boolean addLead = true; if(!unconvertedLeadsToUpdate.containsKey(l.Id)){ unConvertedLeadsToUpdate.put(l.id, l); } leadCheck = true; System.debug('Here is the LEAD id = ' + l.id); //break; }else if (l.Call_Date_All__c <= myDate){ System.debug('Earlier date found on the LEAD MATCH...setting status to Open'); myLead.Status = 'Open'; l.status='Open'; Boolean addLead = true; if(!unconvertedLeadsToUpdate.containsKey(l.Id)){ unConvertedLeadsToUpdate.put(l.id, l); } leadCheck = true; System.debug('Here is the LEAD id = ' + l.id); //break; }else if(l.Call_Date_All__c > myDate){ System.debug('Later date found on the LEAD MATCH...setting status to Pending'); myLead.Status = 'Pending'; l.status='Pending'; Boolean addLead = true; if(!unconvertedLeadsToUpdate.containsKey(l.Id)){ unConvertedLeadsToUpdate.put(l.id, l); } leadCheck = true; System.debug('Here is the LEAD id = ' + l.id); //break; } } } } if(leadCheck){ System.debug('######################################## Existing Lead has set the status #####################'); continue; } if(myLead.Call_Date_All__c == null){ System.debug('NULL Date found...setting status to Open'); myLead.Status = 'Open'; //leadList.add(myLead); }else if (myLead.Call_Date_All__c <= myDate){ System.debug('Earlier date found...setting status to Open'); myLead.Status = 'Open'; //leadList.add(myLead); }else if(myLead.Call_Date_All__c > myDate){ System.debug('Later date found...setting status to Pending'); myLead.Status = 'Pending'; //leadList.add(myLead); } } } //Checking the Do Not Call Object Boolean DNCCheck = false; if(tmpDNCList.size()>0){ for(Do_Not_Call obj : tmpDNCList) { if((obj.Name == myLead.Company) { System.debug(Matching Do Not Call Record Found - setting status to 'pending'); myLead.Status = 'Pending'; DNCCheck = true; break; } } } if(DNCCheck){ System.debug('######################################## Do Not Call Object has set the status #####################'); continue; } if(unConvertedLeadsToUpdate.size() > 0){ List<Lead> updateME = new List<Lead>(); updateME = unConvertedLeadsToUpdate.values(); System.debug('unConvertedLeadsToUpdate SIZE = ' + unConvertedLeadsToUpdate.size()); // update updateMe; } }
Wow - this is why my teachers in school told me to have someone else proofread your work!
Notived I had an extra ')' on that line. I didn't see that in all the times I looked at that line.
if((obj.Name == myLead.Company){ changed to: if(obj.Name == myLead.Company){
Sheesh.
All Answers
Sorry - meant to post the error too:
I got to sleep on this and saw some toher issues I had with the code (I forgot to declare one of my lists). The line that bombs out is:
That's this line here: if((obj.Name == myLead.Company) {
They way this code works, is when I import leads and if certian criteria are met on a matching lead, opporutnity or custom object, then the l.status is changed on insert. I'm not sure where I'm off and have run out of ideas about where I messed up on formatting. Thanks for reading - code to follow:
Wow - this is why my teachers in school told me to have someone else proofread your work!
Notived I had an extra ')' on that line. I didn't see that in all the times I looked at that line.
if((obj.Name == myLead.Company){ changed to: if(obj.Name == myLead.Company){
Sheesh.