You need to sign in to do that
Don't have an account?
Dipak@pvs
Problem in writing test class
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,
Are you facing problem in some specific part of class? To get started the below is useful link ->
http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods