• Dipak@pvs
  • NEWBIE
  • 10 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 4
    Replies
Hi All,

I am getting System.ListException: List index out of bounds: 2 error while running a test class. My class and Test class are:

Class:
global class ArpDataCleanupBatch implements Database.Batchable<SObject>, Database.Stateful{

private List<Id> AlmRepPerfIds;

private String MarketCleanupId;

//private List<Id> CalIds;

public ArpDataCleanupBatch() {
        //do nothing   
    }

   
public ArpDataCleanupBatch(List<Id> AlmRepPerfIds) {
        this.AlmRepPerfIds = AlmRepPerfIds;
    }
   
public ArpDataCleanupBatch(String MarketId) {
        this.MarketCleanupId = MarketId;
    }

public ArpDataCleanupBatch(String MarketId, List<Id> AlmRepPerfIds) {
        this.MarketCleanupId = MarketId;
        this.AlmRepPerfIds = AlmRepPerfIds;
       // this.CalIds = CalIds;
    }     

    global Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator(prepareSOQL());
    }

    global void execute(Database.BatchableContext bc, List<ALM_Rep_Performance_1__c> rows){
            delete rows;
        //   DataBase.emptyRecycleBin(rows);    
    }
   
    global void finish(Database.BatchableContext bc){
    
     String CleanupLastRun;
     datetime myDateTime = datetime.now();
     String myDateStr = String.ValueOf(myDateTime);
     Market__c mkt = [select Id,Cleanup_Last_Run__c from market__c
                                                        where Market_Id__c=:MarketCleanupId];
                      
         mkt.Cleanup_Last_Run__c = 'ALM_Rep_Performance_1__c:'+myDateStr;
              
           update mkt;
          
           Database.executeBatch(new SlhDataCleanupBatch('73'),2000);              
              System.debug('job finished.');
     
    }
   
    public static void startJob() {
        scheduleJob(2);
    }
   
   
    private String prepareSOQL() {
     
       Market__c mrkt = [select PREV_1_CMPGN_NR__c,X90_Day_Camp_CNT__c from market__c
                       where Market_Id__c=:MarketCleanupId];
       
       List<Calendar__c> camp = [select CMPGN_NR__c from Calendar__c where MRKT_ID__c = :MarketCleanupId order by CMPGN_NR__c desc];
      
          Integer index = -1;
         
          Integer CampaignIndex=1;

       List<String> Camps=new List<String>();
      
          for(Calendar__c ca: camp){
            Camps.add(String.valueOf(ca.CMPGN_NR__c));
          }

    for(Integer m = 0; m<Camps.size();m++){
             IF(Camps[m].equalsignorecase(mrkt.PREV_1_CMPGN_NR__c)){
             index = m;
             System.debug('index='+ index);
             break;       
             }
          }

       String PrevCmpgnStr=Camps[index+CampaignIndex];
       Decimal myDecimal = decimal.valueOf(PrevCmpgnStr);
      
       system.debug('prevcamps'+ PrevCmpgnStr);
     
        // For testing
       
          Set<Id> ptIds = new Set<Id>{'a1KZ0000001o81u','a1KZ0000001o81z','a1KZ0000001o820'};
        List<Id> llistId =  New List<Id>();
          llistId.addAll(ptIds);
         String idStrings= '\''+String.join(llistId,'\',\'')+'\'';
      String sql = 'SELECT Id FROM ALM_Rep_Performance_1__c ';
        
         sql += ' where Id In ('+idStrings+') ' ;

        // End For testing
      
   /*   String sql = 'SELECT FLD_SLS_CMPGN_NR__c, id FROM ALM_Rep_Performance_1__c ';
                
            sql += ' where FLD_SLS_CMPGN_NR__c = '+myDecimal+' and MRKT_ID__c =\''+MarketCleanupId+'\'';*/
           
            system.debug('query'+ sql);     
      return sql;
     
    }
   
    private Set<String> fetchEligibleMarketCodes() {
        Set<String> marketCodes = new Set<String>();
        for (Market__c market : [Select Market_Id__c from Market__c where Is_ALMPLUS_Enabled__c=true]) {
            marketCodes.add(market.Market_Id__c);
        }
        System.debug('eligible market codes: ' + marketCodes);
        return marketCodes;
    }
   
    private static void scheduleJob(Integer minutesOffset) {
        DateTime currentTime = System.now();
        String scheduleTime = ALMPlusUtils.prepareJobsSchTime(currentTime, minutesOffset); 
        String uniqueJobName = ALMPlusUtils.getUniqueJobName('ArpDataCleanupBatch');
        String cronID = System.schedule(uniqueJobName, scheduleTime, new BatchJobScheduler(new ArpDataCleanupBatch(), 1000));  //use 10 as the batch size         
    }
   
    //ArpDataCleanupBatch arp=new ArpDataCleanupBatch('73');
    //arp.startJob();
   
   
}


Test Class:
@isTest
private class ArpDataCleanupBatchTest {

static testMethod void testBatchJob() {

User loginUser = new User(Id=UserInfo.getUserId());
    TestDataHelper td = new TestDataHelper();
      
       Market__c mrkt = TestDataHelper.createMarket('test market', '1234', false);
        mrkt.ALM_Rep_Indicator__c = 'ALM_Rep_Performance_1__c';
        mrkt.PREV_1_CMPGN_NR__c = '201111';
        mrkt.X90_Day_Camp_CNT__c = 4;
        mrkt.Mail_Plan_Enabled__c = true;
        mrkt.CMPGN_NR__c = '1234567';
        mrkt.Is_Cleanup_Enabled__c= true;
       
        insert mrkt;
  
    System.runAs(loginUser) {
    Account acc = TestDataHelper.createAccount('test', 'USD', true);
    Contact con = TestDataHelper.createContact('1234', acc.Id, true);
    List<Id> AlmRepPerfIds = new List<Id>();
    String MarketCleanupId;
    MarketCleanupId = mrkt.Market_Id__c;
   
      List<ALM_Rep_Performance_1__c> arp = new List<ALM_Rep_Performance_1__c>(); 
       ALM_Rep_Performance_1__c arp1 = new ALM_Rep_Performance_1__c(Name = 'Test Name',FLD_SLS_CMPGN_NR__c = 201312,MRKT_ID__c = '73',
                      Personal_Performance_Key__c = '1233444322',MRKT_ACCT_KEY__c = con.Id,MRKT_KEY__c =mrkt.Id);
       
        insert arp1;                                                         
        arp.add(arp1);                                                              
  
     List<Calendar__c> cal = new List<Calendar__c>();
      Calendar__c cal1 = new Calendar__c(CMPGN_NR__c = 201312, MRKT_ID__c = '73', YEAR_NR__c = 4,
                                      CMPGN_STRT_DT__c = date.valueOf('2013-04-02'), PRIOR_CMPGN_NR__c='201311', Market__c =mrkt.Id);

      Calendar__c cal2 = new Calendar__c(CMPGN_NR__c = 201312, MRKT_ID__c = '73', YEAR_NR__c = 4,
                                 CMPGN_STRT_DT__c = date.valueOf('2013-05-02'), PRIOR_CMPGN_NR__c='201311',Market__c =mrkt.Id);                                                                                                                                       
       cal.add(cal1);                                                    
       cal.add(cal2);
      
       insert cal;
       System.debug('cal1 ->>'+cal1);
       System.debug('cal2 ->>'+cal2);                                                   
       Set<Id> CalIds = new Set<Id>();
       CalIds.add(cal1.Id);
       CalIds.add(cal2.Id);
      
       Integer index = -1;
       Integer CampaignIndex=1;
      
       List<String> Camps=new List<String>();
       system.debug('string is'+ cal);
      
       for(Calendar__c ca: cal){
            Camps.add(String.valueOf(ca.CMPGN_NR__c));
          }
         
        
    for(Integer m = 0; m<Camps.size();m++){
             index = m;
             System.debug('index='+ index);
          }
         
          String PrevCmpgnStr=Camps[index+CampaignIndex];
          system.debug('string for index'+ PrevCmpgnStr);
 
    Test.startTest();
Database.executeBatch(new ArpDataCleanupBatch(MarketCleanupId,AlmRepPerfIds), 10);
    ArpDataCleanupBatch.startJob();
    Test.stopTest();
  //  System.assert(0 == [Select count() from ALM_Rep_Performance_1__c where Id=:arp.Id]);
    }

     List<ALM_Rep_Performance_1__c> alerts = [select Id,FLD_SLS_CMPGN_NR__c from ALM_Rep_Performance_1__c];
        if(alerts.size() > 0) {
            System.assert(alerts.size() == 1);
            System.assert(alerts[0].FLD_SLS_CMPGN_NR__c == 201312);
        }
}                                                                     
      
}.

It gives me error like this:
System.ListException: List index out of bounds: 2

Class.ArpDataCleanupBatchTest.testBatchJob: line 67, column 1(line no. 67:--String PrevCmpgnStr=Camps[index+CampaignIndex];)

Any help will be greatly appreciated.

Regards,
Dip
Hi,

Whenever I am going to run the folowing batch I get the error 'First error: unexpected token: '{''. The batch is :

global class ZmDmAttachmentCleanupBatch implements Database.Batchable<SObject>, Database.Stateful{

private List<Id> ZmDmAttachmentIds;

private String MarketCleanupId;

public ZmDmAttachmentCleanupBatch() {
        //do nothing   
    }

   
public ZmDmAttachmentCleanupBatch(List<Id> ZmDmAttachmentIds) {
        this.ZmDmAttachmentIds = ZmDmAttachmentIds;
    }
   
public ZmDmAttachmentCleanupBatch(String MarketId) {
        this.MarketCleanupId = MarketId;
    }  

    global Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator(prepareSOQL());
    }

    global void execute(Database.BatchableContext bc, List<Attachment> rows){
            delete rows;
           DataBase.emptyRecycleBin(rows);    
    }
   
    global void finish(Database.BatchableContext bc){
     String CleanupLastRun;
     datetime myDateTime = datetime.now();
     String myDateStr = String.ValueOf(myDateTime);
     Market__c mkt = [select Id,Cleanup_Last_Run__c from market__c
                                                        where Market_Id__c=:MarketCleanupId];

         String CleanupLastRun1 = mkt.Cleanup_Last_Run__c;
         String CleanupLastRun2 = CleanupLastRun1+'Attachment:'+myDateStr;             
        // mkt.Cleanup_Last_Run__c = 'Attachment:'+myDateStr;
              
           update mkt;
          
           Database.executeBatch(new SlAttachmentCleanupBatch('73'),2000);
        System.debug('job finished.');
     
    }
   
    public static void startJob() {
        scheduleJob(2);
    }
   
   
    private String prepareSOQL() {
     
       Market__c mrkt = [select PREV_1_CMPGN_NR__c,X90_Day_Camp_CNT__c from market__c
                                                     where Market_Id__c=:MarketCleanupId];
       List<CDW_Market_Report__c> Parent_id = [select id from CDW_Market_Report__c
                                                      where Market__r.Market_Id__c=:MarketCleanupId];
             system.debug('parent id'+Parent_id);
      
      // List<SObject> results = Database.query(someSOQL);
       Set<Id> resultIds = (new Map<Id,CDW_Market_Report__c>(Parent_id)).keySet();
      // Set<Id> resultIds = new Set<Id> (new Map<Id,CDW_Market_Report__c>(Parent_id).keySet());
      // Set<String> resultIds = (new Map<String,CDW_Market_Report__c>(Parent_id)).keySet();      
       List<Calendar__c> camp = [select CMPGN_NR__c,CMPGN_STRT_DT__c from Calendar__c
                                                    where MRKT_ID__c = :MarketCleanupId order by CMPGN_NR__c desc];

          Integer index = -1;
         
          Integer CampaignIndex=6;

       List<String> Camps=new List<String>();
      
          for(Calendar__c ca: camp){
            Camps.add(String.valueOf(ca.CMPGN_NR__c));
          }

          for(Integer m = 0; m<Camps.size();m++){
             IF(Camps[m].equalsignorecase(mrkt.PREV_1_CMPGN_NR__c)){
             index = m;
             System.debug('index='+ index);
             break;       
             }
          }
       Calendar__c PrevCmpgnStr1=camp[index+CampaignIndex];
              system.debug('final campaign'+ PrevCmpgnStr1);
  
               date startdate= PrevCmpgnStr1.CMPGN_STRT_DT__c;
               Datetime dt = datetime.newInstance(startdate.year(), startdate.month(),startdate.day(),00,00,00);

     // List<Attachment> atc = [select Id from Attachment where ParentId In :resultIds and LastModifiedDate<:dt];
     
     // system.debug('attachmentis'+ atc);

      // String PrevCmpgnStr=Camps[index+CampaignIndex];
      
      String sql = 'SELECT Id FROM Attachment ';
                
           // sql += ' where ParentId In :\''+resultIds+'\' and LastModifiedDate<:\''+dt+'\'';
            sql += ' where ParentId In :'+resultIds+' and LastModifiedDate<:'+dt+'';
           
       system.debug('queryis'+ sql);           
      return sql;
     
    }
   
   
    private Set<String> fetchEligibleMarketCodes() {
        Set<String> marketCodes = new Set<String>();
        for (Market__c market : [Select Market_Id__c from Market__c where Is_ALMPLUS_Enabled__c=true]) {
            marketCodes.add(market.Market_Id__c);
        }
        System.debug('eligible market codes: ' + marketCodes);
        return marketCodes;
    }
   
    private static void scheduleJob(Integer minutesOffset) {
        DateTime currentTime = System.now();
        String scheduleTime = ALMPlusUtils.prepareJobsSchTime(currentTime, minutesOffset); 
        String uniqueJobName = ALMPlusUtils.getUniqueJobName('ZmDmAttachmentCleanupBatch');
        String cronID = System.schedule(uniqueJobName, scheduleTime, new BatchJobScheduler(new ZmDmAttachmentCleanupBatch(), 1000));  //use 10 as the batch size         
    }
   
    //ZmDmAttachmentCleanupBatch zda=new ZmDmAttachmentCleanupBatch('73');
    //zda.startJob();
   
   
}

Can anybody tell me where I am missing in the code.

Regards,
Dip
Hi,

I am facing problem in writing test method of the following class:

global class LeadEntryFormController_PL {
  
  public String fName{get;set;}
  public String lName{get;set;}
  public String leadType{get;set;}
  public String email{get;set;}
  public String confEmail{get;set;}
  public String mobile{get;set;}
  public String zipcode{get;set;}
  public String city{get;set;}
  public String Area{get;set;}
  public String note{get;set;}
  public String MaxAge{get;set;}
    public String MinAge{get;set;}
    public String userLang {get; set;}
    public String marketId{get;set;}
    public Boolean allReqField{get;set;}
  public Market__c currMarket{get;set;}
  public LeadsDistribution.LeadWrapper wLead;
  public LeadEntryFormController_PL(ApexPages.StandardController controller){
     
  }
  public LeadEntryFormController_PL(){
    wLead = new LeadsDistribution.LeadWrapper();
    currMarket = [Select Security_and_Privacy_URL__c, CMPGN_NR__c, Conditions_Of_Use_URL__c, Name, Market_Id__c, Id, ASLF_Market_Id__c,Lead_Minimum_Age__c, Lead_Maximum_Age__c,CURRENT_QRTR__c,CURRENT_CAMPAIGN_NR__c,
                        Lead_Security_and_Privacy_URL__c,Lead_Conditions_Of_Use_URL__c,Lead_Source_Exclusions__c,Phone_Format__c,Postcode_Format__c,Name_Format__c,Omniture_RSID__c,Omniture_JS_URL__c,LeadEntryFields__c
                        From Market__c 
                        where Market_Id__c =: ApexPages.currentPage().getParameters().get(ALMPLusConstants.MRKT_ID)];
        System.debug('currMarket--'+currMarket);
        this.marketId = currMarket.Market_Id__c;---------not covered(1)
        if(this.marketId == ALMPLusConstants.ROMANIA_MKT_ID){
          findAreas();
        }
        MaxAge = String.valueOf(currMarket.Lead_Maximum_Age__c);
        MinAge = String.ValueOf(currMarket.Lead_Minimum_Age__c); 
        try{
            
            this.userLang = ApexPages.currentPage().getParameters().get(ALMPLusConstants.LANG_CD);
            //this.src = ApexPages.currentPage().getParameters().get('src');
            //this.accNo = ApexPages.currentPage().getParameters().get('accId');
            if(this.userLang!=null){
                Gi3_Language_Mapping__c langConfig = Gi3_Language_Mapping__c.getValues(this.userLang);
                try{
                    this.userLang = (langConfig.Gi3_Lang_code__c!=null?langConfig.Gi3_Lang_code__c:'en_US');
                }catch(Exception ex){
                    this.userLang = 'en_US';
                }
            }
        }catch(exception ex){
            //CRF: don't ignore exception
        }              
  }
  public List<Selectoption> areas{get;set;}
  public void findAreas(){
    areas = new List<Selectoption>();
    for(Geo_Level_2__c ar: [Select g.Name, g.MRKT_ID__c, g.Id, g.Geo_Level_1__c From Geo_Level_2__c g
                where MRKT_ID__c =: ALMPLusConstants.ROMANIA_MKT_ID order by Name limit 998]){
      areas.add(new Selectoption(ar.Id,ar.Name));            
      
    }
    
  }
  public List<SelectOption> getType(){
        Schema.DescribeFieldResult F1 = Schema.sObjectType.Lead.fields.User_Type__c;
        List<Schema.PicklistEntry> P1 = F1.getPicklistValues();
        List<SelectOption> Ltype = new List<SelectOption>();
        for(Schema.PicklistEntry E1: P1){
            Ltype.add(new SelectOption(E1.getValue(), E1.getLabel()));
        }
    return Ltype;
    }
  public List<Selectoption> cities{get;set;}
  public PageReference findROCities(){
    cities = new list<Selectoption>();
    System.debug('Area---'+Area);
    try{
      for(Geo_Level_3__c ci: [Select g.MRKT_ID__c, g.Id, g.Geo_Level_2__c, Name From Geo_Level_3__c g
                  where Geo_Level_2__c =: Area and MRKT_ID__c =: this.marketId order by Name limit 998])
        {
          //String city_area = g4.Geo_Level_3__r.Name+'-'+g4.Geo_Level_3__r.Geo_Level_2__r.Name;
          cities.add(new Selectoption(ci.Id, ci.Name));
        }
    }catch(exception e){
      
    }
    return null;
  }
  public Pagereference findCities(){
    cities = new list<Selectoption>();
    try{
      for(Geo_Level_4__c g4:  [Select g.Name, g.MRKT_ID__c, g.Id, g.Geo_Level_3__r.Geo_Level_2__c, g.Geo_Level_3__r.Geo_Level_2__r.Name, 
                        g.Geo_Level_3__r.Name, g.Geo_Level_3__c From Geo_Level_4__c g 
                        where Name =:zipcode and MRKT_ID__c =: ALMPlusConstants.POLAND_MKT_ID order by Geo_Level_3__r.Name])
        {
          //String city_area = g4.Geo_Level_3__r.Name+'-'+g4.Geo_Level_3__r.Geo_Level_2__r.Name;
          cities.add(new Selectoption(g4.Geo_Level_3__c,g4.Geo_Level_3__r.Name));
        }
      
    }catch(exception e){
      System.debug('no cities found');
    }
    return null;
  }
  public PageReference submit(){
    try{
      Geo_Level_4__c currGeo = [Select g.Name, g.MRKT_ID__c, g.Id, g.Geo_Level_3__r.Geo_Level_2__r.Geo_Level_1__c, g.Geo_Level_3__r.Geo_Level_2__r.Geo_Level_1__r.Name,
                          g.Geo_Level_3__r.Geo_Level_2__c, g.Geo_Level_3__r.Geo_Level_2__r.Name, 
                          g.Geo_Level_3__r.Name, g.Geo_Level_3__c From Geo_Level_4__c g 
                          where Name =:zipcode and MRKT_ID__c =: ALMPlusConstants.POLAND_MKT_ID and Geo_Level_3__c =:city]; 
      Lead currLead = new Lead();
      currLead.Creation_QRTR__c = currMarket.CURRENT_QRTR__c;
          currLead.User_Type__c = leadType;
          currLead.FirstName = fName;
          currLead.LastName = lName;
          currLead.Company = 'NA';  //CRF: use constant
          currLead.Market__c = currMarket.Id;
          currLead.MRKT_ID__c = ALMPLusConstants.POLAND_MKT_ID;
          currLead.Creation_CMPGN_NR__c = currMarket.CMPGN_NR__c;
          currLead.Is_Consent_Received__c = true;
          currLead.Channel__c = 'Online';
          currLead.Geo_Level_1__c = currGeo.Geo_Level_3__r.Geo_Level_2__r.Geo_Level_1__c;
          currLead.Geo_Level_2__c = currGeo.Geo_Level_3__r.Geo_Level_2__c;
          currLead.Geo_Level_3__c = city;
          currLead.Geo_Level_4__c = currGeo.Id;
          wLead.geoLevel1Name = currGeo.Geo_Level_3__r.Geo_Level_2__r.Geo_Level_1__r.Name;
          wLead.geoLevel2Name = currGeo.Geo_Level_3__r.Geo_Level_2__r.Name;
          wLead.geoLevel3Name = currGeo.Geo_Level_3__r.Name;
          wLead.geoLevel4Name = zipcode;
          currLead.Email = email;
          currLead.Confirm_Email__c = confEmail;
          if(mobile.trim()!='' && mobile != null)
          {
              currLead.MobilePhone = mobile.replaceAll('-','').replaceAll(' ','');
          }
          if(note != System.Label.Comments){
              currLead.Description = note;    
          }
          currLead.Preferred_Language__c = userLang;
          currLead.Type__c = 'AGL';
          Date bdate = date.valueOf('1900-1-1');
          currLead.Birthday__c = bdate;
          //invoke lead validation method
          System.debug('input lead--'+currLead);
          List<String> validationErrs = LeadValidation.isMandatoryFields(currLead);
          System.debug('validationErrs--'+validationErrs);
          if(validationErrs.size()>0){
              allReqField = false;
              for(Integer e=0;e<validationErrs.size();e++){
                  Apexpages.addMessage(new Apexpages.Message(ApexPages.Severity.FATAL, validationErrs[e]));
              }
          }else if((currLead.Email != null &&  currLead.Email != '') && (currLead.Confirm_Email__c != null && currLead.Confirm_Email__c !='' ) && (currLead.Email.trim() != currLead.Confirm_Email__c.trim())){
              Apexpages.addMessage(new Apexpages.Message(ApexPages.Severity.FATAL, System.label.LnoEmailMatch));
          }else{
            //Duplicate check
              Lead dupLead = LeadDuplicateCheck.isDuplicateLead(currLead);
              System.debug('dupLead--'+dupLead);
              if(dupLead == null){
                //if no duplicate found 
                  System.debug('currLead--'+currLead);
                  //List<Lead> distLst = new List<Lead>();
                  //distLst.add(lead);
                  wLead.l = currLead;
                  List<LeadsDistribution.LeadWrapper> wLeadsToDistribute = new List<LeadsDistribution.LeadWrapper>{wLead};
                  //Distribution logic
                  DistributionResult distResult = LeadsDistribution.distributeLeads(wLeadsToDistribute, false);
                  if(distResult != null){
                      List<Lead> updLead = distResult.leads;
                      if(updLead.size()>0){
                          System.debug('Lead after distribution logic--'+updLead);
                          try{
                              //after distribution insert lead
                              insert updLead[0];
                              //notify lead and the owner
                              System.debug('distResult PR Cont-->'+distResult);
                              sendNotifications(updLead[0], distResult.notifications);                            
                              PageReference pageRef = Page.LeadConfirmation;
                              pageRef.getParameters().put('langcd',this.userLang);
                              //PageReference conf1 = new PageReference('apex/LeadConfirmation?langcd='+this.userLang);
                                      //PageReference conf1 = Page.LeadConfirmation;
                              return pageRef;
                          }catch(exception ex){
                              System.debug('error--'+ex);
                          }
                      }
                  }
              }else{
                  //If duplicate lead is found
                  //check if lead age is <Primary_Lead_Distribution_Age__c hrs
                  //if(dupLead.Age__c > currMarket.Primary_Lead_Distribution_Age__c){
                  //    unattendedLead(dupLead);
                  //}
                  //else{
                      System.debug('duplicate lead age < Primary_Lead_Distribution_Age__c');
                      //display duplicate lead confirmation page
                      //PageReference dup = new PageReference('apex/LeadDuplicate?langcd='+this.userLang);
                      PageReference pageRef = Page.LeadDuplicate;
                      pageRef.getParameters().put('langcd',this.userLang);
                      //PageReference dup = Page.LeadDuplicate;
                      return pageRef;
                  //}
                }
          }
    }catch(exception e){
      
    }
    return null;
  }
  private void sendNotifications(Lead l, List<LeadNotification> notifications){
        System.debug('inside PR Cont sendnotifications mtd'+notifications);
        for(LeadNotification n: notifications){
            n.leadId = l.Id;
        }
        try{
        LeadNotificationManager nManager = new LeadNotificationManager(notifications);
        nManager.notify();
    }
        catch(Exception e){
            System.debug('Notification failed: ' + e);
        }
    }
}

Any help will be useful to me.

Thanks,
Dip.

Hi,

 

I have two fields in visualforce page. one is zip code which is a text field and other is city which is a picklist field. My requirement is that if I will enter the zip code value in text field zip code, the city picklist should be dynamically auto populated based on the zip code. 

how it can be done?

 

Any help will be appreciated.

 

Thanks,

Dipak

Hi,

 

I have created a custom object in which a custom field receiving time of data type text is created. When I go to insert the record in the custom object with receiving time in the format like 10:40 or 10:40 PM, I am unable to get this format after insertion of record. I get the decimal value in the receiving time field instead of given value. What can be the reason behind this?

 

Any suggestion will be helpful.

 

Thanks,

 

 

Hi,

 

I want to update the Parent Account Lookup field in account record using after insert and after update trigger. The condition to update the parent account lookup field is that if recruiter id of account record matches with the parent account the corresponding record will be updated in parent account lookup field of account record.

I am trying with the following code but getting error:

 

trigger UpdateParentAccountInAccount on Account(after insert, after update)
{
    List<string> lst_RecID= new List<string>();
    Map<String, Id> map_ParentAccounts = new Map<String, Id>();
   
    for(Account acct : Trigger.new)
    {
        lst_RecID.add(acct.Recruiter_ID__c);
    }
   
    for(Parent p : [  Select Id,
                                    Recruiter_ID__c
                               From Parent
                              Where Recruiter_ID__c In :lst_RecID])
    {
        map_ParentAccounts.put(p.Recruiter_ID__c , p.Id);
    }
   
    for(Account acct : Trigger.new)
    {                          
        if(map_ParentAccounts.containsKey(acct.Recruiter_ID__c) == true)
        {
            acct.Parent = map_ParentAccounts.get(acct.Recruiter_ID__c);
        }
         else
        {
            //throw error ...
           
           // adb.addError('You can\'t insert Active_Database record without Account Number!');
            return;
        }      
    }   
}

 

 

Any suggestion will be helpful for me.

 

Thanks,

Hi,

 

I have written the following test class:

 

@isTest
public class Test_tgrActuator
{
    static testMethod void caseAssignmentAndEscalation_Test()
    {
        Case c = new Case();

        Account aa = new Account();
        aa.Name = 'Test';
        aa.Address__c = 'Kolkata';
        aa.Account_Number__c = '293848343';
        insert aa;
        
        User u = new User();
        u.lastname = 'TestUser';
        u.Username = 'TestUser@user.com';
        u.Alias = 'TUse';
        u.CommunityNickname = 'TestUse';
        //u.TimeZoneSidKey = '(GMT+05:30)';
        u.LocaleSidKey = 'English (United States)';
        u.EmailEncodingKey = 'General US & Western Europe (ISO-8859-1, ISO-LATIN-1)';
        u.LanguageLocaleKey = 'English';
        u.email = 'test@test.com';
        u.city = 'Kolkata';
        u.department = 'PPS';
        insert u;
       
        Case_Category__c caseCategoryParent = new Case_Category__c();
        Case_Category__c caseCategoryCaseSubType = new Case_Category__c();
        Case_Category__c caseCategoryMapType = new Case_Category__c();
        Case_Category__c caseCategoryMapSubType = new Case_Category__c();    
        //Attachment a = new Attachment();
        //List<Steps__c> s = new List<Steps__c>();
        
        Id id_1 = [Select Id from RecordType WHERE Name='Case Type'].Id;
        Id id_2 = [Select Id from RecordType WHERE Name='Case Subtype'].Id;
        Id id_3 = [Select Id from RecordType WHERE Name='Map Type'].Id;
        Id id_4 = [Select Id from RecordType WHERE Name='Map Subtype'].Id;
                        
        //aId = aa.Id;
        caseCategoryParent.RecordTypeId = id_1 ;
        caseCategoryParent.Name = 'Request';
        insert caseCategoryParent;
        
        caseCategoryCaseSubType.RecordTypeId = id_2 ;
        caseCategoryCaseSubType.Parent__c = caseCategoryParent.Id;
        caseCategoryCaseSubType.Name = 'Reset Password';
        insert caseCategoryCaseSubType;
        
        caseCategoryMapType.RecordTypeId = id_3;
        caseCategoryMapType.Parent__c = caseCategoryCaseSubType.Id;
        caseCategoryMapType.Name = 'Reset the Password of GSL Report';
        caseCategoryMapType.Department__c = 'PPS';
        insert caseCategoryMapType;        
        
        Assignment_Rule__c assignByLoc = new Assignment_Rule__c();
        assignByLoc.Name = 'Assign By Location';
        assignByLoc.Case_Category__c = caseCategoryMapType.Id;
        assignByLoc.Assign_By__c = 'Location';
        assignByLoc.Criteria__c = 'Kolkata';
        assignByLoc.Priority__c = 1;
        insert assignByLoc;
        
        Mail_To__c assignmentQueue = new Mail_To__c();
        assignmentQueue.Assignment_Rule__c = assignByLoc.Id;
        assignmentQueue.User__c = u.Id;
        
     }     
}

 

 

When I run this test class, I get the following error:

 

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Locale: bad value for restricted picklist field: English (United States): [LocaleSidKey]

Is there any format to write time zone and locale picklist value in test class?

 

 

Any help will be appreciated.

Hi,

Whenever I am going to run the folowing batch I get the error 'First error: unexpected token: '{''. The batch is :

global class ZmDmAttachmentCleanupBatch implements Database.Batchable<SObject>, Database.Stateful{

private List<Id> ZmDmAttachmentIds;

private String MarketCleanupId;

public ZmDmAttachmentCleanupBatch() {
        //do nothing   
    }

   
public ZmDmAttachmentCleanupBatch(List<Id> ZmDmAttachmentIds) {
        this.ZmDmAttachmentIds = ZmDmAttachmentIds;
    }
   
public ZmDmAttachmentCleanupBatch(String MarketId) {
        this.MarketCleanupId = MarketId;
    }  

    global Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator(prepareSOQL());
    }

    global void execute(Database.BatchableContext bc, List<Attachment> rows){
            delete rows;
           DataBase.emptyRecycleBin(rows);    
    }
   
    global void finish(Database.BatchableContext bc){
     String CleanupLastRun;
     datetime myDateTime = datetime.now();
     String myDateStr = String.ValueOf(myDateTime);
     Market__c mkt = [select Id,Cleanup_Last_Run__c from market__c
                                                        where Market_Id__c=:MarketCleanupId];

         String CleanupLastRun1 = mkt.Cleanup_Last_Run__c;
         String CleanupLastRun2 = CleanupLastRun1+'Attachment:'+myDateStr;             
        // mkt.Cleanup_Last_Run__c = 'Attachment:'+myDateStr;
              
           update mkt;
          
           Database.executeBatch(new SlAttachmentCleanupBatch('73'),2000);
        System.debug('job finished.');
     
    }
   
    public static void startJob() {
        scheduleJob(2);
    }
   
   
    private String prepareSOQL() {
     
       Market__c mrkt = [select PREV_1_CMPGN_NR__c,X90_Day_Camp_CNT__c from market__c
                                                     where Market_Id__c=:MarketCleanupId];
       List<CDW_Market_Report__c> Parent_id = [select id from CDW_Market_Report__c
                                                      where Market__r.Market_Id__c=:MarketCleanupId];
             system.debug('parent id'+Parent_id);
      
      // List<SObject> results = Database.query(someSOQL);
       Set<Id> resultIds = (new Map<Id,CDW_Market_Report__c>(Parent_id)).keySet();
      // Set<Id> resultIds = new Set<Id> (new Map<Id,CDW_Market_Report__c>(Parent_id).keySet());
      // Set<String> resultIds = (new Map<String,CDW_Market_Report__c>(Parent_id)).keySet();      
       List<Calendar__c> camp = [select CMPGN_NR__c,CMPGN_STRT_DT__c from Calendar__c
                                                    where MRKT_ID__c = :MarketCleanupId order by CMPGN_NR__c desc];

          Integer index = -1;
         
          Integer CampaignIndex=6;

       List<String> Camps=new List<String>();
      
          for(Calendar__c ca: camp){
            Camps.add(String.valueOf(ca.CMPGN_NR__c));
          }

          for(Integer m = 0; m<Camps.size();m++){
             IF(Camps[m].equalsignorecase(mrkt.PREV_1_CMPGN_NR__c)){
             index = m;
             System.debug('index='+ index);
             break;       
             }
          }
       Calendar__c PrevCmpgnStr1=camp[index+CampaignIndex];
              system.debug('final campaign'+ PrevCmpgnStr1);
  
               date startdate= PrevCmpgnStr1.CMPGN_STRT_DT__c;
               Datetime dt = datetime.newInstance(startdate.year(), startdate.month(),startdate.day(),00,00,00);

     // List<Attachment> atc = [select Id from Attachment where ParentId In :resultIds and LastModifiedDate<:dt];
     
     // system.debug('attachmentis'+ atc);

      // String PrevCmpgnStr=Camps[index+CampaignIndex];
      
      String sql = 'SELECT Id FROM Attachment ';
                
           // sql += ' where ParentId In :\''+resultIds+'\' and LastModifiedDate<:\''+dt+'\'';
            sql += ' where ParentId In :'+resultIds+' and LastModifiedDate<:'+dt+'';
           
       system.debug('queryis'+ sql);           
      return sql;
     
    }
   
   
    private Set<String> fetchEligibleMarketCodes() {
        Set<String> marketCodes = new Set<String>();
        for (Market__c market : [Select Market_Id__c from Market__c where Is_ALMPLUS_Enabled__c=true]) {
            marketCodes.add(market.Market_Id__c);
        }
        System.debug('eligible market codes: ' + marketCodes);
        return marketCodes;
    }
   
    private static void scheduleJob(Integer minutesOffset) {
        DateTime currentTime = System.now();
        String scheduleTime = ALMPlusUtils.prepareJobsSchTime(currentTime, minutesOffset); 
        String uniqueJobName = ALMPlusUtils.getUniqueJobName('ZmDmAttachmentCleanupBatch');
        String cronID = System.schedule(uniqueJobName, scheduleTime, new BatchJobScheduler(new ZmDmAttachmentCleanupBatch(), 1000));  //use 10 as the batch size         
    }
   
    //ZmDmAttachmentCleanupBatch zda=new ZmDmAttachmentCleanupBatch('73');
    //zda.startJob();
   
   
}

Can anybody tell me where I am missing in the code.

Regards,
Dip

Hi,

 

I want to update the Parent Account Lookup field in account record using after insert and after update trigger. The condition to update the parent account lookup field is that if recruiter id of account record matches with the parent account the corresponding record will be updated in parent account lookup field of account record.

I am trying with the following code but getting error:

 

trigger UpdateParentAccountInAccount on Account(after insert, after update)
{
    List<string> lst_RecID= new List<string>();
    Map<String, Id> map_ParentAccounts = new Map<String, Id>();
   
    for(Account acct : Trigger.new)
    {
        lst_RecID.add(acct.Recruiter_ID__c);
    }
   
    for(Parent p : [  Select Id,
                                    Recruiter_ID__c
                               From Parent
                              Where Recruiter_ID__c In :lst_RecID])
    {
        map_ParentAccounts.put(p.Recruiter_ID__c , p.Id);
    }
   
    for(Account acct : Trigger.new)
    {                          
        if(map_ParentAccounts.containsKey(acct.Recruiter_ID__c) == true)
        {
            acct.Parent = map_ParentAccounts.get(acct.Recruiter_ID__c);
        }
         else
        {
            //throw error ...
           
           // adb.addError('You can\'t insert Active_Database record without Account Number!');
            return;
        }      
    }   
}

 

 

Any suggestion will be helpful for me.

 

Thanks,