• rmranjith8881.3927046400771116E12
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 35
    Replies
Hello Everyone,

How to exclude Weekends on Workflow Task Due Dates?
On Workflow Tasks, we are setting up a due date extending with 'X' days, here, we need to exclude the weekends.

For Example, if we setup a workflow task to "Rule Triggered Date + 5 Days" and if that 5th day falls on weekend either Saturday or Sunday, SF should automatically consider the next Business Day, i.e Monday.

Different Workflows have different Due Dates, need to work it for all Workflow Tasks (on different Objects), irrespective of Due Date.
And Different Workflows have multiple actions like Email Alert, Field Update and Outbound Messages along with Tasks.

Can any one please help me out on achieving same?

Thanks in Advance,
Ranjith.
Hello Everyone,

I have one multiple picklist field and I have a,b,c,d as values in it. And if I want to select either "a or b" OR "a and b", I would like to update one text field with "AB", if I want to select either " c or d" OR "c and d", I would like to update same text field with "CD", if I want to select all values or one value of " a or b" and "c or d", I would like to update same text field with "both".

Can we do this with workflow field update, if yes, please give me some ideas?
Thanks in advance
Hello Everyone,

How do we do Email Template folders default to specific Objects?

Here, I have different email template folders for each object.
For example, I have Lead Templates, Contact Templates, Account Templates, and Opportunity templates Folders.
If I am sending an email from Lead, I have to see default to Lead Templates Folders, other folders let it be there in list.
Like that I have to see Default Email templates folders specific to other Objects.

Can anyone help me out?

Thanks in advance........
Ranjith
Hi EveryOne,

I have a Extensions on Oppportunity, which sends the Email with two Visualforce Pdf file attachments.
I need to write a test class for it,
As of now, My test coverage is 8%.
Please find my Code below.

Extension Code:
 
//Send email with Multiple attachments, and before sending edit template
public class SendEmail {

    public Account acc;
    public String body { get; set; }    
    Product_EmailTemplates__c template;//Custom settings to read the template, which template to send
    public Opportunity opp { get; set;}
    public String subject { get; set; }
    public String htmlBody {get; set;}
    

    // Create a constructor that populates the Opportunity object
    public SendEmail(ApexPages.StandardController controller) {        
        opp = [Select Id, Name, Email__c, Amount, Contact_Name__c, Account.PersonContactId, Account.id, Product__r.Name, Account.Name, StageName, Tax_Amount__c, Total_after_Tax__c, 
               payment_1_Amount__c, Payment_2_Amount__c, Payment_3_Amount__c, Payment_1_Before_Tax__c, Payment_2_Before_Tax__c, Payment_3_Before_Tax__c, Payment_1_Tax_Amount__c, 
               Payment_2_Tax_Amount__c, Payment_3_Tax_Amount__c, Potential_Number__c,Branch_Name__c, Branch_Name__r.Name, Branch_Name__r.Address_1__c, Branch_Name__r.Address_2__c, Branch_Name__r.City__c, 
               Branch_Name__r.Country__c, Branch_Name__r.Main_Phone_1__c, Branch_Name__r.Main_Phone_2__c, Branch_Name__r.Main_Phone_3__c, Branch_Name__r.Region__c, Branch_Name__r.State__c, 
               Branch_Name__r.Zip_Postal_Code__c, Product__r.Product_Type__c, Admin_Fee__c, Payment_1_plus_Admin_Fee__c
                    from Opportunity where Id = :ApexPages.currentPage().getParameters().get('id')];
              
        EmailTemplate emailTemplate = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Id = :getTemplateId(opp.Product__r.Name, opp.Product__r.Product_Type__c)];
    
        htmlBody = emailTemplate.HtmlValue;
        subject = emailTemplate.subject;
    }
    
    //Send the email with two attachments
    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        
        //Send email if Branch not equals to Saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name != 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf1 =  Page.CCLPdf;//CCLPdf is a Visualforce page
            pdf1.getParameters().put('id',opp.id); 
            pdf1.setRedirect(true);
    
            // Take the PDF content
            Blob b1 = pdf1.getContentAsPDF();
            
            PageReference pdf2 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf2.getParameters().put('id',opp.id); 
            pdf2.setRedirect(true);
    
            // Take the PDF content
            Blob b2 = pdf2.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
            efa1.setFileName(opp.account.Name+'-CCL.pdf');//set the email attachment name
            efa1.setBody(b1);
            
            Messaging.EmailFileAttachment efa2 = new Messaging.EmailFileAttachment();
            efa2.setFileName(opp.account.Name+'-Invoice.pdf');//set the email attachment name
            efa2.setBody(b2);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1,efa2});
            StoringAttachments();
        }
        
        //Send email if Branch not equals to Saudi Arabia and Product type is Canada
        if(opp.Branch_Name__r.Name != 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf3 =  Page.CANCCLPdf;//CANCCLPdf is a Visualforce page
            pdf3.getParameters().put('id',opp.id); 
            pdf3.setRedirect(true);
    
            // Take the PDF content
            Blob b3 = pdf3.getContentAsPDF();
            
            PageReference pdf4 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf4.getParameters().put('id',opp.id); 
            pdf4.setRedirect(true);
    
            // Take the PDF content
            Blob b4 = pdf4.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa3 = new Messaging.EmailFileAttachment();
            efa3.setFileName(opp.account.Name+'-CANCCL.pdf');//set the email attachment name
            efa3.setBody(b3);
            
            Messaging.EmailFileAttachment efa4 = new Messaging.EmailFileAttachment();
            efa4.setFileName(opp.account.Name+'-CANInvoice.pdf');//set the email attachment name
            efa4.setBody(b4);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa3,efa4});
            StoringAttachments();
        }
        
        //Send email if Branch is saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf5 =  Page.KSACCLPdf;//KSACCLPdf is a Visualforce page
            pdf5.getParameters().put('id',opp.id); 
            pdf5.setRedirect(true);
    
            // Take the PDF content
            Blob b5 = pdf5.getContentAsPDF();
            
            PageReference pdf6 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf6.getParameters().put('id',opp.id); 
            pdf6.setRedirect(true);
    
            // Take the PDF content
            Blob b6 = pdf6.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa5 = new Messaging.EmailFileAttachment();
            efa5.setFileName(opp.account.Name+'-KSACCL.pdf');//set the email attachment name
            efa5.setBody(b5);
            
            Messaging.EmailFileAttachment efa6 = new Messaging.EmailFileAttachment();
            efa6.setFileName(opp.account.Name+'-KSAInvoice.pdf');//set the email attachment name
            efa6.setBody(b6);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa5,efa6});
            StoringAttachments();
         } 
         
         //Send email if Branch is saudi Arabia and Product type is Canada
         if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf7 =  Page.KSACANCCLPdf;//KSACANCCLPdf is a Visualforce page
            pdf7.getParameters().put('id',opp.id); 
            pdf7.setRedirect(true);
    
            // Take the PDF content
            Blob b7 = pdf7.getContentAsPDF();
            
            PageReference pdf8 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf8.getParameters().put('id',opp.id); 
            pdf8.setRedirect(true);
    
            // Take the PDF content
            Blob b8 = pdf8.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa7 = new Messaging.EmailFileAttachment();
            efa7.setFileName(opp.account.Name+'-KSACANCCL.pdf');//set the email attachment name
            efa7.setBody(b7);
            
            Messaging.EmailFileAttachment efa8 = new Messaging.EmailFileAttachment();
            efa8.setFileName(opp.account.Name+'-KSACANInvoice.pdf');//set the email attachment name
            efa8.setBody(b8);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa7,efa8});
            StoringAttachments();
         } 
    
            // Sends the email
            Messaging.SendEmailResult [] r = 
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
        
        
        return new PageReference('/'+opp.Id);
    }
    
    //Creating attachments
    public void StoringAttachments() {
        //Send attachments if Branch is India and Product type is Standard
        if((opp.Branch_Name__r.Name == 'India' || opp.Branch_Name__r.Name == 'United Kingdom') && opp.Product__r.Product_Type__c == 'Standard'){
            Attachment myAttach1 = new Attachment();
            myAttach1.ParentId = opp.Account.PersonContactId;
            myAttach1.name = opp.account.Name+'-CCL.pdf';
            PageReference myPdf1 = Page.CCLPdf;
            myAttach1.body = myPdf1.getContentAsPdf();
            insert myAttach1;
            
            Attachment myAttach2 = new Attachment();
            myAttach2.ParentId = opp.Account.PersonContactId;
            myAttach2.name = opp.account.Name+'-Invoice.pdf';
            PageReference myPdf2 = Page.ProformaInvoicePdf;
            myAttach2.body = myPdf2.getContentAsPdf();
            insert myAttach2;
        }
        
        //Send attachments if Branch is India and Product type is Canada
        if((opp.Branch_Name__r.Name == 'India' || opp.Branch_Name__r.Name == 'United Kingdom') && opp.Product__r.Product_Type__c == 'Canada'){
            Attachment myAttach3 = new Attachment();
            myAttach3.ParentId = opp.Account.PersonContactId;
            myAttach3.name = opp.account.Name+'-CANCCL.pdf';
            PageReference myPdf3 = Page.CANCCLPdf;
            myAttach3.body = myPdf3.getContentAsPdf();
            insert myAttach3;
            
            Attachment myAttach4 = new Attachment();
            myAttach4.ParentId = opp.Account.PersonContactId;
            myAttach4.name = opp.account.Name+'-CANInvoice.pdf';
            PageReference myPdf4 = Page.ProformaInvoicePdf;
            myAttach4.body = myPdf4.getContentAsPdf();
            insert myAttach4;
        }
        
        //Send attachments if Branch is saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            Attachment myAttach5 = new Attachment();
            myAttach5.ParentId = opp.Account.PersonContactId;
            myAttach5.name = opp.account.Name+'-KSACCL.pdf';
            PageReference myPdf5 = Page.KSACCLPdf;
            myAttach5.body = myPdf5.getContentAsPdf();
            insert myAttach5;
            
            Attachment myAttach6 = new Attachment();
            myAttach6.ParentId = opp.Account.PersonContactId;
            myAttach6.name = opp.account.Name+'-KSAInvoice.pdf';
            PageReference myPdf6 = Page.ProformaInvoicePdf;
            myAttach6.body = myPdf6.getContentAsPdf();
            insert myAttach6;
        }
        
        //Send attachments if Branch is saudi Arabia and Product type is Canada
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            Attachment myAttach7 = new Attachment();
            myAttach7.ParentId = opp.Account.PersonContactId;
            myAttach7.name = opp.account.Name+'-KSACANCCL.pdf';
            PageReference myPdf7 = Page.KSACANCCLPdf;
            myAttach7.body = myPdf7.getContentAsPdf();
            insert myAttach7;
            
            Attachment myAttach8 = new Attachment();
            myAttach8.ParentId = opp.Account.PersonContactId;
            myAttach8.name = opp.account.Name+'-KSACANInvoice.pdf';
            PageReference myPdf8 = Page.ProformaInvoicePdf;
            myAttach8.body = myPdf8.getContentAsPdf();
            insert myAttach8;
        }
    } 
    
    //Reads the Template from Custom settings        
    public String getTemplateId(String prodName, String prodType){
       template = [Select Name, Email_Template_Id__c, Product_Type__c from Product_EmailTemplates__c 
                        where Name = : prodName and Product_Type__c = : prodType];
       return template.Email_Template_Id__c;
   }

}

Can anyone please help me to write a Test class for my Extensions?

Thanks In Advance.......
Ranjith
 
Hi Everyone,

I have a Extensions on Oppportunity, which sends the Email with two Visualforce Pdf file attachments.
I need to write a test class for it,
As of now, My test coverage is 8%.
Please find my Code below.

Extensions and Test class Code:
 
//Send email with Multiple attachments, and before sending edit template
public class SendEmail {

    public Account acc;
    public String body { get; set; }    
    Product_EmailTemplates__c template;//Custom settings to read the template, which template to send
    public Opportunity opp { get; set;}
    public String subject { get; set; }
    public String htmlBody {get; set;}
    

    // Create a constructor that populates the Opportunity object
    public SendEmail(ApexPages.StandardController controller) {        
        opp = [Select Id, Name, Email__c, Amount, Contact_Name__c, Account.PersonContactId, Account.id, Product__r.Name, Account.Name, StageName, Tax_Amount__c, Total_after_Tax__c, 
               payment_1_Amount__c, Payment_2_Amount__c, Payment_3_Amount__c, Payment_1_Before_Tax__c, Payment_2_Before_Tax__c, Payment_3_Before_Tax__c, Payment_1_Tax_Amount__c, 
               Payment_2_Tax_Amount__c, Payment_3_Tax_Amount__c, Potential_Number__c,Branch_Name__c, Branch_Name__r.Name, Branch_Name__r.Address_1__c, Branch_Name__r.Address_2__c, Branch_Name__r.City__c, 
               Branch_Name__r.Country__c, Branch_Name__r.Main_Phone_1__c, Branch_Name__r.Main_Phone_2__c, Branch_Name__r.Main_Phone_3__c, Branch_Name__r.Region__c, Branch_Name__r.State__c, 
               Branch_Name__r.Zip_Postal_Code__c, Product__r.Product_Type__c, Admin_Fee__c, Payment_1_plus_Admin_Fee__c
                    from Opportunity where Id = :ApexPages.currentPage().getParameters().get('id')];
              
        EmailTemplate emailTemplate = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Id = :getTemplateId(opp.Product__r.Name, opp.Product__r.Product_Type__c)];
    
        htmlBody = emailTemplate.HtmlValue;
        subject = emailTemplate.subject;
    }
    
    //Send the email with two attachments
    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        
        //Send email if Branch not equals to Saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name != 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf1 =  Page.CCLPdf;//CCLPdf is a Visualforce page
            pdf1.getParameters().put('id',opp.id); 
            pdf1.setRedirect(true);
    
            // Take the PDF content
            Blob b1 = pdf1.getContentAsPDF();
            
            PageReference pdf2 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf2.getParameters().put('id',opp.id); 
            pdf2.setRedirect(true);
    
            // Take the PDF content
            Blob b2 = pdf2.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
            efa1.setFileName(opp.account.Name+'-CCL.pdf');//set the email attachment name
            efa1.setBody(b1);
            
            Messaging.EmailFileAttachment efa2 = new Messaging.EmailFileAttachment();
            efa2.setFileName(opp.account.Name+'-Invoice.pdf');//set the email attachment name
            efa2.setBody(b2);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1,efa2});
            StoringAttachments();
        }
        
        //Send email if Branch not equals to Saudi Arabia and Product type is Canada
        if(opp.Branch_Name__r.Name != 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf3 =  Page.CANCCLPdf;//CANCCLPdf is a Visualforce page
            pdf3.getParameters().put('id',opp.id); 
            pdf3.setRedirect(true);
    
            // Take the PDF content
            Blob b3 = pdf3.getContentAsPDF();
            
            PageReference pdf4 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf4.getParameters().put('id',opp.id); 
            pdf4.setRedirect(true);
    
            // Take the PDF content
            Blob b4 = pdf4.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa3 = new Messaging.EmailFileAttachment();
            efa3.setFileName(opp.account.Name+'-CANCCL.pdf');//set the email attachment name
            efa3.setBody(b3);
            
            Messaging.EmailFileAttachment efa4 = new Messaging.EmailFileAttachment();
            efa4.setFileName(opp.account.Name+'-CANInvoice.pdf');//set the email attachment name
            efa4.setBody(b4);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa3,efa4});
            StoringAttachments();
        }
        
        //Send email if Branch is saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf5 =  Page.KSACCLPdf;//KSACCLPdf is a Visualforce page
            pdf5.getParameters().put('id',opp.id); 
            pdf5.setRedirect(true);
    
            // Take the PDF content
            Blob b5 = pdf5.getContentAsPDF();
            
            PageReference pdf6 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf6.getParameters().put('id',opp.id); 
            pdf6.setRedirect(true);
    
            // Take the PDF content
            Blob b6 = pdf6.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa5 = new Messaging.EmailFileAttachment();
            efa5.setFileName(opp.account.Name+'-KSACCL.pdf');//set the email attachment name
            efa5.setBody(b5);
            
            Messaging.EmailFileAttachment efa6 = new Messaging.EmailFileAttachment();
            efa6.setFileName(opp.account.Name+'-KSAInvoice.pdf');//set the email attachment name
            efa6.setBody(b6);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa5,efa6});
            StoringAttachments();
         } 
         
         //Send email if Branch is saudi Arabia and Product type is Canada
         if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf7 =  Page.KSACANCCLPdf;//KSACANCCLPdf is a Visualforce page
            pdf7.getParameters().put('id',opp.id); 
            pdf7.setRedirect(true);
    
            // Take the PDF content
            Blob b7 = pdf7.getContentAsPDF();
            
            PageReference pdf8 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf8.getParameters().put('id',opp.id); 
            pdf8.setRedirect(true);
    
            // Take the PDF content
            Blob b8 = pdf8.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa7 = new Messaging.EmailFileAttachment();
            efa7.setFileName(opp.account.Name+'-KSACANCCL.pdf');//set the email attachment name
            efa7.setBody(b7);
            
            Messaging.EmailFileAttachment efa8 = new Messaging.EmailFileAttachment();
            efa8.setFileName(opp.account.Name+'-KSACANInvoice.pdf');//set the email attachment name
            efa8.setBody(b8);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa7,efa8});
            StoringAttachments();
         } 
    
            // Sends the email
            Messaging.SendEmailResult [] r = 
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
        
        
        return new PageReference('/'+opp.Id);
    }
    
    //Creating attachments
    public void StoringAttachments() {
        //Send attachments if Branch is India and Product type is Standard
        if((opp.Branch_Name__r.Name == 'India' || opp.Branch_Name__r.Name == 'United Kingdom') && opp.Product__r.Product_Type__c == 'Standard'){
            Attachment myAttach1 = new Attachment();
            myAttach1.ParentId = opp.Account.PersonContactId;
            myAttach1.name = opp.account.Name+'-CCL.pdf';
            PageReference myPdf1 = Page.CCLPdf;
            myAttach1.body = myPdf1.getContentAsPdf();
            insert myAttach1;
            
            Attachment myAttach2 = new Attachment();
            myAttach2.ParentId = opp.Account.PersonContactId;
            myAttach2.name = opp.account.Name+'-Invoice.pdf';
            PageReference myPdf2 = Page.ProformaInvoicePdf;
            myAttach2.body = myPdf2.getContentAsPdf();
            insert myAttach2;
        }
        
        //Send attachments if Branch is India and Product type is Canada
        if((opp.Branch_Name__r.Name == 'India' || opp.Branch_Name__r.Name == 'United Kingdom') && opp.Product__r.Product_Type__c == 'Canada'){
            Attachment myAttach3 = new Attachment();
            myAttach3.ParentId = opp.Account.PersonContactId;
            myAttach3.name = opp.account.Name+'-CANCCL.pdf';
            PageReference myPdf3 = Page.CANCCLPdf;
            myAttach3.body = myPdf3.getContentAsPdf();
            insert myAttach3;
            
            Attachment myAttach4 = new Attachment();
            myAttach4.ParentId = opp.Account.PersonContactId;
            myAttach4.name = opp.account.Name+'-CANInvoice.pdf';
            PageReference myPdf4 = Page.ProformaInvoicePdf;
            myAttach4.body = myPdf4.getContentAsPdf();
            insert myAttach4;
        }
        
        //Send attachments if Branch is saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            Attachment myAttach5 = new Attachment();
            myAttach5.ParentId = opp.Account.PersonContactId;
            myAttach5.name = opp.account.Name+'-KSACCL.pdf';
            PageReference myPdf5 = Page.KSACCLPdf;
            myAttach5.body = myPdf5.getContentAsPdf();
            insert myAttach5;
            
            Attachment myAttach6 = new Attachment();
            myAttach6.ParentId = opp.Account.PersonContactId;
            myAttach6.name = opp.account.Name+'-KSAInvoice.pdf';
            PageReference myPdf6 = Page.ProformaInvoicePdf;
            myAttach6.body = myPdf6.getContentAsPdf();
            insert myAttach6;
        }
        
        //Send attachments if Branch is saudi Arabia and Product type is Canada
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            Attachment myAttach7 = new Attachment();
            myAttach7.ParentId = opp.Account.PersonContactId;
            myAttach7.name = opp.account.Name+'-KSACANCCL.pdf';
            PageReference myPdf7 = Page.KSACANCCLPdf;
            myAttach7.body = myPdf7.getContentAsPdf();
            insert myAttach7;
            
            Attachment myAttach8 = new Attachment();
            myAttach8.ParentId = opp.Account.PersonContactId;
            myAttach8.name = opp.account.Name+'-KSACANInvoice.pdf';
            PageReference myPdf8 = Page.ProformaInvoicePdf;
            myAttach8.body = myPdf8.getContentAsPdf();
            insert myAttach8;
        }
    } 
    
    //Reads the Template from Custom settings        
    public String getTemplateId(String prodName, String prodType){
       template = [Select Name, Email_Template_Id__c, Product_Type__c from Product_EmailTemplates__c 
                        where Name = : prodName and Product_Type__c = : prodType];
       return template.Email_Template_Id__c;
   }

}

Test Class:

@isTest(seeAllData=true)
public class CreateCaseTests{

     private static Id leadId;

static testMethod void testCreateCase() {
    
        
        //Inserting Products
        Product2 prod = new Product2();
        prod.Name = 'Resident Visa';
        prod.ProductCode = 'RV';
        insert prod;
        
        //Inserting Products
        Product2 prod1 = new Product2();
        prod1.Name = 'Permanant Visa';
        prod1.ProductCode = 'PV';
        insert prod1;
        
        //get standard pricebook
        Pricebook2  standardPb = [select Id, Name, isActive from Pricebook2 where IsStandard = true limit 1];
        
        //Inserting pricebook
        Pricebook2 pb = new Pricebook2();
        pb.Name = 'India';
        pb.IsActive= true;
        insert pb;
        
        //Inserting pricebook
        Pricebook2 pb1 = new Pricebook2();
        pb1.Name = 'Saudi Arabia';
        pb1.IsActive= true;
        insert pb1;
        
        //Inserting pricebookEntry
        PricebookEntry pbe = new PricebookEntry();
        pbe.Pricebook2Id = standardPb.Id;
        pbe.Product2Id = prod.Id;
        pbe.UnitPrice = 1.0;
        //pbe.UseStandardPrice = true;
        pbe.IsActive = true;
        insert pbe;
        
        //Inserting pricebookEntry
        PricebookEntry pbe1 = new PricebookEntry();
        pbe1.Pricebook2Id = standardPb.Id;
        pbe1.Product2Id = prod1.Id;
        pbe1.UnitPrice = 1.0;
        //pbe.UseStandardPrice = true;
        pbe1.IsActive = true;
        insert pbe1;
        
        Lead testLead = new Lead();
            testLead.FirstName = 'Test First';
            testLead.LastName = 'Test Last';
            //testLead.Company = 'Test Co';
            //testLead.RecordTypeId = '012110000004b9Q';
            testLead.Status = 'Converted';
            testLead.LeadSource = 'Web';
            testLead.Date_Received__c = System.Today();
            testLead.Email = 'ranjith@rixyncs.co.in';
            testLead.Payment_Plan__c = '2 Monthly Payments';
            testLead.Phone = '+919590854842';
            testLead.MobilePhone = '+919590854842';
            //testLead.Branch__c = 'India';
            testLead.CurrencyIsoCode = 'INR';
            testLead.Destination_Visa__c = 'Denmark';
            testLead.Product__c = prod.Id;
            testLead.Date_of_Birth__c = System.Today();
            testLead.Age__c = 30;
            testLead.Occupation__c = 'SE';
            testLead.Number_of_years_in_this_occupation__c = 2;
            testLead.Highest_Qualification__c = 'MCA';
            testLead.Experience__c = 'Full - Time';
            testLead.Dependents__c = '2';
            testLead.Nationality_Immigration_Status__c = 'Pending';
            testLead.Criminal_Health__c = 'No';
            testLead.Job_Offer__c = True;
            testLead.Maintenance__c = 'Yes';
            testLead.Family_Links__c = True;
            testLead.Country = 'India';
            testLead.Country__c = 'India';
            insert testLead;
            leadId = testLead.Id;
            
            System.currentPagereference().getParameters().put('id',testLead.id);

        
        
        
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(leadId);
        //lc.setAccountId(myRecordType.Id) ;
        //lc.strAccountId= '1';
        //lc.strContactId= '1';
        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        //lcr.getAccountId();
        //lcr.getContactId();
        //lcr.getOpportunityId();
        
        //this line returned my lead with isConverted:true and ids for related contact and account
    /*Lead leadFromDB = [select 
                       FirstName,
                       LastName,
                       Country,
                       isConverted,
                       ConvertedAccountId,
                       ConvertedContactId
                       from Lead where id = : testLead.Id];
    System.debug('this lead looks like: ' + leadFromDB);

    // successfully queried contact, would produce query exception if no contact found
    Contact c = [select Id,FirstName,LastName from Contact where Id = : leadFromDB.ConvertedContactId];

    // again success, no query exception
    Account a = [select Id,Name from Account where Id = : leadFromDB.ConvertedAccountId];

    // confirmation in my log of what I got back.
    System.debug(c);
    System.debug(a);*/

    //System.assert(lcr.isSuccess()); //<--assert passed   
        
        System.assert(lcr.isSuccess());
        

    
        /*Inserting Lead and converting
        Lead ld = new Lead();
        ld.LastName='Doe';
        ld.FirstName='John';
        ld.Company='Test';
        ld.Status = 'Converted';
        ld.LeadSource = 'Web';
        ld.Date_Received__c = System.Today();
        ld.Email = 'ranjith@rixyncs.co.in';
        ld.Payment_Plan__c = '2 Monthly Payments';
        ld.Phone = '+919590854842';
        ld.MobilePhone = '+919590854842';
        ld.Branch__c = 'India';
        ld.CurrencyIsoCode = 'INR';
        ld.Destination_Visa__c = 'Denmark';
        ld.Product__c = prod.Id;
        ld.Date_of_Birth__c = System.Today();
        ld.Age__c = 30;
        ld.Occupation__c = 'SE';
        ld.Number_of_years_in_this_occupation__c = 2;
        ld.Highest_Qualification__c = 'MCA';
        ld.Experience__c = 'Full - Time';
        ld.Dependents__c = '2';
        ld.Nationality_Immigration_Status__c = 'Pending';
        ld.Criminal_Health__c = 'No';
        ld.Job_Offer__c = True;
        ld.Maintenance__c = 'Yes';
        ld.Family_Links__c = True;
        insert ld;            


        ld =  [SELECT Id,Status, FirstName,LastName,Company,LeadSource
             FROM Lead
             WHERE Id = :ld.Id];

        System.assertEquals('Converted', ld.Status);*/
        
        RecordType myRecordType = [select id from RecordType where SobjectType='Account' AND IsPersonType=True limit 1];
    
        //Inserting Account
        Account acc = new Account();
        acc.LastName = 'Ranjith';
        acc.RecordTypeId = myRecordType.Id;
        insert acc;
        
        //Inserting Contact
        Contact con = new Contact();
        con.LastName = 'kumar';
        //con.AccountId = acc.Id;
        insert con;    
              
                
        
        
        //Inserting Potential
        Opportunity opp = new Opportunity();
        opp.Name = 'Ranjith kumar';
        //opp.Potential_Number__c = '0011';
        opp.AccountId = acc.Id;
        opp.CloseDate = System.today()+20;
        opp.StageName = 'CCL Sent';
        opp.Contact_Name__c = con.Id;
        opp.Type  = 'Existing Business';
        opp.English_Language__c  = 'Vocational';
        opp.Payment_Plan__c = '2 Monthly Payments';
        opp.Tax_Amount__c = 1000.00;
        opp.Total_after_Tax__c = 1000000.00;
        opp.Amount = 10000000.00;
        opp.Date_of_Birth__c = System.today();
        opp.Destination_Visa__c = 'US';
        opp.TimeFrame__c = '3 Months';
        opp.Eligibility_Score__c = 60;
        //opp.Branch__c = 'India';
        opp.Occupation__c = 'SE';
        opp.Number_of_years_in_this_occupation__c = 2;
        opp.Highest_Qualification__c = 'MCA';
        opp.Experience__c = 'Full - Time';
        opp.Dependents__c = '2';
        opp.Nationality_Immigration_Status__c = 'Pending';
        opp.Criminal_Health__c = 'No';
        opp.Job_Offer__c = True;
        opp.Maintenance__c = 'Yes';
        opp.Family_Links__c = True;
        opp.payment_1_Amount__c = 100.00;
        opp.Payment_2_Amount__c = 100.00;
        opp.Payment_3_Amount__c = 100.00;
        opp.Payment_1_Received_Date__c = System.today();
        opp.Payment_2_Due_Date__c = System.today()+30;
        opp.Payment_3_Due_Date__c = System.today()+60;
        opp.Payment_1_Before_Tax__c = 100.00;
        opp.Payment_2_Before_Tax__c = 100.00;
        opp.Payment_3_Before_Tax__c = 100.00;
        opp.Payment_1_Status__c = 'Received';
        opp.Payment_2_Status__c = 'Pending';
        opp.Payment_3_Status__c = 'Pending';   
        opp.Pricebook2Id  = pbe.Pricebook2Id; 
        opp.Product__c = prod.Id;
        insert opp;
    System.currentPagereference().getParameters().put('id',opp.id);
         Blob content;        
         PageReference pf = page.CCLPdf;
         Attachment objAtt = new Attachment();
         objAtt.Name = opp.Account.Name + '-CCL.Pdf';
         objAtt.body =  Blob.valueof('string');
         objAtt.ParentId = opp.Id;        
         if (Test.IsRunningTest()){
                content=Blob.valueOf('UNIT.TEST');
             }else{
                content=pf.getContent();
             }
         insert objAtt;
        
ApexPages.StandardController stdController = new ApexPages.StandardController(opp); 
        SendEmail send = new SendEmail(stdController);
        
        send.send();
        send.StoringAttachments();
        send.getTemplateId('Permanant Visa','Standard');
        
    
      }
    
}


Can anyone please help me to write a Test class for my Extensions?

Thanks In Advance.......
Ranjith

 
Hi All,

I have a Custom object called Branch__c, which has Region__c and Country__c picklist fields.

Branch__c is a Lookup on Lead object.

Lead also have Region__c and Country__c picklist fields,

So, I want to update the Branch__c Lookup field on Lead, If the Branch Region__c and Country__c fields matches with Lead Region__c and Country__c.
If Branch Region__c is null. update the Lead Region__c with Bangalore.

For this I wrote a Trigger below.

It is saving without errors, but it will not update the Lookup field on Lead.
 
trigger UpdateBranch on Lead (before insert, before update) {
    Set<Id> ids = trigger.newmap.keySet();
    Lead ld;
    
    for (Lead lT:Trigger.new){
        ld = lT;
    }
    
    try{
        List<Branch__c> brList = [Select Id, Name, Country__c, Region__c, Email_ID__c from Branch__c where Id IN : ids];        
        Branch__c b = new Branch__c();
        for (Branch__c br : brList){
            if (brList .size() > 0 && ld.Country == br.Country__c && b.Region__c != Null){
                    ld.Branch_NAME__c = br.Id;
                    ld.Region__c = br.Region__c;
            }
            else{
                ld.Branch_NAME__c = null;
                ld.Region__c = 'Bangalore';
            }
        }
        }catch(Exception e){
         ld.addError('unable to find the Branch Name  ' + e.getMessage());
        }

}

Thanks in advance................
Hi Everyone,

I am enabled Multi currenies.

I would like to update my Lead currency based on the another picklist field(Branch).

For Example,
     If Branch is set to India, update the Lead currency with INR,
     If Branch is set to London, Update the Lead curency with GBP,
     If Branch is set to Saudi Arabia, Update the Lead currency with SAR.

How do we do that?

Can we do by Trigger?
If yes, can you please share some sample code here?

Thanks in advance........
 
Hi EveryOne,

The user request is that when a Custom button(Send Email) is clicked on the oportunity screen it should open a standard email UI and select the email template associated to the product for the template in that body and two attachments - attachment1  and attachment2 .

I am able to achieve all the functionality but we can add only one attachment. when we call the url to call that standard email page, we can only add one &docid = .

I am Passing this URL:

emailURL = '/_ui/core/email/author/EmailAuthor?p2_lkid=' + opp.Account.id + '&p3_lkid=' + opp.id + 
                    '&template_id='+getTemplateId(opp.Product__r.Name) + '&doc_id='+getCreatedDocId();

With this I am able to do the above functionality of sending email with one attachment.

How do I send 2 attachments?

Thanks In advance.........

I am sending my code below.
//Send the CCL Document to the potential when we cliclk the Send CCL Button.
public class CCLSendEmail {

    public Account acc;
    public Opportunity opp;
    public CCL_Documents__c cclDocs;//Custom settings
    Product_EmailTemplates__c template;//Custom settings
    public CCLSendEmail(ApexPages.StandardController controller){
        opp = [Select Id, Account.id, Product__r.Name, Account.Name,StageName from Opportunity where Id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
    public PageReference pdfEmail(){
        try{
            if(opp.StageName.equals('CCL Sent')){        
                String emailURL;
                emailURL = '/_ui/core/email/author/EmailAuthor?p2_lkid=' + opp.Account.id + '&p3_lkid=' + opp.id + 
                    '&template_id='+getTemplateId(opp.Product__r.Name) + '&doc_id='+getCreatedDocId();
                PageReference cclPage = new PageReference(emailURL); 
                cclPage.setRedirect(true); 
                return cclPage;
             }
             else{
                     ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING, 'Email Template is not there for this perticular Product');         
                     return null;
                  }
                  
             
              }catch(Exception e){
                    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING, e.getMessage()); 
                    ApexPages.addMessage(myMsg); 
                    return null;
       }  
   }
   
   
    public String getCreatedDocId(){
        Blob content;
        cclDocs = CCL_Documents__c.getInstance('VNP CCL Documents');
        PageReference pr = Page.CCLPdf; 
        pr.setRedirect(true); 
        pr = Page.CCLPdf; 
        pr.setRedirect(true); 
        pr.getParameters().put('id', opp.id); 
        
        if(!Test.isRunningTest()){ 
            content = pr.getContentAsPDF(); 
        } 
        
        Document doc = new Document(Name = opp.Account.Name+'.PDF', Body = content, FolderId = cclDocs.Document_Id__c);
        Database.SaveResult insertResult = Database.Insert(doc, true); 
        return doc.Id;
   }  
   
   
   public String getTemplateId(String prodName){
       template = [Select Name, Email_Template_Id__c from Product_EmailTemplates__c 
                        where Name = : prodName];
       return template.Email_Template_Id__c;
   }
}


 
Hi EveryOne,

I have 2 Queries,
1.) Can we have an alert message on the save for Opportunity record, whenever Stage becomes Posted?

2.) Can we have a Email section, open Activities, closed activities, Tasks and Events as a separate sections(like related lists)?

Thanks in Advance.

Hi All,


I wrote a Test class for 2 Triggers in Sandbox,

Earlier it covered 92%, before refreshed my Sandbox, and again when I Run my Test It is showing 0%, even though Test is passed.

I don't know why code coverage is 0%?

Can you please help me out?

Thanks in Advance...............

Hi All,

In my Sandbox(EE) we have 2 Triggers(Written by us), for that Triggers I covered the Code upto 92%.

Eventhough Code coverage is 92%, when i am moving from sanbox to Production by changesets, it showing the Error in Production as Test code Coverage failed and It showing the Code coverage 63% only.

Because of Managed Packages?

We need to cover the code for Managed Package also?

Please Let me know?


Thanks in Advance................
Hi All,

I have 2 picklist fields:
1.) Tenure of Support:Values are 3 Years, 4 Years, 5 Years
2.) Installment Period: Monthly, Quarterly, Half-Yearly, Yearly.

Installments: It is another Field(Number)

1.)If i select Tenure of SUpport as 3 Years and Installment Period as Monthly, then update the Installments as 36.
2.)If i select Tenure of SUpport as 4 Years and Installment Period as Monthly, then update the Installments as 48.
3.)If i select Tenure of SUpport as 5 Years and Installment Period as Monthly, then update the Installments as 60.
4.)If i select Tenure of SUpport as 3 Years and Installment Period as Quarterly, then update the Installments as 12.
5.)If i select Tenure of SUpport as 4 Years and Installment Period as Quarterly, then update the Installments as 16.
6.)If i select Tenure of SUpport as 5 Years and Installment Period as Quarterly, then update the Installments as 20.
7.)If i select Tenure of SUpport as 3 Years and Installment Period as Half-Yearly, then update the Installments as 6.
8.)If i select Tenure of SUpport as 4 Years and Installment Period as Half-Yearly, then update the Installments as 8.
9.)If i select Tenure of SUpport as 5 Years and Installment Period as Half-Yearly, then update the Installments as 10.
10)If i select Tenure of SUpport as 3 Years and Installment Period as Yearly, then update the Installments as 3.
11)If i select Tenure of SUpport as 4 Years and Installment Period as Yearly, then update the Installments as 4.
12)If i select Tenure of SUpport as 5 Years and Installment Period as Yearly, then update the Installments as 5.

For that, We are going to use the Field Update evaluates formula.

Is it achieve by Filed update?

If you Say Yes, Can you try out and let me know?

Thanks In Advance..........
Hi All,

I have a Sorting problem with my controller,

I am unable to sort the records when i click on column header,

can you people look into this and guide me how to achieve this?

Thanks in advance.............

here are my controller and Visualforce page,

Controller:

public with sharing class studentSponsorController{
public List<Opportunity> oppList{get; set;}//List of all Opportunities for data table
public Opportunity oppObj {get; set;}//object for oppotunity to get content on visualforce page
public String sortDirection = 'ASC';//variables to sort data table columns
public String sortExp = 'name';//variables to sort data table columns
public Contact con {set; get;}//variable for contact fo get content on visual force page
public Account acc {set; get;}//variable for Account fo get content on visual force page
public boolean isExport {get;set;}//variable to export data into excel
public Boolean isSearch {get;set;}//variable to verify searched values
//variables for search criteria
public String selectStr;
public String whereStr;
public String whereStr1;
public String whereStr2;
public String whereStr3;
public String whereStr4;
public String whereStr5;
//pagination for pageblock table
public ApexPages.StandardSetController pgn {
get {
if(pgn == null) {
pgn = new ApexPages.StandardSetController(oppList);
pgn.setPageSize(50);
}
return pgn;
}
set;
}
// indicates whether there are more records after the current page set..
public Boolean hasNext {
get {
return pgn.getHasNext();
}
set;
}
// indicates whether there are more records before the current page set..
public Boolean hasPrevious {
get {
return pgn.getHasPrevious();
}
set;
}
//Page number of the current displaying records
public Integer pageNumber
{
get
{
return pgn.getPageNumber();
}
set;
}
//Returns the previous page of records
public void previous()
{
pgn.previous();
}
//Returns the next page of records
public void next()
{
pgn.next();
}
// Initialize setPGN and return a list of records
public List<Opportunity> getOpportunityList() {
oppList = [Select Id, Name,AccountId, Account.Id, Account.Name, Record_Type_Name__c,
StageName,
Sponsorship_For__c, Std__c, Student_Name__c, Sponsorship_Date__c,
Student_Name__r.STD__c
FROM
Opportunity
WHERE
Recordtype.name = 'Education Sponsor' order by Std__c ASC LIMIT 1000];
return (List<Opportunity>) pgn.getRecords();
}
//logic to sort the data table values
public String sortExpression{
get{
return sortExp;
}
set{
//if the column is clicked on then switch between Ascending and Descending modes
if (value == sortExp)
sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
else
sortDirection = 'ASC';
sortExp = value;
}
}
//Logic to sorting in asce/desce
public String getSortDirection(){
//if not column is selected
if (sortExpression == null || sortExpression == '')
return 'ASC';
else
return sortDirection;
}
//logic to view sorted data
public PageReference ViewData() {
//build the full sort expression
String sortFullExp = sortExpression + ' ' + sortDirection;
//query the database based on the sort expression
try{
String RecTypeName = 'Education Sponsor';
OpportunityRecordTypes__c edSponsorSort = OpportunityRecordTypes__c.getValues('RT1');//object to get record type using custom settings
if(RecTypeName == 'Education Sponsor'){
RecTypeName = edSponsorSort.RecordTypeName__c;
}
if(isSearch == false){
oppList = Database.query('Select Id, Name, Account.Id, Account.Name, Record_Type_Name__c, StageName, Sponsorship_For__c, Std__c, Student_Name__c, Sponsorship_Date__c,Student_Name__r.STD__c FROM Opportunity WHERE Recordtype.name = :RecTypeName ORDER BY ' + sortFullExp + ' limit 1000');
}else{
oppList = Database.query(selectStr+ whereStr+' ORDER BY ' + sortFullExp + ' limit 1000');
}
}catch(Exception e ) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, e.getMessage() ));
}
return null;
}
//Controller
public studentSponsorController(){
try{
oppList = [Select Id, Name,AccountId, Account.Id, Account.Name, Record_Type_Name__c,
StageName,
Sponsorship_For__c, Std__c, Student_Name__c, Sponsorship_Date__c,
Student_Name__r.STD__c
FROM
Opportunity
WHERE
Recordtype.name = 'Education Sponsor' order by Std__c ASC LIMIT 1000];
pgn = new ApexPages.StandardSetController(oppList);
pgn.setPageSize(50);
oppObj = new Opportunity();
con = new Contact();
isSearch = false;
if(Apexpages.currentPage().getParameters().get('Export') != null){
isExport = true;
}
else{
isExport = false;
}
}catch(Exception e ) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, e.getMessage() ));
}
}
//Logic to view respective opportunity record
public PageReference View() {
Opportunity oppTemp = new Opportunity(id=ApexPages.currentPage().getParameters().get('Id'));
PageReference stundentSponsorPage = new ApexPages.StandardController(oppTemp).view();
return stundentSponsorPage ;
}
//Getting list of all opprtunites
public List<Opportunity> getOppList() {
//return oppList;
return (List<Opportunity>) pgn.getRecords();
}
//logic to reset searched values
public void reset() {
oppObj = new Opportunity();
}
//method to get search results
public void dynamicSearch(){
try{
isSearch = true;
selectStr =' Select Id, Name,AccountId, Account.Id, Account.Name, Record_Type_Name__c,Student_Name__r.STD__c, StageName, Sponsorship_For__c, Std__c, Student_Name__c, Sponsorship_Date__c ' +
' FROM Opportunity WHERE Recordtype.name = \''+'Education Sponsor\'';
whereStr ='';
String orderBy=' order by Std__c ASC limit 1000';
whereStr1 = (con.STD__c != null) ? whereStr + ' Student_Name__r.STD__c = \''+ con.STD__c+'\'' : '';
whereStr2 = (oppObj.Student_Name__c!=null) ? whereStr + ' Student_Name__c = \''+ oppObj.Student_Name__c+'\'' : '';
whereStr3 = (oppObj.AccountId != null) ? whereStr + ' AccountId = \''+ oppObj.AccountId+'\'' : '';
whereStr4 = (oppObj.Sponsorship_For__c != null) ? whereStr + ' Sponsorship_For__c = \''+ oppObj.Sponsorship_For__c+'\'' : '';
whereStr5 = (oppObj.Name !='') ? whereStr + ' Name Like \'%'+oppObj.Name+'%\' ' : '';
whereStr =(whereStr1.length()>0) ? whereStr + ' AND ' + whereStr1 : whereStr;
whereStr =(whereStr2.length()>0) ? whereStr + ' AND ' + whereStr2 : whereStr;
whereStr =(whereStr3.length()>0) ? whereStr + ' AND ' + whereStr3 : whereStr;
whereStr =(whereStr4.length()>0) ? whereStr + ' AND ' + whereStr4 : whereStr;
whereStr =(whereStr5.length()>0) ? whereStr + ' AND ' + whereStr5 : whereStr;
oppList = Database.query(selectStr + whereStr + orderBy);
pgn = new ApexPages.StandardSetController(oppList);
pgn.setPageSize(25);
}catch(Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING, e.getMessage()));
}
}
//method to export data into excel
public PageReference export(){
isExport = true;
return null;
}
}

Visualforce page:

<apex:page controller="studentSponsorController" contentType="{!IF(isExport = true, 'application/vnd.ms-excel#StudentSponsorReport.xls', '')}" sidebar="false" standardStylesheets="true" rendered="{!$User.Allow_Student_Sponsor_Report__c == true}">
<apex:sectionHeader title="Student Sponsor's Report View" rendered="{!(isExport = false)}"/>
<form name="PrintInformationTop">
<Center>
<input type="button" value=" Print Report " onClick="window.print()"/>
</Center>
</form>
<apex:pageMessages ></apex:pageMessages>
<apex:form >
<apex:pageBlock title="Legends" rendered="{!(isExport = false)}">
<Center>
<apex:commandButton action="{!export}" value="Export Report" rendered="{!AND(isExport = false)}" reRender=""/>
</Center>
<apex:pageBlockSection >
<apex:panelGrid columns="4" title="LEGENDS" width="1200">
<apex:image alt="Yellow" url="https://cs6.salesforce.com/resource/1390282686000/Yellow">Sponsor Name(Account Name) - &nbsp;</apex:image>
<apex:image alt="Green" url="https://cs6.salesforce.com/resource/1390282619000/Green">Student Sponsored - &nbsp;</apex:image>
<apex:image alt="Orange" url="https://cs6.salesforce.com/resource/1390282660000/Orange">Sponsor Prospecting - &nbsp;</apex:image>
<apex:image alt="Red" url="https://cs6.salesforce.com/resource/1390282570000/Red">Student Not Sponsored - &nbsp;</apex:image>
</apex:panelGrid>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageblock title="Filtering Criteria" id="pb1" rendered="{!(isExport = false)}">
<apex:pageBlockSection columns="5">
<apex:inputField value="{!con.STD__c }" label="Student Standards"/>
<apex:inputField value="{!oppObj.Student_Name__c}" label="Student Name"/>
<apex:inputField value="{!oppObj.AccountId}" label="Sponsor Name"/>
<apex:inputField value="{!oppObj.Sponsorship_For__c}" label="Sponsorship For"/>
<apex:inputText value="{!oppObj.Name}" label="Opportunity Name"/>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Search" action="{!dynamicSearch}" rerender="pb2,pgNavigate" status="status1"/>
<apex:commandButton value="Reset" action="{!reset}" rerender="pb1" status="status1"/>
</apex:pageBlockButtons>
<apex:actionstatus id="status1">
<apex:facet name="start">
<img class="waitingImage" src="/img/loading.gif" title="Please Wait..." />
<span class="waitingDescription">Loading...</span>
</apex:facet>
</apex:actionstatus>
</apex:pageblock>
<apex:pageBlock title="Student Sponsor Report">
<apex:outputLabel style="font-weight:bold;font-size:12px;" rendered="{!(isExport = false)}">Sort Columns</apex:outputLabel>
<img src="/s.gif" alt="Help" class="helpIcon" title="{!$Label.Note}"/>
<apex:pageBlockTable value="{!OpportunityList}" var="o" rows="1000" id="pb2">
<apex:column >
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Student Standard{!IF(sortExpression=='Student_Name__r.STD__c',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort1" title="Click on this link to get values sorted in Ascending/Descending Order">
<apex:param value="Student_Name__r.STD__c" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!o.Student_Name__r.STD__c }"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Student Name{!IF(sortExpression=='Student_Name__c',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort2">
<apex:param value="Student_Name__c" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!o.Student_Name__c}"/>
</apex:column>
<apex:column >
<div style="background-color:{!If(o.Account.Name != Null,'‪#‎FFFF00‬','‪#‎FFFFFF‬' )};">
{!o.Account.Name}
</div>
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Sponsor Name{!IF(sortExpression=='Account.Name',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort3">
<apex:param value="Account.Name" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column headerValue="Sponsorship For">
<a href="/{!o.Account.Id}" id="{!o.Account.Id}" onblur="LookupHoverDetail.getHover('{!o.Account.Id}').hide();" onfocus="LookupHoverDetail.getHover('{!o.Account.Id}', '/{!o.Account.Id}/m?retURL=%2F{!o.Account.Id}&isAjaxRequest=1').show();" onmouseout="LookupHoverDetail.getHover('{!o.Account.Id}').hide();" onmouseover="LookupHoverDetail.getHover('{!o.Account.Id}', '/{!o.Id}/m?retURL=%2F{!o.Account.Id}&isAjaxRequest=1').show();">
<div style="background-color:{!If(o.StageName = "Posted",'‪#‎00CC33‬',If(o.StageName = "Prospecting",'‪#‎FF9900‬','‪#‎FF0000‬'))};">
{!o.Sponsorship_For__c}
</div>
</a>
</apex:column>
<apex:column >
<div style="background-color:{!If(o.StageName = "Posted",'#00CC33',If(o.StageName = "Prospecting",'#FF9900','#FF0000'))};">
{!o.StageName}
</div>
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Stage Name{!IF(sortExpression=='StageName',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort5">
<apex:param value="StageName" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Sponsroship Date{!IF(sortExpression=='Sponsorship_Date__c',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort6">
<apex:param value="Sponsorship_Date__c" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!o.Sponsorship_Date__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Opportunity Name{!IF(sortExpression=='Name',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort7">
<apex:param value="Name" name="column" assignTo="{!sortExpression}" ></apex:param>
</apex:commandLink>
</apex:facet>
<apex:commandLink action="{!View}" immediate="true" target="_blank">{!o.Name}
<apex:param name="id" value="{!o.id}"/>
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
<!--Pagination for PageBlock Table -->
<apex:outputPanel layout="block" styleClass="pSearchShowMore" id="pgNavigate">
<center>
<font style="color:red">Total Records Found: <apex:outputText rendered="{!IF(pgn.resultSize==10000,true,false)}">10000 +</apex:outputText><apex:outputText rendered="{!IF(pgn.resultSize < 10000,true,false)}">{!pgn.resultSize}</apex:outputText>
&nbsp;<apex:image url="/img/search_prevarrow_disabled.gif" styleClass="prevArrow" rendered="{!NOT(pgn.HasPrevious)}"/>
<apex:image url="/img/search_prevarrow.gif" title="Previous Page" styleClass="prevArrow" rendered="{!pgn.HasPrevious}"/>
<apex:commandLink action="{!Previous}" title="Previous Page" value="Previous Page" rendered="{!pgn.HasPrevious}"/>
<apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(pgn.HasPrevious)}">Previous Page</apex:outputPanel>
&nbsp;({!IF(pgn.PageNumber == 1,1,((pgn.PageNumber -1) * pgn.PageSize)+1)}-{!IF(pgn.resultSize < pgn.PageSize,pgn.resultSize,pgn.PageNumber * pgn.pageSize)})&nbsp;
<apex:outputPanel styleClass="pShowLess noLink" style="color:grey" rendered="{!NOT(pgn.HasNext)}">Next Page</apex:outputPanel>
<apex:commandLink title="Next Page" value="Next Page" rendered="{!pgn.HasNext}" action="{!Next}"/>&nbsp;
<apex:image url="/img/search_nextarrow.gif" title="Next Page" styleClass="nextArrow" rendered="{!pgn.HasNext}"/>
<apex:image url="/img/search_nextarrow_disabled.gif" rendered="{!NOT(pgn.HasNext)}"/></font>
</center>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Hi All,

I would like to get the Contact phone number on associated Opportunities?

How can i get it?

Thanks in advance...................
Hi All,

I have a 3 Triggers in my Sandbox,
I would like to deploy my Appliction into production,
But The Total Test coverage of organization is 70%,
I want to increase my Test code coverage 75% +.
For those Triggers we have managed Test classes .
The managed coe is unavailable.

How can i increase my code coverage?

can anyone help me out,

Thanks in advance.
Hi Everyone,

I have date field,if i change this in one record,it will affects all the records by using batch apex,
will it possible?
If possible how?

Thanks in advance..............
Hi Everyone,
Iam  dealing with one  NGO Project.

If I want to change the start and finish dates on the campaign, can I do this so it effects all the HH's and Organizations?
if I decided my end date is 4/1/2014 instead of 3/1/2014, can I change this in one place that will effect all the fields on Households or Organizations?

Thanks in advance.............
Hi Everyone,

I have two custom fields(below) on opportunity where Record Type="Rec1"
Donor_nme__c(Text)
Donor_Mobile__c(phone).
I want to update these fields from contact.

Can any one help me out?

Thanks in advance?

Hi All,

I have 3 Rollup summary fields on Household object  like R1,R2,R3(nothing but R1+R2),
these 3 fields caluculates total donations since 11/4/2008,
I now want these three fields to finish and create two new sets of fields where we can define a new set of start and stop dates.

Would that be possible?

Thanks in advance.........
Hi Everyone,

If Opportunity Name and Account Name not equal to null,
then i want to update a custom lookup field with associated contact.


Can anyone Tell, How do we do it?

Thanks in advance.

Hi EveryOne,

I have a Extensions on Oppportunity, which sends the Email with two Visualforce Pdf file attachments.
I need to write a test class for it,
As of now, My test coverage is 8%.
Please find my Code below.

Extension Code:
 
//Send email with Multiple attachments, and before sending edit template
public class SendEmail {

    public Account acc;
    public String body { get; set; }    
    Product_EmailTemplates__c template;//Custom settings to read the template, which template to send
    public Opportunity opp { get; set;}
    public String subject { get; set; }
    public String htmlBody {get; set;}
    

    // Create a constructor that populates the Opportunity object
    public SendEmail(ApexPages.StandardController controller) {        
        opp = [Select Id, Name, Email__c, Amount, Contact_Name__c, Account.PersonContactId, Account.id, Product__r.Name, Account.Name, StageName, Tax_Amount__c, Total_after_Tax__c, 
               payment_1_Amount__c, Payment_2_Amount__c, Payment_3_Amount__c, Payment_1_Before_Tax__c, Payment_2_Before_Tax__c, Payment_3_Before_Tax__c, Payment_1_Tax_Amount__c, 
               Payment_2_Tax_Amount__c, Payment_3_Tax_Amount__c, Potential_Number__c,Branch_Name__c, Branch_Name__r.Name, Branch_Name__r.Address_1__c, Branch_Name__r.Address_2__c, Branch_Name__r.City__c, 
               Branch_Name__r.Country__c, Branch_Name__r.Main_Phone_1__c, Branch_Name__r.Main_Phone_2__c, Branch_Name__r.Main_Phone_3__c, Branch_Name__r.Region__c, Branch_Name__r.State__c, 
               Branch_Name__r.Zip_Postal_Code__c, Product__r.Product_Type__c, Admin_Fee__c, Payment_1_plus_Admin_Fee__c
                    from Opportunity where Id = :ApexPages.currentPage().getParameters().get('id')];
              
        EmailTemplate emailTemplate = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Id = :getTemplateId(opp.Product__r.Name, opp.Product__r.Product_Type__c)];
    
        htmlBody = emailTemplate.HtmlValue;
        subject = emailTemplate.subject;
    }
    
    //Send the email with two attachments
    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        
        //Send email if Branch not equals to Saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name != 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf1 =  Page.CCLPdf;//CCLPdf is a Visualforce page
            pdf1.getParameters().put('id',opp.id); 
            pdf1.setRedirect(true);
    
            // Take the PDF content
            Blob b1 = pdf1.getContentAsPDF();
            
            PageReference pdf2 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf2.getParameters().put('id',opp.id); 
            pdf2.setRedirect(true);
    
            // Take the PDF content
            Blob b2 = pdf2.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
            efa1.setFileName(opp.account.Name+'-CCL.pdf');//set the email attachment name
            efa1.setBody(b1);
            
            Messaging.EmailFileAttachment efa2 = new Messaging.EmailFileAttachment();
            efa2.setFileName(opp.account.Name+'-Invoice.pdf');//set the email attachment name
            efa2.setBody(b2);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1,efa2});
            StoringAttachments();
        }
        
        //Send email if Branch not equals to Saudi Arabia and Product type is Canada
        if(opp.Branch_Name__r.Name != 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf3 =  Page.CANCCLPdf;//CANCCLPdf is a Visualforce page
            pdf3.getParameters().put('id',opp.id); 
            pdf3.setRedirect(true);
    
            // Take the PDF content
            Blob b3 = pdf3.getContentAsPDF();
            
            PageReference pdf4 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf4.getParameters().put('id',opp.id); 
            pdf4.setRedirect(true);
    
            // Take the PDF content
            Blob b4 = pdf4.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa3 = new Messaging.EmailFileAttachment();
            efa3.setFileName(opp.account.Name+'-CANCCL.pdf');//set the email attachment name
            efa3.setBody(b3);
            
            Messaging.EmailFileAttachment efa4 = new Messaging.EmailFileAttachment();
            efa4.setFileName(opp.account.Name+'-CANInvoice.pdf');//set the email attachment name
            efa4.setBody(b4);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa3,efa4});
            StoringAttachments();
        }
        
        //Send email if Branch is saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf5 =  Page.KSACCLPdf;//KSACCLPdf is a Visualforce page
            pdf5.getParameters().put('id',opp.id); 
            pdf5.setRedirect(true);
    
            // Take the PDF content
            Blob b5 = pdf5.getContentAsPDF();
            
            PageReference pdf6 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf6.getParameters().put('id',opp.id); 
            pdf6.setRedirect(true);
    
            // Take the PDF content
            Blob b6 = pdf6.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa5 = new Messaging.EmailFileAttachment();
            efa5.setFileName(opp.account.Name+'-KSACCL.pdf');//set the email attachment name
            efa5.setBody(b5);
            
            Messaging.EmailFileAttachment efa6 = new Messaging.EmailFileAttachment();
            efa6.setFileName(opp.account.Name+'-KSAInvoice.pdf');//set the email attachment name
            efa6.setBody(b6);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa5,efa6});
            StoringAttachments();
         } 
         
         //Send email if Branch is saudi Arabia and Product type is Canada
         if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf7 =  Page.KSACANCCLPdf;//KSACANCCLPdf is a Visualforce page
            pdf7.getParameters().put('id',opp.id); 
            pdf7.setRedirect(true);
    
            // Take the PDF content
            Blob b7 = pdf7.getContentAsPDF();
            
            PageReference pdf8 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf8.getParameters().put('id',opp.id); 
            pdf8.setRedirect(true);
    
            // Take the PDF content
            Blob b8 = pdf8.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa7 = new Messaging.EmailFileAttachment();
            efa7.setFileName(opp.account.Name+'-KSACANCCL.pdf');//set the email attachment name
            efa7.setBody(b7);
            
            Messaging.EmailFileAttachment efa8 = new Messaging.EmailFileAttachment();
            efa8.setFileName(opp.account.Name+'-KSACANInvoice.pdf');//set the email attachment name
            efa8.setBody(b8);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa7,efa8});
            StoringAttachments();
         } 
    
            // Sends the email
            Messaging.SendEmailResult [] r = 
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
        
        
        return new PageReference('/'+opp.Id);
    }
    
    //Creating attachments
    public void StoringAttachments() {
        //Send attachments if Branch is India and Product type is Standard
        if((opp.Branch_Name__r.Name == 'India' || opp.Branch_Name__r.Name == 'United Kingdom') && opp.Product__r.Product_Type__c == 'Standard'){
            Attachment myAttach1 = new Attachment();
            myAttach1.ParentId = opp.Account.PersonContactId;
            myAttach1.name = opp.account.Name+'-CCL.pdf';
            PageReference myPdf1 = Page.CCLPdf;
            myAttach1.body = myPdf1.getContentAsPdf();
            insert myAttach1;
            
            Attachment myAttach2 = new Attachment();
            myAttach2.ParentId = opp.Account.PersonContactId;
            myAttach2.name = opp.account.Name+'-Invoice.pdf';
            PageReference myPdf2 = Page.ProformaInvoicePdf;
            myAttach2.body = myPdf2.getContentAsPdf();
            insert myAttach2;
        }
        
        //Send attachments if Branch is India and Product type is Canada
        if((opp.Branch_Name__r.Name == 'India' || opp.Branch_Name__r.Name == 'United Kingdom') && opp.Product__r.Product_Type__c == 'Canada'){
            Attachment myAttach3 = new Attachment();
            myAttach3.ParentId = opp.Account.PersonContactId;
            myAttach3.name = opp.account.Name+'-CANCCL.pdf';
            PageReference myPdf3 = Page.CANCCLPdf;
            myAttach3.body = myPdf3.getContentAsPdf();
            insert myAttach3;
            
            Attachment myAttach4 = new Attachment();
            myAttach4.ParentId = opp.Account.PersonContactId;
            myAttach4.name = opp.account.Name+'-CANInvoice.pdf';
            PageReference myPdf4 = Page.ProformaInvoicePdf;
            myAttach4.body = myPdf4.getContentAsPdf();
            insert myAttach4;
        }
        
        //Send attachments if Branch is saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            Attachment myAttach5 = new Attachment();
            myAttach5.ParentId = opp.Account.PersonContactId;
            myAttach5.name = opp.account.Name+'-KSACCL.pdf';
            PageReference myPdf5 = Page.KSACCLPdf;
            myAttach5.body = myPdf5.getContentAsPdf();
            insert myAttach5;
            
            Attachment myAttach6 = new Attachment();
            myAttach6.ParentId = opp.Account.PersonContactId;
            myAttach6.name = opp.account.Name+'-KSAInvoice.pdf';
            PageReference myPdf6 = Page.ProformaInvoicePdf;
            myAttach6.body = myPdf6.getContentAsPdf();
            insert myAttach6;
        }
        
        //Send attachments if Branch is saudi Arabia and Product type is Canada
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            Attachment myAttach7 = new Attachment();
            myAttach7.ParentId = opp.Account.PersonContactId;
            myAttach7.name = opp.account.Name+'-KSACANCCL.pdf';
            PageReference myPdf7 = Page.KSACANCCLPdf;
            myAttach7.body = myPdf7.getContentAsPdf();
            insert myAttach7;
            
            Attachment myAttach8 = new Attachment();
            myAttach8.ParentId = opp.Account.PersonContactId;
            myAttach8.name = opp.account.Name+'-KSACANInvoice.pdf';
            PageReference myPdf8 = Page.ProformaInvoicePdf;
            myAttach8.body = myPdf8.getContentAsPdf();
            insert myAttach8;
        }
    } 
    
    //Reads the Template from Custom settings        
    public String getTemplateId(String prodName, String prodType){
       template = [Select Name, Email_Template_Id__c, Product_Type__c from Product_EmailTemplates__c 
                        where Name = : prodName and Product_Type__c = : prodType];
       return template.Email_Template_Id__c;
   }

}

Can anyone please help me to write a Test class for my Extensions?

Thanks In Advance.......
Ranjith
 
Hi Everyone,

I have a Extensions on Oppportunity, which sends the Email with two Visualforce Pdf file attachments.
I need to write a test class for it,
As of now, My test coverage is 8%.
Please find my Code below.

Extensions and Test class Code:
 
//Send email with Multiple attachments, and before sending edit template
public class SendEmail {

    public Account acc;
    public String body { get; set; }    
    Product_EmailTemplates__c template;//Custom settings to read the template, which template to send
    public Opportunity opp { get; set;}
    public String subject { get; set; }
    public String htmlBody {get; set;}
    

    // Create a constructor that populates the Opportunity object
    public SendEmail(ApexPages.StandardController controller) {        
        opp = [Select Id, Name, Email__c, Amount, Contact_Name__c, Account.PersonContactId, Account.id, Product__r.Name, Account.Name, StageName, Tax_Amount__c, Total_after_Tax__c, 
               payment_1_Amount__c, Payment_2_Amount__c, Payment_3_Amount__c, Payment_1_Before_Tax__c, Payment_2_Before_Tax__c, Payment_3_Before_Tax__c, Payment_1_Tax_Amount__c, 
               Payment_2_Tax_Amount__c, Payment_3_Tax_Amount__c, Potential_Number__c,Branch_Name__c, Branch_Name__r.Name, Branch_Name__r.Address_1__c, Branch_Name__r.Address_2__c, Branch_Name__r.City__c, 
               Branch_Name__r.Country__c, Branch_Name__r.Main_Phone_1__c, Branch_Name__r.Main_Phone_2__c, Branch_Name__r.Main_Phone_3__c, Branch_Name__r.Region__c, Branch_Name__r.State__c, 
               Branch_Name__r.Zip_Postal_Code__c, Product__r.Product_Type__c, Admin_Fee__c, Payment_1_plus_Admin_Fee__c
                    from Opportunity where Id = :ApexPages.currentPage().getParameters().get('id')];
              
        EmailTemplate emailTemplate = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Id = :getTemplateId(opp.Product__r.Name, opp.Product__r.Product_Type__c)];
    
        htmlBody = emailTemplate.HtmlValue;
        subject = emailTemplate.subject;
    }
    
    //Send the email with two attachments
    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        
        //Send email if Branch not equals to Saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name != 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf1 =  Page.CCLPdf;//CCLPdf is a Visualforce page
            pdf1.getParameters().put('id',opp.id); 
            pdf1.setRedirect(true);
    
            // Take the PDF content
            Blob b1 = pdf1.getContentAsPDF();
            
            PageReference pdf2 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf2.getParameters().put('id',opp.id); 
            pdf2.setRedirect(true);
    
            // Take the PDF content
            Blob b2 = pdf2.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
            efa1.setFileName(opp.account.Name+'-CCL.pdf');//set the email attachment name
            efa1.setBody(b1);
            
            Messaging.EmailFileAttachment efa2 = new Messaging.EmailFileAttachment();
            efa2.setFileName(opp.account.Name+'-Invoice.pdf');//set the email attachment name
            efa2.setBody(b2);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1,efa2});
            StoringAttachments();
        }
        
        //Send email if Branch not equals to Saudi Arabia and Product type is Canada
        if(opp.Branch_Name__r.Name != 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf3 =  Page.CANCCLPdf;//CANCCLPdf is a Visualforce page
            pdf3.getParameters().put('id',opp.id); 
            pdf3.setRedirect(true);
    
            // Take the PDF content
            Blob b3 = pdf3.getContentAsPDF();
            
            PageReference pdf4 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf4.getParameters().put('id',opp.id); 
            pdf4.setRedirect(true);
    
            // Take the PDF content
            Blob b4 = pdf4.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa3 = new Messaging.EmailFileAttachment();
            efa3.setFileName(opp.account.Name+'-CANCCL.pdf');//set the email attachment name
            efa3.setBody(b3);
            
            Messaging.EmailFileAttachment efa4 = new Messaging.EmailFileAttachment();
            efa4.setFileName(opp.account.Name+'-CANInvoice.pdf');//set the email attachment name
            efa4.setBody(b4);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa3,efa4});
            StoringAttachments();
        }
        
        //Send email if Branch is saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf5 =  Page.KSACCLPdf;//KSACCLPdf is a Visualforce page
            pdf5.getParameters().put('id',opp.id); 
            pdf5.setRedirect(true);
    
            // Take the PDF content
            Blob b5 = pdf5.getContentAsPDF();
            
            PageReference pdf6 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf6.getParameters().put('id',opp.id); 
            pdf6.setRedirect(true);
    
            // Take the PDF content
            Blob b6 = pdf6.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa5 = new Messaging.EmailFileAttachment();
            efa5.setFileName(opp.account.Name+'-KSACCL.pdf');//set the email attachment name
            efa5.setBody(b5);
            
            Messaging.EmailFileAttachment efa6 = new Messaging.EmailFileAttachment();
            efa6.setFileName(opp.account.Name+'-KSAInvoice.pdf');//set the email attachment name
            efa6.setBody(b6);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa5,efa6});
            StoringAttachments();
         } 
         
         //Send email if Branch is saudi Arabia and Product type is Canada
         if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf7 =  Page.KSACANCCLPdf;//KSACANCCLPdf is a Visualforce page
            pdf7.getParameters().put('id',opp.id); 
            pdf7.setRedirect(true);
    
            // Take the PDF content
            Blob b7 = pdf7.getContentAsPDF();
            
            PageReference pdf8 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf8.getParameters().put('id',opp.id); 
            pdf8.setRedirect(true);
    
            // Take the PDF content
            Blob b8 = pdf8.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa7 = new Messaging.EmailFileAttachment();
            efa7.setFileName(opp.account.Name+'-KSACANCCL.pdf');//set the email attachment name
            efa7.setBody(b7);
            
            Messaging.EmailFileAttachment efa8 = new Messaging.EmailFileAttachment();
            efa8.setFileName(opp.account.Name+'-KSACANInvoice.pdf');//set the email attachment name
            efa8.setBody(b8);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa7,efa8});
            StoringAttachments();
         } 
    
            // Sends the email
            Messaging.SendEmailResult [] r = 
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
        
        
        return new PageReference('/'+opp.Id);
    }
    
    //Creating attachments
    public void StoringAttachments() {
        //Send attachments if Branch is India and Product type is Standard
        if((opp.Branch_Name__r.Name == 'India' || opp.Branch_Name__r.Name == 'United Kingdom') && opp.Product__r.Product_Type__c == 'Standard'){
            Attachment myAttach1 = new Attachment();
            myAttach1.ParentId = opp.Account.PersonContactId;
            myAttach1.name = opp.account.Name+'-CCL.pdf';
            PageReference myPdf1 = Page.CCLPdf;
            myAttach1.body = myPdf1.getContentAsPdf();
            insert myAttach1;
            
            Attachment myAttach2 = new Attachment();
            myAttach2.ParentId = opp.Account.PersonContactId;
            myAttach2.name = opp.account.Name+'-Invoice.pdf';
            PageReference myPdf2 = Page.ProformaInvoicePdf;
            myAttach2.body = myPdf2.getContentAsPdf();
            insert myAttach2;
        }
        
        //Send attachments if Branch is India and Product type is Canada
        if((opp.Branch_Name__r.Name == 'India' || opp.Branch_Name__r.Name == 'United Kingdom') && opp.Product__r.Product_Type__c == 'Canada'){
            Attachment myAttach3 = new Attachment();
            myAttach3.ParentId = opp.Account.PersonContactId;
            myAttach3.name = opp.account.Name+'-CANCCL.pdf';
            PageReference myPdf3 = Page.CANCCLPdf;
            myAttach3.body = myPdf3.getContentAsPdf();
            insert myAttach3;
            
            Attachment myAttach4 = new Attachment();
            myAttach4.ParentId = opp.Account.PersonContactId;
            myAttach4.name = opp.account.Name+'-CANInvoice.pdf';
            PageReference myPdf4 = Page.ProformaInvoicePdf;
            myAttach4.body = myPdf4.getContentAsPdf();
            insert myAttach4;
        }
        
        //Send attachments if Branch is saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            Attachment myAttach5 = new Attachment();
            myAttach5.ParentId = opp.Account.PersonContactId;
            myAttach5.name = opp.account.Name+'-KSACCL.pdf';
            PageReference myPdf5 = Page.KSACCLPdf;
            myAttach5.body = myPdf5.getContentAsPdf();
            insert myAttach5;
            
            Attachment myAttach6 = new Attachment();
            myAttach6.ParentId = opp.Account.PersonContactId;
            myAttach6.name = opp.account.Name+'-KSAInvoice.pdf';
            PageReference myPdf6 = Page.ProformaInvoicePdf;
            myAttach6.body = myPdf6.getContentAsPdf();
            insert myAttach6;
        }
        
        //Send attachments if Branch is saudi Arabia and Product type is Canada
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            Attachment myAttach7 = new Attachment();
            myAttach7.ParentId = opp.Account.PersonContactId;
            myAttach7.name = opp.account.Name+'-KSACANCCL.pdf';
            PageReference myPdf7 = Page.KSACANCCLPdf;
            myAttach7.body = myPdf7.getContentAsPdf();
            insert myAttach7;
            
            Attachment myAttach8 = new Attachment();
            myAttach8.ParentId = opp.Account.PersonContactId;
            myAttach8.name = opp.account.Name+'-KSACANInvoice.pdf';
            PageReference myPdf8 = Page.ProformaInvoicePdf;
            myAttach8.body = myPdf8.getContentAsPdf();
            insert myAttach8;
        }
    } 
    
    //Reads the Template from Custom settings        
    public String getTemplateId(String prodName, String prodType){
       template = [Select Name, Email_Template_Id__c, Product_Type__c from Product_EmailTemplates__c 
                        where Name = : prodName and Product_Type__c = : prodType];
       return template.Email_Template_Id__c;
   }

}

Test Class:

@isTest(seeAllData=true)
public class CreateCaseTests{

     private static Id leadId;

static testMethod void testCreateCase() {
    
        
        //Inserting Products
        Product2 prod = new Product2();
        prod.Name = 'Resident Visa';
        prod.ProductCode = 'RV';
        insert prod;
        
        //Inserting Products
        Product2 prod1 = new Product2();
        prod1.Name = 'Permanant Visa';
        prod1.ProductCode = 'PV';
        insert prod1;
        
        //get standard pricebook
        Pricebook2  standardPb = [select Id, Name, isActive from Pricebook2 where IsStandard = true limit 1];
        
        //Inserting pricebook
        Pricebook2 pb = new Pricebook2();
        pb.Name = 'India';
        pb.IsActive= true;
        insert pb;
        
        //Inserting pricebook
        Pricebook2 pb1 = new Pricebook2();
        pb1.Name = 'Saudi Arabia';
        pb1.IsActive= true;
        insert pb1;
        
        //Inserting pricebookEntry
        PricebookEntry pbe = new PricebookEntry();
        pbe.Pricebook2Id = standardPb.Id;
        pbe.Product2Id = prod.Id;
        pbe.UnitPrice = 1.0;
        //pbe.UseStandardPrice = true;
        pbe.IsActive = true;
        insert pbe;
        
        //Inserting pricebookEntry
        PricebookEntry pbe1 = new PricebookEntry();
        pbe1.Pricebook2Id = standardPb.Id;
        pbe1.Product2Id = prod1.Id;
        pbe1.UnitPrice = 1.0;
        //pbe.UseStandardPrice = true;
        pbe1.IsActive = true;
        insert pbe1;
        
        Lead testLead = new Lead();
            testLead.FirstName = 'Test First';
            testLead.LastName = 'Test Last';
            //testLead.Company = 'Test Co';
            //testLead.RecordTypeId = '012110000004b9Q';
            testLead.Status = 'Converted';
            testLead.LeadSource = 'Web';
            testLead.Date_Received__c = System.Today();
            testLead.Email = 'ranjith@rixyncs.co.in';
            testLead.Payment_Plan__c = '2 Monthly Payments';
            testLead.Phone = '+919590854842';
            testLead.MobilePhone = '+919590854842';
            //testLead.Branch__c = 'India';
            testLead.CurrencyIsoCode = 'INR';
            testLead.Destination_Visa__c = 'Denmark';
            testLead.Product__c = prod.Id;
            testLead.Date_of_Birth__c = System.Today();
            testLead.Age__c = 30;
            testLead.Occupation__c = 'SE';
            testLead.Number_of_years_in_this_occupation__c = 2;
            testLead.Highest_Qualification__c = 'MCA';
            testLead.Experience__c = 'Full - Time';
            testLead.Dependents__c = '2';
            testLead.Nationality_Immigration_Status__c = 'Pending';
            testLead.Criminal_Health__c = 'No';
            testLead.Job_Offer__c = True;
            testLead.Maintenance__c = 'Yes';
            testLead.Family_Links__c = True;
            testLead.Country = 'India';
            testLead.Country__c = 'India';
            insert testLead;
            leadId = testLead.Id;
            
            System.currentPagereference().getParameters().put('id',testLead.id);

        
        
        
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(leadId);
        //lc.setAccountId(myRecordType.Id) ;
        //lc.strAccountId= '1';
        //lc.strContactId= '1';
        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        //lcr.getAccountId();
        //lcr.getContactId();
        //lcr.getOpportunityId();
        
        //this line returned my lead with isConverted:true and ids for related contact and account
    /*Lead leadFromDB = [select 
                       FirstName,
                       LastName,
                       Country,
                       isConverted,
                       ConvertedAccountId,
                       ConvertedContactId
                       from Lead where id = : testLead.Id];
    System.debug('this lead looks like: ' + leadFromDB);

    // successfully queried contact, would produce query exception if no contact found
    Contact c = [select Id,FirstName,LastName from Contact where Id = : leadFromDB.ConvertedContactId];

    // again success, no query exception
    Account a = [select Id,Name from Account where Id = : leadFromDB.ConvertedAccountId];

    // confirmation in my log of what I got back.
    System.debug(c);
    System.debug(a);*/

    //System.assert(lcr.isSuccess()); //<--assert passed   
        
        System.assert(lcr.isSuccess());
        

    
        /*Inserting Lead and converting
        Lead ld = new Lead();
        ld.LastName='Doe';
        ld.FirstName='John';
        ld.Company='Test';
        ld.Status = 'Converted';
        ld.LeadSource = 'Web';
        ld.Date_Received__c = System.Today();
        ld.Email = 'ranjith@rixyncs.co.in';
        ld.Payment_Plan__c = '2 Monthly Payments';
        ld.Phone = '+919590854842';
        ld.MobilePhone = '+919590854842';
        ld.Branch__c = 'India';
        ld.CurrencyIsoCode = 'INR';
        ld.Destination_Visa__c = 'Denmark';
        ld.Product__c = prod.Id;
        ld.Date_of_Birth__c = System.Today();
        ld.Age__c = 30;
        ld.Occupation__c = 'SE';
        ld.Number_of_years_in_this_occupation__c = 2;
        ld.Highest_Qualification__c = 'MCA';
        ld.Experience__c = 'Full - Time';
        ld.Dependents__c = '2';
        ld.Nationality_Immigration_Status__c = 'Pending';
        ld.Criminal_Health__c = 'No';
        ld.Job_Offer__c = True;
        ld.Maintenance__c = 'Yes';
        ld.Family_Links__c = True;
        insert ld;            


        ld =  [SELECT Id,Status, FirstName,LastName,Company,LeadSource
             FROM Lead
             WHERE Id = :ld.Id];

        System.assertEquals('Converted', ld.Status);*/
        
        RecordType myRecordType = [select id from RecordType where SobjectType='Account' AND IsPersonType=True limit 1];
    
        //Inserting Account
        Account acc = new Account();
        acc.LastName = 'Ranjith';
        acc.RecordTypeId = myRecordType.Id;
        insert acc;
        
        //Inserting Contact
        Contact con = new Contact();
        con.LastName = 'kumar';
        //con.AccountId = acc.Id;
        insert con;    
              
                
        
        
        //Inserting Potential
        Opportunity opp = new Opportunity();
        opp.Name = 'Ranjith kumar';
        //opp.Potential_Number__c = '0011';
        opp.AccountId = acc.Id;
        opp.CloseDate = System.today()+20;
        opp.StageName = 'CCL Sent';
        opp.Contact_Name__c = con.Id;
        opp.Type  = 'Existing Business';
        opp.English_Language__c  = 'Vocational';
        opp.Payment_Plan__c = '2 Monthly Payments';
        opp.Tax_Amount__c = 1000.00;
        opp.Total_after_Tax__c = 1000000.00;
        opp.Amount = 10000000.00;
        opp.Date_of_Birth__c = System.today();
        opp.Destination_Visa__c = 'US';
        opp.TimeFrame__c = '3 Months';
        opp.Eligibility_Score__c = 60;
        //opp.Branch__c = 'India';
        opp.Occupation__c = 'SE';
        opp.Number_of_years_in_this_occupation__c = 2;
        opp.Highest_Qualification__c = 'MCA';
        opp.Experience__c = 'Full - Time';
        opp.Dependents__c = '2';
        opp.Nationality_Immigration_Status__c = 'Pending';
        opp.Criminal_Health__c = 'No';
        opp.Job_Offer__c = True;
        opp.Maintenance__c = 'Yes';
        opp.Family_Links__c = True;
        opp.payment_1_Amount__c = 100.00;
        opp.Payment_2_Amount__c = 100.00;
        opp.Payment_3_Amount__c = 100.00;
        opp.Payment_1_Received_Date__c = System.today();
        opp.Payment_2_Due_Date__c = System.today()+30;
        opp.Payment_3_Due_Date__c = System.today()+60;
        opp.Payment_1_Before_Tax__c = 100.00;
        opp.Payment_2_Before_Tax__c = 100.00;
        opp.Payment_3_Before_Tax__c = 100.00;
        opp.Payment_1_Status__c = 'Received';
        opp.Payment_2_Status__c = 'Pending';
        opp.Payment_3_Status__c = 'Pending';   
        opp.Pricebook2Id  = pbe.Pricebook2Id; 
        opp.Product__c = prod.Id;
        insert opp;
    System.currentPagereference().getParameters().put('id',opp.id);
         Blob content;        
         PageReference pf = page.CCLPdf;
         Attachment objAtt = new Attachment();
         objAtt.Name = opp.Account.Name + '-CCL.Pdf';
         objAtt.body =  Blob.valueof('string');
         objAtt.ParentId = opp.Id;        
         if (Test.IsRunningTest()){
                content=Blob.valueOf('UNIT.TEST');
             }else{
                content=pf.getContent();
             }
         insert objAtt;
        
ApexPages.StandardController stdController = new ApexPages.StandardController(opp); 
        SendEmail send = new SendEmail(stdController);
        
        send.send();
        send.StoringAttachments();
        send.getTemplateId('Permanant Visa','Standard');
        
    
      }
    
}


Can anyone please help me to write a Test class for my Extensions?

Thanks In Advance.......
Ranjith

 
Hello Everyone,

How to exclude Weekends on Workflow Task Due Dates?
On Workflow Tasks, we are setting up a due date extending with 'X' days, here, we need to exclude the weekends.

For Example, if we setup a workflow task to "Rule Triggered Date + 5 Days" and if that 5th day falls on weekend either Saturday or Sunday, SF should automatically consider the next Business Day, i.e Monday.

Different Workflows have different Due Dates, need to work it for all Workflow Tasks (on different Objects), irrespective of Due Date.
And Different Workflows have multiple actions like Email Alert, Field Update and Outbound Messages along with Tasks.

Can any one please help me out on achieving same?

Thanks in Advance,
Ranjith.
Hello Everyone,

I have one multiple picklist field and I have a,b,c,d as values in it. And if I want to select either "a or b" OR "a and b", I would like to update one text field with "AB", if I want to select either " c or d" OR "c and d", I would like to update same text field with "CD", if I want to select all values or one value of " a or b" and "c or d", I would like to update same text field with "both".

Can we do this with workflow field update, if yes, please give me some ideas?
Thanks in advance
Hi EveryOne,

I have a Extensions on Oppportunity, which sends the Email with two Visualforce Pdf file attachments.
I need to write a test class for it,
As of now, My test coverage is 8%.
Please find my Code below.

Extension Code:
 
//Send email with Multiple attachments, and before sending edit template
public class SendEmail {

    public Account acc;
    public String body { get; set; }    
    Product_EmailTemplates__c template;//Custom settings to read the template, which template to send
    public Opportunity opp { get; set;}
    public String subject { get; set; }
    public String htmlBody {get; set;}
    

    // Create a constructor that populates the Opportunity object
    public SendEmail(ApexPages.StandardController controller) {        
        opp = [Select Id, Name, Email__c, Amount, Contact_Name__c, Account.PersonContactId, Account.id, Product__r.Name, Account.Name, StageName, Tax_Amount__c, Total_after_Tax__c, 
               payment_1_Amount__c, Payment_2_Amount__c, Payment_3_Amount__c, Payment_1_Before_Tax__c, Payment_2_Before_Tax__c, Payment_3_Before_Tax__c, Payment_1_Tax_Amount__c, 
               Payment_2_Tax_Amount__c, Payment_3_Tax_Amount__c, Potential_Number__c,Branch_Name__c, Branch_Name__r.Name, Branch_Name__r.Address_1__c, Branch_Name__r.Address_2__c, Branch_Name__r.City__c, 
               Branch_Name__r.Country__c, Branch_Name__r.Main_Phone_1__c, Branch_Name__r.Main_Phone_2__c, Branch_Name__r.Main_Phone_3__c, Branch_Name__r.Region__c, Branch_Name__r.State__c, 
               Branch_Name__r.Zip_Postal_Code__c, Product__r.Product_Type__c, Admin_Fee__c, Payment_1_plus_Admin_Fee__c
                    from Opportunity where Id = :ApexPages.currentPage().getParameters().get('id')];
              
        EmailTemplate emailTemplate = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Id = :getTemplateId(opp.Product__r.Name, opp.Product__r.Product_Type__c)];
    
        htmlBody = emailTemplate.HtmlValue;
        subject = emailTemplate.subject;
    }
    
    //Send the email with two attachments
    public PageReference send() {
        // Define the email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        
        //Send email if Branch not equals to Saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name != 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf1 =  Page.CCLPdf;//CCLPdf is a Visualforce page
            pdf1.getParameters().put('id',opp.id); 
            pdf1.setRedirect(true);
    
            // Take the PDF content
            Blob b1 = pdf1.getContentAsPDF();
            
            PageReference pdf2 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf2.getParameters().put('id',opp.id); 
            pdf2.setRedirect(true);
    
            // Take the PDF content
            Blob b2 = pdf2.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
            efa1.setFileName(opp.account.Name+'-CCL.pdf');//set the email attachment name
            efa1.setBody(b1);
            
            Messaging.EmailFileAttachment efa2 = new Messaging.EmailFileAttachment();
            efa2.setFileName(opp.account.Name+'-Invoice.pdf');//set the email attachment name
            efa2.setBody(b2);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1,efa2});
            StoringAttachments();
        }
        
        //Send email if Branch not equals to Saudi Arabia and Product type is Canada
        if(opp.Branch_Name__r.Name != 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf3 =  Page.CANCCLPdf;//CANCCLPdf is a Visualforce page
            pdf3.getParameters().put('id',opp.id); 
            pdf3.setRedirect(true);
    
            // Take the PDF content
            Blob b3 = pdf3.getContentAsPDF();
            
            PageReference pdf4 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf4.getParameters().put('id',opp.id); 
            pdf4.setRedirect(true);
    
            // Take the PDF content
            Blob b4 = pdf4.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa3 = new Messaging.EmailFileAttachment();
            efa3.setFileName(opp.account.Name+'-CANCCL.pdf');//set the email attachment name
            efa3.setBody(b3);
            
            Messaging.EmailFileAttachment efa4 = new Messaging.EmailFileAttachment();
            efa4.setFileName(opp.account.Name+'-CANInvoice.pdf');//set the email attachment name
            efa4.setBody(b4);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa3,efa4});
            StoringAttachments();
        }
        
        //Send email if Branch is saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf5 =  Page.KSACCLPdf;//KSACCLPdf is a Visualforce page
            pdf5.getParameters().put('id',opp.id); 
            pdf5.setRedirect(true);
    
            // Take the PDF content
            Blob b5 = pdf5.getContentAsPDF();
            
            PageReference pdf6 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf6.getParameters().put('id',opp.id); 
            pdf6.setRedirect(true);
    
            // Take the PDF content
            Blob b6 = pdf6.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa5 = new Messaging.EmailFileAttachment();
            efa5.setFileName(opp.account.Name+'-KSACCL.pdf');//set the email attachment name
            efa5.setBody(b5);
            
            Messaging.EmailFileAttachment efa6 = new Messaging.EmailFileAttachment();
            efa6.setFileName(opp.account.Name+'-KSAInvoice.pdf');//set the email attachment name
            efa6.setBody(b6);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa5,efa6});
            StoringAttachments();
         } 
         
         //Send email if Branch is saudi Arabia and Product type is Canada
         if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            // Reference the attachment page and pass in the Opportunity ID
            PageReference pdf7 =  Page.KSACANCCLPdf;//KSACANCCLPdf is a Visualforce page
            pdf7.getParameters().put('id',opp.id); 
            pdf7.setRedirect(true);
    
            // Take the PDF content
            Blob b7 = pdf7.getContentAsPDF();
            
            PageReference pdf8 =  Page.ProformaInvoicePdf;//ProformaInvoicePdf is a Visualforce page
            pdf8.getParameters().put('id',opp.id); 
            pdf8.setRedirect(true);
    
            // Take the PDF content
            Blob b8 = pdf8.getContentAsPDF();
    
            // Create the email attachment
            Messaging.EmailFileAttachment efa7 = new Messaging.EmailFileAttachment();
            efa7.setFileName(opp.account.Name+'-KSACANCCL.pdf');//set the email attachment name
            efa7.setBody(b7);
            
            Messaging.EmailFileAttachment efa8 = new Messaging.EmailFileAttachment();
            efa8.setFileName(opp.account.Name+'-KSACANInvoice.pdf');//set the email attachment name
            efa8.setBody(b8);
            
            // Sets the paramaters of the email
            email.setSubject(subject);//Auto populate the Subject from Template
            email.setHtmlBody(htmlBody);//Auto populate the Body from Template
            //email.setTemplateId('00Xj0000000Yg9k');//getTemplateId(opp.Product__r.Name)
            email.setTargetObjectId(opp.Account.PersonContactId);
            email.setSaveAsActivity(true);
            email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa7,efa8});
            StoringAttachments();
         } 
    
            // Sends the email
            Messaging.SendEmailResult [] r = 
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
        
        
        return new PageReference('/'+opp.Id);
    }
    
    //Creating attachments
    public void StoringAttachments() {
        //Send attachments if Branch is India and Product type is Standard
        if((opp.Branch_Name__r.Name == 'India' || opp.Branch_Name__r.Name == 'United Kingdom') && opp.Product__r.Product_Type__c == 'Standard'){
            Attachment myAttach1 = new Attachment();
            myAttach1.ParentId = opp.Account.PersonContactId;
            myAttach1.name = opp.account.Name+'-CCL.pdf';
            PageReference myPdf1 = Page.CCLPdf;
            myAttach1.body = myPdf1.getContentAsPdf();
            insert myAttach1;
            
            Attachment myAttach2 = new Attachment();
            myAttach2.ParentId = opp.Account.PersonContactId;
            myAttach2.name = opp.account.Name+'-Invoice.pdf';
            PageReference myPdf2 = Page.ProformaInvoicePdf;
            myAttach2.body = myPdf2.getContentAsPdf();
            insert myAttach2;
        }
        
        //Send attachments if Branch is India and Product type is Canada
        if((opp.Branch_Name__r.Name == 'India' || opp.Branch_Name__r.Name == 'United Kingdom') && opp.Product__r.Product_Type__c == 'Canada'){
            Attachment myAttach3 = new Attachment();
            myAttach3.ParentId = opp.Account.PersonContactId;
            myAttach3.name = opp.account.Name+'-CANCCL.pdf';
            PageReference myPdf3 = Page.CANCCLPdf;
            myAttach3.body = myPdf3.getContentAsPdf();
            insert myAttach3;
            
            Attachment myAttach4 = new Attachment();
            myAttach4.ParentId = opp.Account.PersonContactId;
            myAttach4.name = opp.account.Name+'-CANInvoice.pdf';
            PageReference myPdf4 = Page.ProformaInvoicePdf;
            myAttach4.body = myPdf4.getContentAsPdf();
            insert myAttach4;
        }
        
        //Send attachments if Branch is saudi Arabia and Product type is Standard
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Standard'){
            Attachment myAttach5 = new Attachment();
            myAttach5.ParentId = opp.Account.PersonContactId;
            myAttach5.name = opp.account.Name+'-KSACCL.pdf';
            PageReference myPdf5 = Page.KSACCLPdf;
            myAttach5.body = myPdf5.getContentAsPdf();
            insert myAttach5;
            
            Attachment myAttach6 = new Attachment();
            myAttach6.ParentId = opp.Account.PersonContactId;
            myAttach6.name = opp.account.Name+'-KSAInvoice.pdf';
            PageReference myPdf6 = Page.ProformaInvoicePdf;
            myAttach6.body = myPdf6.getContentAsPdf();
            insert myAttach6;
        }
        
        //Send attachments if Branch is saudi Arabia and Product type is Canada
        if(opp.Branch_Name__r.Name == 'Saudi Arabia' && opp.Product__r.Product_Type__c == 'Canada'){
            Attachment myAttach7 = new Attachment();
            myAttach7.ParentId = opp.Account.PersonContactId;
            myAttach7.name = opp.account.Name+'-KSACANCCL.pdf';
            PageReference myPdf7 = Page.KSACANCCLPdf;
            myAttach7.body = myPdf7.getContentAsPdf();
            insert myAttach7;
            
            Attachment myAttach8 = new Attachment();
            myAttach8.ParentId = opp.Account.PersonContactId;
            myAttach8.name = opp.account.Name+'-KSACANInvoice.pdf';
            PageReference myPdf8 = Page.ProformaInvoicePdf;
            myAttach8.body = myPdf8.getContentAsPdf();
            insert myAttach8;
        }
    } 
    
    //Reads the Template from Custom settings        
    public String getTemplateId(String prodName, String prodType){
       template = [Select Name, Email_Template_Id__c, Product_Type__c from Product_EmailTemplates__c 
                        where Name = : prodName and Product_Type__c = : prodType];
       return template.Email_Template_Id__c;
   }

}

Can anyone please help me to write a Test class for my Extensions?

Thanks In Advance.......
Ranjith
 
Hi All,

I have a Custom object called Branch__c, which has Region__c and Country__c picklist fields.

Branch__c is a Lookup on Lead object.

Lead also have Region__c and Country__c picklist fields,

So, I want to update the Branch__c Lookup field on Lead, If the Branch Region__c and Country__c fields matches with Lead Region__c and Country__c.
If Branch Region__c is null. update the Lead Region__c with Bangalore.

For this I wrote a Trigger below.

It is saving without errors, but it will not update the Lookup field on Lead.
 
trigger UpdateBranch on Lead (before insert, before update) {
    Set<Id> ids = trigger.newmap.keySet();
    Lead ld;
    
    for (Lead lT:Trigger.new){
        ld = lT;
    }
    
    try{
        List<Branch__c> brList = [Select Id, Name, Country__c, Region__c, Email_ID__c from Branch__c where Id IN : ids];        
        Branch__c b = new Branch__c();
        for (Branch__c br : brList){
            if (brList .size() > 0 && ld.Country == br.Country__c && b.Region__c != Null){
                    ld.Branch_NAME__c = br.Id;
                    ld.Region__c = br.Region__c;
            }
            else{
                ld.Branch_NAME__c = null;
                ld.Region__c = 'Bangalore';
            }
        }
        }catch(Exception e){
         ld.addError('unable to find the Branch Name  ' + e.getMessage());
        }

}

Thanks in advance................
Hi Everyone,

I am enabled Multi currenies.

I would like to update my Lead currency based on the another picklist field(Branch).

For Example,
     If Branch is set to India, update the Lead currency with INR,
     If Branch is set to London, Update the Lead curency with GBP,
     If Branch is set to Saudi Arabia, Update the Lead currency with SAR.

How do we do that?

Can we do by Trigger?
If yes, can you please share some sample code here?

Thanks in advance........
 
Hi EveryOne,

The user request is that when a Custom button(Send Email) is clicked on the oportunity screen it should open a standard email UI and select the email template associated to the product for the template in that body and two attachments - attachment1  and attachment2 .

I am able to achieve all the functionality but we can add only one attachment. when we call the url to call that standard email page, we can only add one &docid = .

I am Passing this URL:

emailURL = '/_ui/core/email/author/EmailAuthor?p2_lkid=' + opp.Account.id + '&p3_lkid=' + opp.id + 
                    '&template_id='+getTemplateId(opp.Product__r.Name) + '&doc_id='+getCreatedDocId();

With this I am able to do the above functionality of sending email with one attachment.

How do I send 2 attachments?

Thanks In advance.........

I am sending my code below.
//Send the CCL Document to the potential when we cliclk the Send CCL Button.
public class CCLSendEmail {

    public Account acc;
    public Opportunity opp;
    public CCL_Documents__c cclDocs;//Custom settings
    Product_EmailTemplates__c template;//Custom settings
    public CCLSendEmail(ApexPages.StandardController controller){
        opp = [Select Id, Account.id, Product__r.Name, Account.Name,StageName from Opportunity where Id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
    public PageReference pdfEmail(){
        try{
            if(opp.StageName.equals('CCL Sent')){        
                String emailURL;
                emailURL = '/_ui/core/email/author/EmailAuthor?p2_lkid=' + opp.Account.id + '&p3_lkid=' + opp.id + 
                    '&template_id='+getTemplateId(opp.Product__r.Name) + '&doc_id='+getCreatedDocId();
                PageReference cclPage = new PageReference(emailURL); 
                cclPage.setRedirect(true); 
                return cclPage;
             }
             else{
                     ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING, 'Email Template is not there for this perticular Product');         
                     return null;
                  }
                  
             
              }catch(Exception e){
                    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.WARNING, e.getMessage()); 
                    ApexPages.addMessage(myMsg); 
                    return null;
       }  
   }
   
   
    public String getCreatedDocId(){
        Blob content;
        cclDocs = CCL_Documents__c.getInstance('VNP CCL Documents');
        PageReference pr = Page.CCLPdf; 
        pr.setRedirect(true); 
        pr = Page.CCLPdf; 
        pr.setRedirect(true); 
        pr.getParameters().put('id', opp.id); 
        
        if(!Test.isRunningTest()){ 
            content = pr.getContentAsPDF(); 
        } 
        
        Document doc = new Document(Name = opp.Account.Name+'.PDF', Body = content, FolderId = cclDocs.Document_Id__c);
        Database.SaveResult insertResult = Database.Insert(doc, true); 
        return doc.Id;
   }  
   
   
   public String getTemplateId(String prodName){
       template = [Select Name, Email_Template_Id__c from Product_EmailTemplates__c 
                        where Name = : prodName];
       return template.Email_Template_Id__c;
   }
}


 
Hi EveryOne,

I have 2 Queries,
1.) Can we have an alert message on the save for Opportunity record, whenever Stage becomes Posted?

2.) Can we have a Email section, open Activities, closed activities, Tasks and Events as a separate sections(like related lists)?

Thanks in Advance.

Hi All,


I wrote a Test class for 2 Triggers in Sandbox,

Earlier it covered 92%, before refreshed my Sandbox, and again when I Run my Test It is showing 0%, even though Test is passed.

I don't know why code coverage is 0%?

Can you please help me out?

Thanks in Advance...............

Hi All,

In my Sandbox(EE) we have 2 Triggers(Written by us), for that Triggers I covered the Code upto 92%.

Eventhough Code coverage is 92%, when i am moving from sanbox to Production by changesets, it showing the Error in Production as Test code Coverage failed and It showing the Code coverage 63% only.

Because of Managed Packages?

We need to cover the code for Managed Package also?

Please Let me know?


Thanks in Advance................
Hi All,

I have 2 picklist fields:
1.) Tenure of Support:Values are 3 Years, 4 Years, 5 Years
2.) Installment Period: Monthly, Quarterly, Half-Yearly, Yearly.

Installments: It is another Field(Number)

1.)If i select Tenure of SUpport as 3 Years and Installment Period as Monthly, then update the Installments as 36.
2.)If i select Tenure of SUpport as 4 Years and Installment Period as Monthly, then update the Installments as 48.
3.)If i select Tenure of SUpport as 5 Years and Installment Period as Monthly, then update the Installments as 60.
4.)If i select Tenure of SUpport as 3 Years and Installment Period as Quarterly, then update the Installments as 12.
5.)If i select Tenure of SUpport as 4 Years and Installment Period as Quarterly, then update the Installments as 16.
6.)If i select Tenure of SUpport as 5 Years and Installment Period as Quarterly, then update the Installments as 20.
7.)If i select Tenure of SUpport as 3 Years and Installment Period as Half-Yearly, then update the Installments as 6.
8.)If i select Tenure of SUpport as 4 Years and Installment Period as Half-Yearly, then update the Installments as 8.
9.)If i select Tenure of SUpport as 5 Years and Installment Period as Half-Yearly, then update the Installments as 10.
10)If i select Tenure of SUpport as 3 Years and Installment Period as Yearly, then update the Installments as 3.
11)If i select Tenure of SUpport as 4 Years and Installment Period as Yearly, then update the Installments as 4.
12)If i select Tenure of SUpport as 5 Years and Installment Period as Yearly, then update the Installments as 5.

For that, We are going to use the Field Update evaluates formula.

Is it achieve by Filed update?

If you Say Yes, Can you try out and let me know?

Thanks In Advance..........
Hi All,

I have a 3 Triggers in my Sandbox,
I would like to deploy my Appliction into production,
But The Total Test coverage of organization is 70%,
I want to increase my Test code coverage 75% +.
For those Triggers we have managed Test classes .
The managed coe is unavailable.

How can i increase my code coverage?

can anyone help me out,

Thanks in advance.
I am trying to create a trigger that will count activities (tasks) on leads.
My code is below....

When saving I am getting the following error....

Error: Compile Error: unexpected token: '}' at line 30 column 1

But if I remove the curly bracket I get a different error

Error: Compile Error: unexpected token: '<EOF>' at line 30 column 0


trigger TaskUpdateLead on Task (after delete, after insert, after undelete, after update)
{
Set<ID> LeadIds = new Set<ID>();

//We only care about tasks linked to Leads.

String leadPrefix = Lead.SObjectType.getDescribe().getKeyPrefix();

//Add any Lead ids coming from the new data

if (Trigger.new != null) {
    for (Task t : Trigger.new) {
     if (t.WhatId != null && string.valueOf(t.whatId).startsWith(leadprefix) )
         {LeadIds.add(t.whatId);
      }
   }
}
//Also add any Lead ids coming from the old data (deletes, moving an activity from one Lead to another)

if (Trigger.old != null) {
    for (Task t : Trigger.old) {
     if (t.WhatId != null && String.valueOf(t.whatId).startsWith(leadprefix) )
         { LeadIds.add(t.whatId);
      }
   }
}
if (LeadIds.size() > 0)

Lead.Activity_Count__c.updateLeadCount<LeadIds>
}


Any guidance is very much appreciated.
Hi Everyone,

I have date field,if i change this in one record,it will affects all the records by using batch apex,
will it possible?
If possible how?

Thanks in advance..............
Hi Everyone,
Iam  dealing with one  NGO Project.

If I want to change the start and finish dates on the campaign, can I do this so it effects all the HH's and Organizations?
if I decided my end date is 4/1/2014 instead of 3/1/2014, can I change this in one place that will effect all the fields on Households or Organizations?

Thanks in advance.............
Hi Everyone,

I have two custom fields(below) on opportunity where Record Type="Rec1"
Donor_nme__c(Text)
Donor_Mobile__c(phone).
I want to update these fields from contact.

Can any one help me out?

Thanks in advance?

Hi All,

I have 3 Rollup summary fields on Household object  like R1,R2,R3(nothing but R1+R2),
these 3 fields caluculates total donations since 11/4/2008,
I now want these three fields to finish and create two new sets of fields where we can define a new set of start and stop dates.

Would that be possible?

Thanks in advance.........
Hi Everyone,

If Opportunity Name and Account Name not equal to null,
then i want to update a custom lookup field with associated contact.


Can anyone Tell, How do we do it?

Thanks in advance.

I want to close the task on lead list page without going to task page an close. I just want to close the task by clicking cls link in front of created task. Please guide me, how can i do this.