-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
6Questions
-
3Replies
test save and cancel method in test class
Controller
public Class LogAcallController{
private ApexPages.StandardController con;
public class DataException extends Exception {}
public Boolean isError = FALSE;
public String whatId = ApexPages.CurrentPage().getParameters().get('what_Id');
public String leadId = ApexPages.CurrentPage().getParameters().get('lead_id');
public string WhoID=ApexPages.CurrentPage().getParameters().get('who_id');
public Lead LeadData;
public String retURL = ApexPages.CurrentPage().getParameters().get('id');
public String parentId;
public Task logACall {get;set;}
public list<Task> TaskList{get;set;}
public Task followUpTask {get;set;}
public Boolean createFollowUpTask {get;set;}
public LogAcallController(){
String queryString = GeneralUtilityClass.getQueryString('Lead');
queryString += ' From Lead WHERE Id =: leadId ';
LeadData= dataBase.query(queryString);
if(WhoId !=null){
parentId = LeadData.Id;
}
else{
parentId = WhatID;
}
TaskList =new List<Task>();
logACall = new Task();
logACall.WhoID=LeadData.id;
logACALL.lEAD__C=LeadData.Id;
logACall.Subject = 'Transferred';
logACall.Task_Type__c = 'Inbound';
followUpTask = new Task();
followUpTask.WhoID=LeadData.id;
createFollowUpTask = FALSE;
Map<String, String> taskRecordTypeMap = new Map<String, String>();
for(Schema.RecordTypeInfo r :Task.SObjectType.getDescribe().getRecordTypeInfos()){
taskRecordTypeMap.put(r.getName(), r.getRecordTypeId());
}
Task logACall = new Task();
logACall.whatId =whatId;
logACall.RecordTypeId = taskRecordTypeMap.get('Call');
logACall.WhoId = WhoId;
}
public PageReference save(){
try{
isError=false;
validateData();
if(isError == TRUE ){
throw new DataException(ErrorMessages.REVIEW_ERROR_MESSAGE);
}
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
return null;
}
try{
Savepoint sp = Database.setSavepoint();
database.insert(logACall); // insert logACall ;
PageReference pr = new pageReference('/'+leadId);
pr.setRedirect(true);
return pr;
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
return null;
}
}
public PageReference cancel(){
// PageReference pr = new pageReference(retURL);
PageReference pr = new pageReference ('/apex/LeadEditOverridePage?retURL=/'+leadId+'&id='+leadId);
// PageReference pr = new pageReference(retURL);
pr.setRedirect(true);
return pr;
}
public Boolean validateData() {
isError =False;
if(logACall.Attended_By__c==null) {
logACall.Attended_By__c.addError('Please Enter Attended By Fields');
isError = TRUE;
}
if(logACall.Call_Status__c!='Transferred') {
logACall.Call_Status__c.addError('Please Enter Call Status as Transferred');
isError = TRUE;
}
if(logACall.Call_Status__c=='Transferred' && (logACall.Transferred_To__c==null || logACall.Transferred_To__c=='' )) {
logACall.Transferred_To__c.addError('Please Enter a value');
isError = TRUE;
}
return isError;
}
}
TEST CLASSS
@isTest(seeAllData=false)
private class LogAcallController_TestClass
{
private static Lead newLead;
private static Campaign newCampaign;
private static Task newTask;
private static Task newLogACall;
private static Task newAnotherTask;
private static User newUser;
private static void init() {
newUser = InitializeTestData.createUser('cgpet00D900000010QJQ.test@demmo.com.test');
database.insert(newUser);
newCampaign = InitializeTestData.createCampaign();
database.insert(newCampaign);
newLead = InitializeTestData.createLeadWebsite(newCampaign.Id);
newLead.DecisionMaker__c='Self';
newLead.IsConverted = FALSE;
database.insert(newLead);
newLogACall=InitializeTestData.createLeadLogACall(newLead.Id,newUser.Id);
database.insert(newLogACall);
System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+newLead.Id);
}
private static TestMethod void Test1() {
init();
Test.StartTest();
PageReference pageRef = Page.LogACallPageNew; // Add your VF page Name here
pageRef.getParameters().put('who_id', String.valueOf(newLead.Id));
pageRef.getParameters().put('lead_id', String.valueOf(newLead.Id));
pageRef.getParameters().put('what_Id','');
Test.setCurrentPage(pageRef);
// PageReference testPage = testAccPlan.save();
LogAcallController taskinfo= new LogAcallController();
taskInfo.parentId = newLead.Id;
taskInfo.logACall = newLogACall;
taskInfo.createFollowUpTask = TRUE;
taskinfo.save();
taskinfo.cancel();
// testAccPlan.save();
// testAccPlan.cancel();
Test.StopTest();
}
}
public Class LogAcallController{
private ApexPages.StandardController con;
public class DataException extends Exception {}
public Boolean isError = FALSE;
public String whatId = ApexPages.CurrentPage().getParameters().get('what_Id');
public String leadId = ApexPages.CurrentPage().getParameters().get('lead_id');
public string WhoID=ApexPages.CurrentPage().getParameters().get('who_id');
public Lead LeadData;
public String retURL = ApexPages.CurrentPage().getParameters().get('id');
public String parentId;
public Task logACall {get;set;}
public list<Task> TaskList{get;set;}
public Task followUpTask {get;set;}
public Boolean createFollowUpTask {get;set;}
public LogAcallController(){
String queryString = GeneralUtilityClass.getQueryString('Lead');
queryString += ' From Lead WHERE Id =: leadId ';
LeadData= dataBase.query(queryString);
if(WhoId !=null){
parentId = LeadData.Id;
}
else{
parentId = WhatID;
}
TaskList =new List<Task>();
logACall = new Task();
logACall.WhoID=LeadData.id;
logACALL.lEAD__C=LeadData.Id;
logACall.Subject = 'Transferred';
logACall.Task_Type__c = 'Inbound';
followUpTask = new Task();
followUpTask.WhoID=LeadData.id;
createFollowUpTask = FALSE;
Map<String, String> taskRecordTypeMap = new Map<String, String>();
for(Schema.RecordTypeInfo r :Task.SObjectType.getDescribe().getRecordTypeInfos()){
taskRecordTypeMap.put(r.getName(), r.getRecordTypeId());
}
Task logACall = new Task();
logACall.whatId =whatId;
logACall.RecordTypeId = taskRecordTypeMap.get('Call');
logACall.WhoId = WhoId;
}
public PageReference save(){
try{
isError=false;
validateData();
if(isError == TRUE ){
throw new DataException(ErrorMessages.REVIEW_ERROR_MESSAGE);
}
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
return null;
}
try{
Savepoint sp = Database.setSavepoint();
database.insert(logACall); // insert logACall ;
PageReference pr = new pageReference('/'+leadId);
pr.setRedirect(true);
return pr;
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
return null;
}
}
public PageReference cancel(){
// PageReference pr = new pageReference(retURL);
PageReference pr = new pageReference ('/apex/LeadEditOverridePage?retURL=/'+leadId+'&id='+leadId);
// PageReference pr = new pageReference(retURL);
pr.setRedirect(true);
return pr;
}
public Boolean validateData() {
isError =False;
if(logACall.Attended_By__c==null) {
logACall.Attended_By__c.addError('Please Enter Attended By Fields');
isError = TRUE;
}
if(logACall.Call_Status__c!='Transferred') {
logACall.Call_Status__c.addError('Please Enter Call Status as Transferred');
isError = TRUE;
}
if(logACall.Call_Status__c=='Transferred' && (logACall.Transferred_To__c==null || logACall.Transferred_To__c=='' )) {
logACall.Transferred_To__c.addError('Please Enter a value');
isError = TRUE;
}
return isError;
}
}
TEST CLASSS
@isTest(seeAllData=false)
private class LogAcallController_TestClass
{
private static Lead newLead;
private static Campaign newCampaign;
private static Task newTask;
private static Task newLogACall;
private static Task newAnotherTask;
private static User newUser;
private static void init() {
newUser = InitializeTestData.createUser('cgpet00D900000010QJQ.test@demmo.com.test');
database.insert(newUser);
newCampaign = InitializeTestData.createCampaign();
database.insert(newCampaign);
newLead = InitializeTestData.createLeadWebsite(newCampaign.Id);
newLead.DecisionMaker__c='Self';
newLead.IsConverted = FALSE;
database.insert(newLead);
newLogACall=InitializeTestData.createLeadLogACall(newLead.Id,newUser.Id);
database.insert(newLogACall);
System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+newLead.Id);
}
private static TestMethod void Test1() {
init();
Test.StartTest();
PageReference pageRef = Page.LogACallPageNew; // Add your VF page Name here
pageRef.getParameters().put('who_id', String.valueOf(newLead.Id));
pageRef.getParameters().put('lead_id', String.valueOf(newLead.Id));
pageRef.getParameters().put('what_Id','');
Test.setCurrentPage(pageRef);
// PageReference testPage = testAccPlan.save();
LogAcallController taskinfo= new LogAcallController();
taskInfo.parentId = newLead.Id;
taskInfo.logACall = newLogACall;
taskInfo.createFollowUpTask = TRUE;
taskinfo.save();
taskinfo.cancel();
// testAccPlan.save();
// testAccPlan.cancel();
Test.StopTest();
}
}
- sona gaikwad
- May 30, 2019
- Like
- 0
datetime.newinstance method now working
Test_survey surveyobj =new Test_survey();
String Test_DOBOfFamilyHead ;
surveyobj .Test_DOBOfFamilyHead__c;
Invalid identifier ' datetime.newinstance'. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_'.
surveyobj.Test_SurveyDate__c= datetime.newinstance(long.valueOf(String.valueOf(reqData.Test_Survey_Date)));
- sona gaikwad
- January 25, 2019
- Like
- 0
how to write test class for this method ---urgent
public static Boolean LeadDuplicateCheck(String contactInfo){ String searchQuery= 'FIND \'' + contactInfo.trim() + '*\' IN ALL FIELDS RETURNING Lead(Id,MobilePhone,Mobile_2__c,Whats_App_Number__c,LandLine__c,Email), Account(Id,PersonMobilePhone,Mobile_2__c,Whats_App_Number__c,LandLine__c,PersonEmail)'; List<List <sObject>> searchList= search.query(searchQuery); Lead [] leads= ((List<Lead>)searchList[0]); Account [] accounts = ((List<Account>)searchList[1]); if(leads.size()>0) { /* this line is not covered */ for(Lead lead:leads ){ if((lead.MobilePhone!=null && contactInfo.contains(lead.MobilePhone))||(lead.Mobile_2__c!=null && contactInfo.contains(lead.Mobile_2__c))||(lead.Whats_App_Number__c!=null &&contactInfo.contains(lead.Whats_App_Number__c))|| (lead.LandLine__c!=null && contactInfo.contains(lead.LandLine__c))||(lead.Email!=null && contactInfo.contains(lead.Email))) return true; //duplicate return true } /* this line is not covered */ } if(accounts.size()>0) { /* this line is not covered */ for(Account account:accounts ){ if((account.PersonMobilePhone!=null && contactInfo.contains(account.PersonMobilePhone))||(account.Mobile_2__c!=null && contactInfo.contains(account.Mobile_2__c))|| (account.Whats_App_Number__c!=null &&contactInfo.contains(account.Whats_App_Number__c))|| (account.LandLine__c!=null && contactInfo.contains(account.LandLine__c))||(account.PersonEmail!=null && contactInfo.contains(account.PersonEmail))) return true; //duplicate return true } /* this line is not covered */ } return false; } **test class** @isTest public with sharing class checkleaddetails { public static testMethod Boolean checkleadinfo () { Account c = new Account(); { RecordType personAccountRecordTypeId = [select developerName from RecordType where IsPersonType=True And DeveloperName = 'personAccount']; c.RecordtypeId = personAccountRecordTypeId.Id; c.PersonMobilePhone='9743800309'; c.LastName='Jitesh'; c.FirstName='kape'; c.Date_of_Birth__c = date.today()-2; c.Mobile_2__c='9743800309'; c.Whats_App_Number__c = '8652146259'; c.LandLine__c ='022-25412365'; c.PersonEmail = 'email@gmail.com'; insert c; } Lead leadobj=new Lead( FirstName=c.id, LastName = c.id, MobilePhone = c.id, Mobile_2__c= c.id, Whats_App_Number__c= c.Whats_App_Number__c, LandLine__c= c.LandLine__c, Email= c.PersonEmail); insert leadobj ; Test.StartTest(); LeadHandlerClass.LeadDuplicateCheck(leadobj.MobilePhone); LeadHandlerClass.LeadDuplicateCheck(leadobj.Mobile_2__c); LeadHandlerClass.LeadDuplicateCheck(leadobj.Whats_App_Number__c); LeadHandlerClass.LeadDuplicateCheck(leadobj.LandLine__c); LeadHandlerClass.LeadDuplicateCheck(leadobj.Email); LeadHandlerClass.CCHelp(); Test.StopTest(); return false ; } }
- sona gaikwad
- January 08, 2019
- Like
- 0
test class for not covering line where Product_Category__c ='VC'
public pageReference saveMethod(){ try{ isError = FALSE; validateData(); if(leadinfo.Lead_Sub_Stage__c == 'Booked' && fromSaveNConvert == false){ leadinfo.Lead_Sub_Stage__c.addError('Please Click on Save and Convert Button'); isError = True; createLogACall = true; } if(isError == TRUE && createLogACall ==TRUE ){ fromSaveNConvert = false; throw new DataException(ErrorMessages.REVIEW_ERROR_MESSAGE); } } catch(exception e){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage())); return null; } Savepoint sp = Database.setSavepoint(); try { pageReference pr; if(campaignId.length()!=0) { leadinfo.Campaign__c = campaignId; } if(leadinfo.Product_Category__c=='VC'){ leadinfo.Direct_VC__c=TRUE; } if(leadchatlog == TRUE){ } leadinfo.Modified_Date_Time__c = System.today(); leadinfo.Is_LastCall_Inbound__c= logACall.Inbound_Call__c; leadinfo.Lead_Assigned__c=FALSE; if(leadinfo.Product_Category__c =='CWR' || leadinfo.Product_Category__c =='Corporate CWR'){ leadinfo.Enquiry_Type__c ='CWR Enquiry'; } if(leadinfo.Product_Category__c =='VC' ||leadinfo.Product_Category__c =='Corporate VC'){ leadinfo.Enquiry_Type__c ='Direct VC'; } if(leadinfo.Product_Category__c =='Plan/CWR'){ leadinfo.Enquiry_Type__c ='Plan Enquiry'; } insert leadinfo; if(createLogACall == TRUE ){ FollowUpTasksValidationController.insertLogACall(logACall, leadinfo.Id, TRUE); } if(createFollowUpTask == TRUE){ FollowUpTasksValidationController.insertFollowUpTask(followUpTask, leadinfo.Id); } pr = new pageReference('/'+leadinfo.id); pr.setRedirect(true); return pr; /* pr = new pageReference ('/apex/ProductNewOverridePage?retURL=/'+leadinfo.id+'&id='+leadinfo.id+'&isConvert='+isConvert); pr.setRedirect(true); return pr; */ } catch(Exception e) { leadinfo=leadinfo.clone(false,false); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage())); Database.rollback(sp); return null; } }
private static Testmethod void mytest() { Test.startTest(); init(); Apexpages.StandardController sc = new Apexpages.standardController(anothernewLead); ApexPages.currentPage().getParameters().put('retUrl',anothernewLead.Id); LeadNewOverrideExtension leadinfo = new LeadNewOverrideExtension(sc); leadinfo.leadinfo = anothernewLead; leadinfo.createFollowUpTask = TRUE; leadinfo.createLogACall = TRUE; leadinfo.campaignId =newCampaign.Id; leadinfo.followUpTask =NewTask; leadInfo.logACall = LogACallNew; leadInfo.showASD = TRUE; leadInfo.showPreferedDate = FALSE; leadInfo.getDays(); leadInfo.getTimeSlots(); leadInfo.ASDAvilability(); leadInfo.saveMethod(); leadInfo.leadchatlog = TRUE; LeadNewOverrideExtension.getVillageCityAutocomplete('Vitave','Chandwad'); LeadNewOverrideExtension.getCountryAutocomplete('India'); LeadNewOverrideExtension.getStateAutocomplete('Maharashtra','India'); LeadNewOverrideExtension.getdistrictAutocomplete('Nashik','Maharashtra'); LeadNewOverrideExtension.getTalukaAutocomplete('Chandwad','Nashik'); LeadNewOverrideExtension.getVillageCityAutocompleteupdate('Vitave','Chandwad'); LeadNewOverrideExtension.getCountryAutocompleteupdate('India'); LeadNewOverrideExtension.getStateAutocompleteupdate('Maharashtra','India'); LeadNewOverrideExtension.getDistrictAutocompleteupdate('Nashik','Maharashtra'); LeadNewOverrideExtension.getTalukaAutocompleteupdate('Chandwad','Nashik'); LeadNewOverrideExtension.getPhoneNumbersList('9988776243',''); LeadNewOverrideExtension.getZoneAutocomplete('Vitave'); LeadNewOverrideExtension.getZoneAutocompleteupdate('Vitave'); LeadNewOverrideExtension.getCampaigns('TV Program','TV Program'); LeadNewOverrideExtension.getCampaignsUpdate('TV Program','TV Program'); LeadNewOverrideExtension.getPhoneNumbersList('9988776243',anothernewLead.Id); ApexPages.currentPage().getParameters().put('returl','textUrl'); leadInfo.cancel(); Test.StopTest(); }
// initializing Fields values public static Lead createAnotherNewLead(String campaignId) { Lead newLead = new Lead(); newLead.firstName='Suresh'; newLead.LastName='Narayanarao'; newLead.Email = 'Suresh@mail.com'; newLead.MobilePhone = '9988776243'; newLead.Product_category__c ='VC'; newLead.LeadSource='TV Program'; newLead.Mobile_2__c = '7656876899'; newLead.campaign__c = campaignId; newLead.Lead_Sub_stage__c = 'Booked'; newLead.Date_of_Birth__c = Date.today()-2; newLead.Prefered_date_and_Time__c = Date.today()+2; newLead.Advanced_Schedule_Date_Value__c='14/01/19'; newLead.Time_Slot_Value__c= ''; newLead.Prop_City_Village__c ='Vitave'; newLead.Com_State__c = 'Maharashtra'; newLead.Prop_State__c = 'Maharashtra'; newLead.Prop_Taluka__c = 'Chandwad'; newLead.Com_Taluka__c = 'Chandwad'; newLead.Prop_Country__c = 'India'; newLead.Number_of_Times_Contacted__c = 0; newLead.IsConverted = False; return newLead ;
- sona gaikwad
- January 02, 2019
- Like
- 0
how to write test class for below methods
public void validateData() {
Boolean isErrorLogACall = FALSE;
Boolean isErrorFollowUpTask = FALSE;
Boolean isErrorOpenTasks = FALSE;
Boolean PropState;
if(AccountInfo.PersonMobilePhone!=null && AccountInfo.PersonMobilePhone!='')
{
if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.PersonMobilePhone,AccountInfo.Id))
{
System.debug('Duplicate Mobile 1: ');
AccountInfo.PersonMobilePhone.addError('Duplicate : '+AccountInfo.PersonMobilePhone);
isError = TRUE;
return;
}
}
if(AccountInfo.Mobile_2__c !=null && AccountInfo.Mobile_2__c!='')
{
if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.Mobile_2__c ,AccountInfo.Id))
{
AccountInfo.Mobile_2__c.addError('Duplicate : '+AccountInfo.Mobile_2__c );
isError = TRUE;
return;
}
}
if(AccountInfo.PersonEmail!=null &&AccountInfo.PersonEmail!='')
{
if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.PersonEmail,AccountInfo.Id))
{
AccountInfo.PersonEmail.addError('Duplicate : '+AccountInfo.PersonEmail);
isError = TRUE;
return;
}
}
//JJ - 04/27/2016
if(AccountInfo.City_Village__c != null && AccountInfo.City_Village__c != '')
{
List<Village_City__c> lstCityVill = new List<Village_City__c>();
lstCityVill = HandlerClass.getVillageCityAutocomplete(AccountInfo.City_Village__c, '');
//Case Sensitive Logic
for(Village_City__c recTaluka :lstCityVill)
{
PropState = AccountInfo.City_Village__c.equals(recTaluka.Name);
if(PropState) break;
}
//Case Sensitive Logic - End.
if(lstCityVill.isEmpty())
{
AccountInfo.City_Village__c.addError('This Communication City/Village value is not available.');
isError = true;
}
else if(PropState == FALSE)
{
AccountInfo.City_Village__c.addError('This Case Sensitive Communication City/Village value is not available.');
isError = true;
}
}
}
Boolean isErrorLogACall = FALSE;
Boolean isErrorFollowUpTask = FALSE;
Boolean isErrorOpenTasks = FALSE;
Boolean PropState;
if(AccountInfo.PersonMobilePhone!=null && AccountInfo.PersonMobilePhone!='')
{
if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.PersonMobilePhone,AccountInfo.Id))
{
System.debug('Duplicate Mobile 1: ');
AccountInfo.PersonMobilePhone.addError('Duplicate : '+AccountInfo.PersonMobilePhone);
isError = TRUE;
return;
}
}
if(AccountInfo.Mobile_2__c !=null && AccountInfo.Mobile_2__c!='')
{
if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.Mobile_2__c ,AccountInfo.Id))
{
AccountInfo.Mobile_2__c.addError('Duplicate : '+AccountInfo.Mobile_2__c );
isError = TRUE;
return;
}
}
if(AccountInfo.PersonEmail!=null &&AccountInfo.PersonEmail!='')
{
if(LeadHandlerClass.AccountDuplicateCheckOnEdit(AccountInfo.PersonEmail,AccountInfo.Id))
{
AccountInfo.PersonEmail.addError('Duplicate : '+AccountInfo.PersonEmail);
isError = TRUE;
return;
}
}
//JJ - 04/27/2016
if(AccountInfo.City_Village__c != null && AccountInfo.City_Village__c != '')
{
List<Village_City__c> lstCityVill = new List<Village_City__c>();
lstCityVill = HandlerClass.getVillageCityAutocomplete(AccountInfo.City_Village__c, '');
//Case Sensitive Logic
for(Village_City__c recTaluka :lstCityVill)
{
PropState = AccountInfo.City_Village__c.equals(recTaluka.Name);
if(PropState) break;
}
//Case Sensitive Logic - End.
if(lstCityVill.isEmpty())
{
AccountInfo.City_Village__c.addError('This Communication City/Village value is not available.');
isError = true;
}
else if(PropState == FALSE)
{
AccountInfo.City_Village__c.addError('This Case Sensitive Communication City/Village value is not available.');
isError = true;
}
}
}
- sona gaikwad
- December 14, 2018
- Like
- 0
How to write a test class for an apex trigger on lead
trigger
trigger MyTrigger on Lead (before insert,before update) {
leadhandlerclass handler =new leadhandlerclass();
if(Trigger.isInsert && Trigger.isbefore)
{
handler.UpdateLeadStatus(Trigger.new);
}
if(Trigger.isupdate && Trigger.isbefore)
{
handler.UpdateLeadStatus(Trigger.new);
}
}
Testlead
@istest
private class Testlead {
static testmethod void addressOverride(){
Lead s = new Lead();
s.stages__c = 'Booked';
leadhandlerclass handler =new leadhandlerclass();
Lead acc = new Lead (stages__c = 'Booked');
insert acc;
system.debug('----->>> stages__c: ' + acc.stages__c);
Test.startTest();
system.debug('----->>> status__c: ' + acc.status__c);
Test.stopTest();
}
}
trigger MyTrigger on Lead (before insert,before update) {
leadhandlerclass handler =new leadhandlerclass();
if(Trigger.isInsert && Trigger.isbefore)
{
handler.UpdateLeadStatus(Trigger.new);
}
if(Trigger.isupdate && Trigger.isbefore)
{
handler.UpdateLeadStatus(Trigger.new);
}
}
Testlead
@istest
private class Testlead {
static testmethod void addressOverride(){
Lead s = new Lead();
s.stages__c = 'Booked';
leadhandlerclass handler =new leadhandlerclass();
Lead acc = new Lead (stages__c = 'Booked');
insert acc;
system.debug('----->>> stages__c: ' + acc.stages__c);
Test.startTest();
system.debug('----->>> status__c: ' + acc.status__c);
Test.stopTest();
}
}
- sona gaikwad
- October 25, 2018
- Like
- 0
test save and cancel method in test class
Controller
public Class LogAcallController{
private ApexPages.StandardController con;
public class DataException extends Exception {}
public Boolean isError = FALSE;
public String whatId = ApexPages.CurrentPage().getParameters().get('what_Id');
public String leadId = ApexPages.CurrentPage().getParameters().get('lead_id');
public string WhoID=ApexPages.CurrentPage().getParameters().get('who_id');
public Lead LeadData;
public String retURL = ApexPages.CurrentPage().getParameters().get('id');
public String parentId;
public Task logACall {get;set;}
public list<Task> TaskList{get;set;}
public Task followUpTask {get;set;}
public Boolean createFollowUpTask {get;set;}
public LogAcallController(){
String queryString = GeneralUtilityClass.getQueryString('Lead');
queryString += ' From Lead WHERE Id =: leadId ';
LeadData= dataBase.query(queryString);
if(WhoId !=null){
parentId = LeadData.Id;
}
else{
parentId = WhatID;
}
TaskList =new List<Task>();
logACall = new Task();
logACall.WhoID=LeadData.id;
logACALL.lEAD__C=LeadData.Id;
logACall.Subject = 'Transferred';
logACall.Task_Type__c = 'Inbound';
followUpTask = new Task();
followUpTask.WhoID=LeadData.id;
createFollowUpTask = FALSE;
Map<String, String> taskRecordTypeMap = new Map<String, String>();
for(Schema.RecordTypeInfo r :Task.SObjectType.getDescribe().getRecordTypeInfos()){
taskRecordTypeMap.put(r.getName(), r.getRecordTypeId());
}
Task logACall = new Task();
logACall.whatId =whatId;
logACall.RecordTypeId = taskRecordTypeMap.get('Call');
logACall.WhoId = WhoId;
}
public PageReference save(){
try{
isError=false;
validateData();
if(isError == TRUE ){
throw new DataException(ErrorMessages.REVIEW_ERROR_MESSAGE);
}
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
return null;
}
try{
Savepoint sp = Database.setSavepoint();
database.insert(logACall); // insert logACall ;
PageReference pr = new pageReference('/'+leadId);
pr.setRedirect(true);
return pr;
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
return null;
}
}
public PageReference cancel(){
// PageReference pr = new pageReference(retURL);
PageReference pr = new pageReference ('/apex/LeadEditOverridePage?retURL=/'+leadId+'&id='+leadId);
// PageReference pr = new pageReference(retURL);
pr.setRedirect(true);
return pr;
}
public Boolean validateData() {
isError =False;
if(logACall.Attended_By__c==null) {
logACall.Attended_By__c.addError('Please Enter Attended By Fields');
isError = TRUE;
}
if(logACall.Call_Status__c!='Transferred') {
logACall.Call_Status__c.addError('Please Enter Call Status as Transferred');
isError = TRUE;
}
if(logACall.Call_Status__c=='Transferred' && (logACall.Transferred_To__c==null || logACall.Transferred_To__c=='' )) {
logACall.Transferred_To__c.addError('Please Enter a value');
isError = TRUE;
}
return isError;
}
}
TEST CLASSS
@isTest(seeAllData=false)
private class LogAcallController_TestClass
{
private static Lead newLead;
private static Campaign newCampaign;
private static Task newTask;
private static Task newLogACall;
private static Task newAnotherTask;
private static User newUser;
private static void init() {
newUser = InitializeTestData.createUser('cgpet00D900000010QJQ.test@demmo.com.test');
database.insert(newUser);
newCampaign = InitializeTestData.createCampaign();
database.insert(newCampaign);
newLead = InitializeTestData.createLeadWebsite(newCampaign.Id);
newLead.DecisionMaker__c='Self';
newLead.IsConverted = FALSE;
database.insert(newLead);
newLogACall=InitializeTestData.createLeadLogACall(newLead.Id,newUser.Id);
database.insert(newLogACall);
System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+newLead.Id);
}
private static TestMethod void Test1() {
init();
Test.StartTest();
PageReference pageRef = Page.LogACallPageNew; // Add your VF page Name here
pageRef.getParameters().put('who_id', String.valueOf(newLead.Id));
pageRef.getParameters().put('lead_id', String.valueOf(newLead.Id));
pageRef.getParameters().put('what_Id','');
Test.setCurrentPage(pageRef);
// PageReference testPage = testAccPlan.save();
LogAcallController taskinfo= new LogAcallController();
taskInfo.parentId = newLead.Id;
taskInfo.logACall = newLogACall;
taskInfo.createFollowUpTask = TRUE;
taskinfo.save();
taskinfo.cancel();
// testAccPlan.save();
// testAccPlan.cancel();
Test.StopTest();
}
}
public Class LogAcallController{
private ApexPages.StandardController con;
public class DataException extends Exception {}
public Boolean isError = FALSE;
public String whatId = ApexPages.CurrentPage().getParameters().get('what_Id');
public String leadId = ApexPages.CurrentPage().getParameters().get('lead_id');
public string WhoID=ApexPages.CurrentPage().getParameters().get('who_id');
public Lead LeadData;
public String retURL = ApexPages.CurrentPage().getParameters().get('id');
public String parentId;
public Task logACall {get;set;}
public list<Task> TaskList{get;set;}
public Task followUpTask {get;set;}
public Boolean createFollowUpTask {get;set;}
public LogAcallController(){
String queryString = GeneralUtilityClass.getQueryString('Lead');
queryString += ' From Lead WHERE Id =: leadId ';
LeadData= dataBase.query(queryString);
if(WhoId !=null){
parentId = LeadData.Id;
}
else{
parentId = WhatID;
}
TaskList =new List<Task>();
logACall = new Task();
logACall.WhoID=LeadData.id;
logACALL.lEAD__C=LeadData.Id;
logACall.Subject = 'Transferred';
logACall.Task_Type__c = 'Inbound';
followUpTask = new Task();
followUpTask.WhoID=LeadData.id;
createFollowUpTask = FALSE;
Map<String, String> taskRecordTypeMap = new Map<String, String>();
for(Schema.RecordTypeInfo r :Task.SObjectType.getDescribe().getRecordTypeInfos()){
taskRecordTypeMap.put(r.getName(), r.getRecordTypeId());
}
Task logACall = new Task();
logACall.whatId =whatId;
logACall.RecordTypeId = taskRecordTypeMap.get('Call');
logACall.WhoId = WhoId;
}
public PageReference save(){
try{
isError=false;
validateData();
if(isError == TRUE ){
throw new DataException(ErrorMessages.REVIEW_ERROR_MESSAGE);
}
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
return null;
}
try{
Savepoint sp = Database.setSavepoint();
database.insert(logACall); // insert logACall ;
PageReference pr = new pageReference('/'+leadId);
pr.setRedirect(true);
return pr;
}
catch(exception e){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
return null;
}
}
public PageReference cancel(){
// PageReference pr = new pageReference(retURL);
PageReference pr = new pageReference ('/apex/LeadEditOverridePage?retURL=/'+leadId+'&id='+leadId);
// PageReference pr = new pageReference(retURL);
pr.setRedirect(true);
return pr;
}
public Boolean validateData() {
isError =False;
if(logACall.Attended_By__c==null) {
logACall.Attended_By__c.addError('Please Enter Attended By Fields');
isError = TRUE;
}
if(logACall.Call_Status__c!='Transferred') {
logACall.Call_Status__c.addError('Please Enter Call Status as Transferred');
isError = TRUE;
}
if(logACall.Call_Status__c=='Transferred' && (logACall.Transferred_To__c==null || logACall.Transferred_To__c=='' )) {
logACall.Transferred_To__c.addError('Please Enter a value');
isError = TRUE;
}
return isError;
}
}
TEST CLASSS
@isTest(seeAllData=false)
private class LogAcallController_TestClass
{
private static Lead newLead;
private static Campaign newCampaign;
private static Task newTask;
private static Task newLogACall;
private static Task newAnotherTask;
private static User newUser;
private static void init() {
newUser = InitializeTestData.createUser('cgpet00D900000010QJQ.test@demmo.com.test');
database.insert(newUser);
newCampaign = InitializeTestData.createCampaign();
database.insert(newCampaign);
newLead = InitializeTestData.createLeadWebsite(newCampaign.Id);
newLead.DecisionMaker__c='Self';
newLead.IsConverted = FALSE;
database.insert(newLead);
newLogACall=InitializeTestData.createLeadLogACall(newLead.Id,newUser.Id);
database.insert(newLogACall);
System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+newLead.Id);
}
private static TestMethod void Test1() {
init();
Test.StartTest();
PageReference pageRef = Page.LogACallPageNew; // Add your VF page Name here
pageRef.getParameters().put('who_id', String.valueOf(newLead.Id));
pageRef.getParameters().put('lead_id', String.valueOf(newLead.Id));
pageRef.getParameters().put('what_Id','');
Test.setCurrentPage(pageRef);
// PageReference testPage = testAccPlan.save();
LogAcallController taskinfo= new LogAcallController();
taskInfo.parentId = newLead.Id;
taskInfo.logACall = newLogACall;
taskInfo.createFollowUpTask = TRUE;
taskinfo.save();
taskinfo.cancel();
// testAccPlan.save();
// testAccPlan.cancel();
Test.StopTest();
}
}
- sona gaikwad
- May 30, 2019
- Like
- 0
how to write test class for this method ---urgent
public static Boolean LeadDuplicateCheck(String contactInfo){ String searchQuery= 'FIND \'' + contactInfo.trim() + '*\' IN ALL FIELDS RETURNING Lead(Id,MobilePhone,Mobile_2__c,Whats_App_Number__c,LandLine__c,Email), Account(Id,PersonMobilePhone,Mobile_2__c,Whats_App_Number__c,LandLine__c,PersonEmail)'; List<List <sObject>> searchList= search.query(searchQuery); Lead [] leads= ((List<Lead>)searchList[0]); Account [] accounts = ((List<Account>)searchList[1]); if(leads.size()>0) { /* this line is not covered */ for(Lead lead:leads ){ if((lead.MobilePhone!=null && contactInfo.contains(lead.MobilePhone))||(lead.Mobile_2__c!=null && contactInfo.contains(lead.Mobile_2__c))||(lead.Whats_App_Number__c!=null &&contactInfo.contains(lead.Whats_App_Number__c))|| (lead.LandLine__c!=null && contactInfo.contains(lead.LandLine__c))||(lead.Email!=null && contactInfo.contains(lead.Email))) return true; //duplicate return true } /* this line is not covered */ } if(accounts.size()>0) { /* this line is not covered */ for(Account account:accounts ){ if((account.PersonMobilePhone!=null && contactInfo.contains(account.PersonMobilePhone))||(account.Mobile_2__c!=null && contactInfo.contains(account.Mobile_2__c))|| (account.Whats_App_Number__c!=null &&contactInfo.contains(account.Whats_App_Number__c))|| (account.LandLine__c!=null && contactInfo.contains(account.LandLine__c))||(account.PersonEmail!=null && contactInfo.contains(account.PersonEmail))) return true; //duplicate return true } /* this line is not covered */ } return false; } **test class** @isTest public with sharing class checkleaddetails { public static testMethod Boolean checkleadinfo () { Account c = new Account(); { RecordType personAccountRecordTypeId = [select developerName from RecordType where IsPersonType=True And DeveloperName = 'personAccount']; c.RecordtypeId = personAccountRecordTypeId.Id; c.PersonMobilePhone='9743800309'; c.LastName='Jitesh'; c.FirstName='kape'; c.Date_of_Birth__c = date.today()-2; c.Mobile_2__c='9743800309'; c.Whats_App_Number__c = '8652146259'; c.LandLine__c ='022-25412365'; c.PersonEmail = 'email@gmail.com'; insert c; } Lead leadobj=new Lead( FirstName=c.id, LastName = c.id, MobilePhone = c.id, Mobile_2__c= c.id, Whats_App_Number__c= c.Whats_App_Number__c, LandLine__c= c.LandLine__c, Email= c.PersonEmail); insert leadobj ; Test.StartTest(); LeadHandlerClass.LeadDuplicateCheck(leadobj.MobilePhone); LeadHandlerClass.LeadDuplicateCheck(leadobj.Mobile_2__c); LeadHandlerClass.LeadDuplicateCheck(leadobj.Whats_App_Number__c); LeadHandlerClass.LeadDuplicateCheck(leadobj.LandLine__c); LeadHandlerClass.LeadDuplicateCheck(leadobj.Email); LeadHandlerClass.CCHelp(); Test.StopTest(); return false ; } }
- sona gaikwad
- January 08, 2019
- Like
- 0