• Madhulendra
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 4
    Replies

hi

 

can anybody help me to write Test class for this Trigger

 

 

 

trigger insertIntoCustomerContactDetail on Contact (after insert)

{

 

for (Contact a : Trigger.new)

{

CustomerContactDetail__c ccd = new CustomerContactDetail__c

(

Contact__c = a.id,

First_Name__c =a.firstName,

Last_Name__c=a.lastName,

Date_Of_Birth__c = a.Date_Of_Birth__c,

Mobile_No__c = a.MobilePhone,

Email__c = a.Email__c

);

insert ccd ;

}

}

 

Thanks in Advance

 

Madhulendra

can anybody help me to write Test Method for the given code below :

 

 

 

public PageReference sendEmail()

{

ApexPages.Message sendMessage= null;

ApexPages.Message sendErrorMessage= null;Messaging.SendEmailResult[] mailResult=

null;

PageReference pages=null;

try

{

this.customerId = ApexPages.currentPage().getParameters().get('customerIdForLookup');

PageReference ForecastPdfPage=null;String thisFNAReport = ApexPages.currentPage().getParameters().get(

'Id');

customerContact = [select id,Email__c,First_Name__c,Last_Name__c from

 CustomerContactDetail__c where id = :customerId];

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage ();

if(fnaReport.Report_Type__c =='FNA Report')

{

ForecastPdfPage = Page.FNAReportAsPdf;

ForecastPdfPage.getParameters().put('Id',customerContact.id);

Blob ForecastPdfBlob = ForecastPdfPage.getContent();

Attachment a = new Attachment(parentId=customerContact.id,name=customerContact.First_Name__c + '-'+ customerContact.Last_Name__c+'-'+'FNAReport.pdf', body = ForecastPdfBlob);  insert a;

email.setSaveAsActivity(true);

email.setToAddresses(new String[]{customerContact.email__c});email.setSenderDisplayName(

'FNA Report');

email.setSubject('FNA Report For ' + customerContact.First_Name__c + ' '+customerContact.Last_Name__c);

email.setHtmlBody('Hi,' + '&nbsp;'+'<br>'+'<b>'+'&nbsp;&nbsp;'+customerContact.First_Name__c +'&nbsp;'+'<br><br>'+'</b>'+'Your FNA Report is attached with this mail'+'<br>'+'<br><br>'+'Thanks'); // Create an email attachment

Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); efa.setFileName('FNAReport.pdf');

efa.setBody(ForecastPdfBlob);

email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); mailResult = Messaging.sendEmail(

new Messaging.SingleEmailMessage[] {email});

for(Messaging.SendEmailResult er : mailResult)

if(er.isSuccess())

{

sendMessage=new ApexPages.Message(ApexPages.Severity.CONFIRM, 'Mail Sucessfully Sent to ' + customerContact.email__c);

ApexPages.addMessage(sendMessage);

}

}

 

else if(fnaReport.Report_Type__c=='Retirement Report')

{

ForecastPdfPage = Page.RetirementReportAsPdf;

ForecastPdfPage.getParameters().put('Id',customerContact.id);

Blob ForecastPdfBlob = ForecastPdfPage.getContent();

Attachment a = new Attachment(parentId=customerContact.id,name=customerContact.First_Name__c + '-'+ customerContact.Last_Name__c+'-'+'RetirementReport.pdf', body = ForecastPdfBlob);  insert a;

email.setSaveAsActivity(true);

email.setToAddresses(new String[]{customerContact.email__c});email.setSenderDisplayName(

'Retirement Report');

system.debug('***** Customer Name *****'+customerContact.First_Name__c); email.setSubject(

'Retirement Report For ' + customerContact.First_Name__c + ' '+customerContact.Last_Name__c);

email.setHtmlBody('Hi,' + '&nbsp;'+'<br>'+'<b>'+'&nbsp;&nbsp;'+customerContact.First_Name__c +'&nbsp;'+'<br><br>'+'</b>'+'Your Retirement Report is attached with this mail'+'<br>'+'<br><br>'+'Thanks'); // Create an email attachment

Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); efa.setFileName('RetirementReport.pdf');

efa.setBody(ForecastPdfBlob);

email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); mailResult = Messaging.sendEmail(

new Messaging.SingleEmailMessage[] {email});

for(Messaging.SendEmailResult er : mailResult)

if(er.isSuccess())

{

sendMessage=new ApexPages.Message(ApexPages.Severity.CONFIRM, 'Mail Sucessfully Sent to ' + customerContact.email__c);

ApexPages.addMessage(sendMessage);

}

}

}

catch(Exception e)

{

sendErrorMessage=new ApexPages.Message(ApexPages.Severity.ERROR, 'Unable to send mail to' + customerContact.email__c);

ApexPages.addMessage(sendMessage);

}

 

//return controller.view();

 return pages;

 

}

 

 

Thnaks in advance

 

Madhulendra

hi can anybody help me to write Test Method for given below code ,

 

 

 

public PageReference deleteRecord()

{ String customerId=null;

try { customerId=ApexPages.currentPage().getParameters().get('customerId');

if(customerId!=null)

{

List demo = new List(); demo = [Select id,Customer_Id__c From CustomerDemographicsDetail__c where Customer_Id__c=:customerId]; delete demo; List insuredParty = new List(); insuredParty = [Select id,Customer_Id__c From CustomerFinancialDetail__c where Customer_Id__c=:customerId]; delete insuredParty; List survivor = new List(); survivor = [Select id,Customer_Id__c From Customer_Financial_Detail1__c where Customer_Id__c=:customerId]; delete survivor; List retirement = new List(); retirement = [Select Customer_Id__c From Customer_Retirement_Detail__c where Customer_Id__c=:customerId]; delete retirement; List education = new List(); education = [Select Customer_Id__c From Customer_Educational_Goal__c where Customer_Id__c=:customerId]; delete education; List survivorNeeds = new List(); survivorNeeds = [Select Customer_Id__c From Customer_Survivor_Needs__c where Customer_Id__c=:customerId]; delete survivorNeeds; List survivorIncomeProv = new List(); survivorIncomeProv = [Select Customer_Id__c From Survivor_Income_Provision__c where Customer_Id__c=:customerId]; delete survivorIncomeProv; } } catch(Exception e) { ApexPages.addMessages(e); } return null; }

 

Thanks in advance

 

Madhulendra

hi , I have written a method updateRecord for Controller Class. the funcionality of this

method is to update record. but how I can write a Test Class for this method. can

anybody help me.

 

 

public PageReference updateRecord()

{

ApexPages.Message myMsg=null;

try

{

for(CustomerFinancialDetail__c cfd : updateInsuredParty)

{

Database.SaveResult[] sr = Database.update(updateInsuredParty);

for(Database.SaveResult sr1 : sr)

if(sr1.isSuccess())

{

myMsg = new ApexPages.Message(ApexPages.severity.CONFIRM,'Record Saved Sucessfully','');

ApexPages.addMessage(myMsg);

}

}

}

catch(Exception e)

{

   system.debug('Exception Caught --->'+e.getMessage());

}

}

}

 

Thanks in advance

I am unable to write Test Class for Trigger.

 

here is my trigger

 

this trigger fire after record inserted into Contact Object and also insert record to

CustomerContactDetails custom object. can anybody help me.

 

 

trigger insertIntoCustomerContactDetail on Contact (after update)

{

 

for (Contact a : Trigger.new)

{

CustomerContactDetail__c ccd = new CustomerContactDetail__c

(

Contact__c = a.id,

First_Name__c =a.firstName,

Last_Name__c=a.lastName,

Date_Of_Birth__c = a.Birthdate,

Mobile_No__c = a.MobilePhone,

Email__c = a.Email

);

insert ccd ;

}

}

 

Thanks in advance

Madhulendra

I am getting problem to write Test class for given trigger can anybody help me

 

here is my trigger

 

trigger TriggerAfterLeadConversion on Lead (after update)

{

for(Lead lead:Trigger.new)

{

if (Lead.IsConverted)

{

Contact con = [SELECT Id FROM Contact WHERE Contact.Id = :lead.ConvertedContactId];

con.Birthdate = lead.Date_Of_Birth__c;

con.Email=lead.Email;

update con;

}

}

}

 

Thanks in Advance

Madhulendra

hi can anybody help me to write Test Method for given below code ,

 

 

 

public PageReference deleteRecord()

{ String customerId=null;

try { customerId=ApexPages.currentPage().getParameters().get('customerId');

if(customerId!=null)

{

List demo = new List(); demo = [Select id,Customer_Id__c From CustomerDemographicsDetail__c where Customer_Id__c=:customerId]; delete demo; List insuredParty = new List(); insuredParty = [Select id,Customer_Id__c From CustomerFinancialDetail__c where Customer_Id__c=:customerId]; delete insuredParty; List survivor = new List(); survivor = [Select id,Customer_Id__c From Customer_Financial_Detail1__c where Customer_Id__c=:customerId]; delete survivor; List retirement = new List(); retirement = [Select Customer_Id__c From Customer_Retirement_Detail__c where Customer_Id__c=:customerId]; delete retirement; List education = new List(); education = [Select Customer_Id__c From Customer_Educational_Goal__c where Customer_Id__c=:customerId]; delete education; List survivorNeeds = new List(); survivorNeeds = [Select Customer_Id__c From Customer_Survivor_Needs__c where Customer_Id__c=:customerId]; delete survivorNeeds; List survivorIncomeProv = new List(); survivorIncomeProv = [Select Customer_Id__c From Survivor_Income_Provision__c where Customer_Id__c=:customerId]; delete survivorIncomeProv; } } catch(Exception e) { ApexPages.addMessages(e); } return null; }

 

Thanks in advance

 

Madhulendra

I am unable to write Test Class for Trigger.

 

here is my trigger

 

this trigger fire after record inserted into Contact Object and also insert record to

CustomerContactDetails custom object. can anybody help me.

 

 

trigger insertIntoCustomerContactDetail on Contact (after update)

{

 

for (Contact a : Trigger.new)

{

CustomerContactDetail__c ccd = new CustomerContactDetail__c

(

Contact__c = a.id,

First_Name__c =a.firstName,

Last_Name__c=a.lastName,

Date_Of_Birth__c = a.Birthdate,

Mobile_No__c = a.MobilePhone,

Email__c = a.Email

);

insert ccd ;

}

}

 

Thanks in advance

Madhulendra