• learn sfdc 24
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
school__c -->customObject
studentjoinage =system.today() - createddate; //its formula field which riturn number.
I written the batchclass,in that   if(sch.studentjoinage__c==30) then send an email.
test.starttest
   mybatchcls mb=new mybatchcls();
   database.execute();
test.stoptest;
i get 40% codecoverage, in that start method ,finish methods r coverd but in execute method after if condition which means
messaging.singleemailmessage not coverd bcoze formula field.
i need help here to cover formula field.   
school__c -->customObject
studentjoinage =system.today() - createddate; //its formula field which riturn number.
I written the batchclass,in that   if(sch.studentjoinage__c==30) then send an email.
test.starttest
   mybatchcls mb=new mybatchcls();
   database.execute();
test.stoptest;
i get 40% codecoverage, in that start method ,finish methods r coverd but in execute method after if condition which means
messaging.singleemailmessage not coverd bcoze formula field.
i need help here to cover formula field.   
Hi,

I have a Visualforce page that creates a PDF contract of an opportunity, and I'm trying to save the PDF as an attachment on the opportunity.  I think I'm almost there, but I'm getting an error 

"DML currently not allowed 
An unexpected error has occurred. Your development organization has been notified."


here is my controller extension
public class savePDF {

        // The extension constructor initializes the private member
    // variable pageOpp by using the getRecord method from the standard
    // controller.
    Private Opportunity pageOpp;
    public savePDF(ApexPages.StandardController stdController) {
        this.pageOpp = (Opportunity)stdController.getRecord();
        system.debug('id = ' + pageOpp.id);
        
         PageReference pdf = Page.TWC_Contract;
    // create the new attachment
    Attachment attach = new Attachment();

    // the contents of the attachment from the pdf
    Blob body;

    try {

        // returns the output of the page as a PDF
        body = pdf.getContent();

    // need to pass unit test -- current bug    
    } catch (VisualforceException e) {
        body = Blob.valueOf('Some Text');
    }

    attach.Body = body;
    // add the user entered name
    attach.Name = 'test';
    attach.IsPrivate = false;
    // attach the pdf to the account
    attach.ParentId = pageOpp.Id;
    insert attach;

    }
  
}
I kind of hypridized the code based on the post here
http://blog.jeffdouglas.com/2010/07/14/attach-a-pdf-to-a-record-in-salesforce/


Thanks,