• Simon@M+ve
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

Hi , 

 

I have written test class for the below trigger but covers only 45%, need help to fix it,

 

 

//trigger

trigger updateContactWithLatestCallStatus on Call_Report__c (after insert,after update){
if(Trigger.isInsert){
Call_Report__c cr=Trigger.new[0];
if(cr.contact__c!=null){
Contact cnt=new Contact(id=cr.contact__c,Call_Status__c=cr.status__c,Last_Call_Report_Date__c=cr.LastModifiedDate);
update cnt;
}
}else if(Trigger.isUpdate){
Call_Report__c cr=Trigger.new[0];
List<Call_Report__c> cntCrs=[select Id,name,contact__c,Status__c,Date__c from Call_Report__c where Contact__c=:cr.Contact__c and Date__c>= :cr.Date__c order by Date__c desc];
System.debug('Date__c ==> '+cntCrs.get(0).Date__c);
if(cntCrs!=null && cntCrs.size()>0 && cntCrs.get(0)!=null && cr.contact__c!=null){
Contact cnt=new Contact(id=cr.contact__c,Call_Status__c=cntCrs.get(0).status__c);
update cnt;
}
}

}

 

//test class

 

@isTest
private class updateContactWithLatestCallStatusTest
 {
 static testMethod void myUnitTest()
  {
  Call_Report__c cr = new Call_Report__c ();
  //cr.Id='a0XW0000000LjTa';
  cr.name='test';
  cr.contact__c='003W0000009LKIz';
  cr.Status__c='Scheduled';
  cr.Date__c=date.today();
  insert cr;
  
  Contact con=new Contact();
  //cnt.id='003W0000009LKIz';
  con.Call_Status__c='Scheduled';
  con.Last_Call_Report_Date__c=date.today();
  con.LastName = 'Test';
  con.Phone='6853235351';
  con.Job_Title__c='Dentist';
  con.Has_a_computer__c='yes';
  insert con;

 

Thanks , Please help me

I hope someone can help me with this interesting little nugget.


We are using the Docusign API to manage electronic signatures on some documents.  Part of the process of this is to send a letter out to the user as a PDF.  We create the PDF by using a Visualforce Page set as "renderAs='PDF'" assign it to a PageReference object, and then use the .getContent() method to assign the data to a Blob.

 

We have three scenarios attempted to get this to work:

 

1.  Run the code from a button on a VF page - this works fine.  The PDF isn't truncated (i.e in the XML message the tag 'PDFBytes' is well formed and the correct length).

 

2.  Run the code from a button on a VF page, but it uses an @future call (this is necessary as we are aiming towards batch processing of Docusign processing) and this also works fine.  The page was a simple test page with three inputs and a button that called the @future method.

 

3.  Run the code from a button, but THIS button processes other bits and pieces in Apex first.  At the end of it's processing, it calls the @future method.  This fails.  The reason it fails is that the WebService Callout receives an error about processing anchor tags.

 

After some investigation on the Docusign website, it appears one of the reasons for this WebService Callout error is the PDF document being sent as been truncated.  We checked our logs and low and behold, our 'PDFBytes' tag was extremely truncated.

 

So - the root problem seems to be, running this code to retrieve a Blob from a PDF-rendered VF page sometimes works (scenarios 1 & 2 above) and sometimes doesn't (scenario 3).  I have tried searching the Developer boards AND the Docusign boards (even though this isn't really a Docusign problem) but with no luck.

 

Can anyone help??

 

Thanks.

Hi , 

 

I have written test class for the below trigger but covers only 45%, need help to fix it,

 

 

//trigger

trigger updateContactWithLatestCallStatus on Call_Report__c (after insert,after update){
if(Trigger.isInsert){
Call_Report__c cr=Trigger.new[0];
if(cr.contact__c!=null){
Contact cnt=new Contact(id=cr.contact__c,Call_Status__c=cr.status__c,Last_Call_Report_Date__c=cr.LastModifiedDate);
update cnt;
}
}else if(Trigger.isUpdate){
Call_Report__c cr=Trigger.new[0];
List<Call_Report__c> cntCrs=[select Id,name,contact__c,Status__c,Date__c from Call_Report__c where Contact__c=:cr.Contact__c and Date__c>= :cr.Date__c order by Date__c desc];
System.debug('Date__c ==> '+cntCrs.get(0).Date__c);
if(cntCrs!=null && cntCrs.size()>0 && cntCrs.get(0)!=null && cr.contact__c!=null){
Contact cnt=new Contact(id=cr.contact__c,Call_Status__c=cntCrs.get(0).status__c);
update cnt;
}
}

}

 

//test class

 

@isTest
private class updateContactWithLatestCallStatusTest
 {
 static testMethod void myUnitTest()
  {
  Call_Report__c cr = new Call_Report__c ();
  //cr.Id='a0XW0000000LjTa';
  cr.name='test';
  cr.contact__c='003W0000009LKIz';
  cr.Status__c='Scheduled';
  cr.Date__c=date.today();
  insert cr;
  
  Contact con=new Contact();
  //cnt.id='003W0000009LKIz';
  con.Call_Status__c='Scheduled';
  con.Last_Call_Report_Date__c=date.today();
  con.LastName = 'Test';
  con.Phone='6853235351';
  con.Job_Title__c='Dentist';
  con.Has_a_computer__c='yes';
  insert con;

 

Thanks , Please help me