• Priya134
  • NEWBIE
  • 50 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 9
    Replies
Hello,

When a create button is clicked on Quote, i want to populate some fields with some predifined values, how is it possible to do so ?
I have some lookup, and text fields to populate

Is it possible to do it in trigger ?

thanks for suggestion
  • April 12, 2017
  • Like
  • 0
Please help with the test class code coverage : I have only 74%.

public with sharing class TC_AttachmentTriggerHelper {
    public static void after (List<Attachment> triggerList) {
        Set<Id> oppIds = new Set<Id>();
        Set<Id> cSignIds = new Set<Id>();
        Set<Id> sign2Ids = new Set<Id>();
        Set<Id> allSignIds = new Set<Id>();
        Set<Id> ccgIds = new Set<Id>();
        List<Opportunity> oppList = new List<Opportunity>();
        Map<id,Opportunity> oppMap = new Map<id,Opportunity>();  
                
        //get all oppIds
        for (Attachment att: triggerList ) {
            if(att.ParentId.getSObjectType().getDescribe().getName() == 'Opportunity'){
                oppIds.add(att.ParentId);
            }
        }
                
        //query all Attachments for all opps
        List<Attachment> all = [SELECT Id, Name, ParentId FROM Attachment WHERE ParentId IN :oppIds];
        
        for (Attachment att: all ) {
            if(att.ParentId.getSObjectType().getDescribe().getName() == 'Opportunity'){
                system.debug('CCG 1----->');
                if(att.Name.contains('-CSign')){
                    cSignIds.add(att.ParentId);
                }else if(att.Name.contains('-Sign2')){
                    sign2Ids.add(att.ParentId);
                }else if(att.Name.contains('-AllSign')){
                    allSignIds.add(att.ParentId);
                }else if(att.Name.contains('CCG')){
                    ccgIds.add(att.ParentId);
                }else if(att.Name.contains('1 CCG')){                    
                    oppList.add(new Opportunity(id=att.ParentId,CCG__c = '1'));
                    oppMap.putall(oppList); 
                }else if(att.Name.contains('2 CCG')){                    
                    oppList.add(new Opportunity(id=att.ParentId,CCG__c = '2'));
                    oppMap.putall(oppList); 
                }else if(att.Name.contains('3 CCG')){                    
                    oppList.add(new Opportunity(id=att.ParentId,CCG__c = '3'));
                    oppMap.putall(oppList); 
                }else if(att.Name.contains('4 CCG')){                    
                    oppList.add(new Opportunity(id=att.ParentId,CCG__c = '4'));
                    oppMap.putall(oppList); 
                }else if(att.Name.contains('5 CCG')){                    
                    oppList.add(new Opportunity(id=att.ParentId,CCG__c = '5'));
                    oppMap.putall(oppList); 
                }else if(att.Name.contains('6 CCG')){                    
                    oppList.add(new Opportunity(id=att.ParentId,CCG__c = '6'));
                    oppMap.putall(oppList); 
                }                            
            }
        }
        
 
        if(oppIds.size() > 0){
            List<Opportunity> opps = [SELECT Id, CSign__c FROM Opportunity WHERE Id IN:oppIds];
            
            for(Opportunity opp : opps){ 
                              
                opp.CSign__c = cSignIds.contains(opp.Id) ? TRUE : FALSE;  
                opp.sign2__c = sign2Ids.contains(opp.Id) ? TRUE : FALSE;  
                opp.allSign__c = allSignIds.contains(opp.Id) ? TRUE : FALSE;       
                if(!ccgIds.contains(opp.Id)){
                opp.CCG__c = ' ';
                }                  
            }
            
            update opps;
        }
               
         if(oppMap.size()>0){
         update oppMap.values();
         }          
    }    
}

@isTest
public class TC_AttachmentTest {
    @isTest
    static void testGenerateRecords() {
        Opportunity opp = new Opportunity();
        opp.StageName = 'test';
        opp.Name = 'test';
        opp.CCG__c = '';
        opp.CloseDate = Date.today();
        
        insert opp;
        
        
        Attachment att = new Attachment();
        att.ParentId = opp.Id;
        att.Name = 'foo-CSign.pdf';
        att.Body = Blob.valueOf('xxxx');
        
        insert att;
        
        att.Name = 'foo.pdf';
        update att;
        
        att.Name = 'CCG.pdf';
        update att;
        
        att.Name = '-Sign2.pdf';
        update att;
        
        att.Name = '-AllSign.pdf';
        update att;
        
        att.Name = '1 CCG.pdf';
        update att;        
        opp.CCG__c = '1';
        update opp;
        
    }

}
public with sharing class Prefundscreen{

    public String oppId{get;set;}    
    public List<Prefund__c> prefundList{get;set;}
    public List<Vendor__c> vendorList{get;set;}  
    public List<Vendor__c> ppvendorList{get;set;}  
    public List<Opportunity> oppList{get;set;}  
    public List<Opportunity> oppList2{get;set;}  
    public List<Task> taskList{get;set;}  
    public List<Approved_Location__c> locList{get;set;}  
    public List<Invoice__c> invoiceList{get;set;} 
    
    public Prefundscreen(){
    prefundList = new List<Prefund__c>();
    vendorList = new List<Vendor__c>();
    ppvendorList = new List<Vendor__c>();
    taskList = new List<Task>();  
    oppList = new List<Opportunity>();
    oppList2 = new List<Opportunity>();
    locList = new List<Approved_Location__c>();
    invoiceList = new List<Invoice__c>();
    oppId = ApexPages.currentpage().getParameters().get('id');
        
         
    if(oppId != null)
    prefundList = [select id,Name,Prefund_Amount__c,Prefund_Date__c from Prefund__c where OppPrefund__c = : oppId ];
        
    if(oppId != null)
    oppList = [select id,Name,Legal_Company_Name_Look__c,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Anticipated_Equipment_Delivery_Date__c,Equipment_Delivery_Timeline__c,CloseDate,Prefund_Eligible__c,UCC_1_Recorded__c,Lien_Search_Required__c,Insurance_Received__c,Lien_Search_Complete__c,Debt_Source_FF__c,Credit_Stips_Cleared__c,Schedule_Number__c,Debt_Source_lookup__c,Document_Type__c,Debt_Source__c,Expiration_Date__c,Approval_Amount__c,Equipment_Totals__c,Equipment_Cost__c from Opportunity where id= : oppId];
        
    if(oppId != null)
    oppList2 = [select id,Name,Legal_Company_Name_Look__c,Prefund_Eligible_PF__c,Prefund_Elgible__c,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Anticipated_Equipment_Delivery_Date__c,Equipment_Delivery_Timeline__c,CloseDate,Prefund_Eligible__c,UCC_1_Recorded__c,Lien_Search_Required__c,Insurance_Received__c,Lien_Search_Complete__c,Debt_Source_FF__c,Credit_Stips_Cleared__c,Schedule_Number__c,Debt_Source_lookup__c,Document_Type__c,Debt_Source__c,Expiration_Date__c,Approval_Amount__c from Opportunity 
    where Prefund_Eligible_PF__c =true and id= : oppId];
        
    if(oppId != null){
    locList=[select id,Name,Location_Code__c,Address1__c,City__c,State__c,Approved__c  from Approved_Location__c where Approved__c = true and Application__c = : oppId ];
    vendorList = [select id,Vendor_Name__c,Prefund_Credit_Approved__c,Account_Name__c,Prefund_Letter__c,Vendor_Account_Id__c,Prefund_Eligible__c,Regents_Approval_Status__c,Vendor_W9_Received_Date__c,Vendor_Payment_Instructions_Validated__c,Validation_Date__c from Vendor__c where Prefund_Credit_Approved__c = TRUE and Opportunity__c=: oppId];
    ppvendorList = [select id,Vendor_Name__c,Prefund_Credit_Approved__c,Account_Name__c,Prefund_Letter__c,Vendor_Account_Id__c,Prefund_Eligible__c,Regents_Approval_Status__c,Vendor_W9_Received_Date__c,Vendor_Payment_Instructions_Validated__c,Validation_Date__c from Vendor__c where Prefund_Eligible__c = TRUE and Opportunity__c=: oppId];
    invoiceList = [select id,Vendor_Name__c,Name,Invoice_Number__c,Invoice_Total_Amount__c,InvoiceStatus__c from Invoice__c where OppInvoice__c = : oppId];
    }
        
    for (Opportunity opp : oppList ){ 
    if(opp.Equipment_Cost__c >= 500000.00 || opp.Equipment_Totals__c >= 500000.00 || opp.CloseDate > opp.Expiration_Date__c || opp.Anticipated_Equipment_Delivery_Date__c > opp.Expiration_Date__c){              
    //taskList.add(new Task(whatid=opp.id,Subject='Progress Payment Decision',status='Open',Task_Owner_Name1__c=opp.Contract_Manager_Name__c,ownerid=opp.Contract_Manager__c,President_Credit_Decision_Required__c=true,ActivityDate=system.today()));      
    taskList.add(new Task(whatid=opp.id,Subject='Progress Payment Decision',status='Open',President_Credit_Decision_Required__c=true,ActivityDate=system.today()));      
    }else{
    //taskList.add(new Task(whatid=opp.id,Subject='Progress Payment Decision',status='Open',Task_Owner_Name1__c=opp.Contract_Manager_Name__c,ownerid=opp.Contract_Manager__c,ActivityDate=system.today()));      
    taskList.add(new Task(whatid=opp.id,Subject='Progress Payment Decision',status='Open',ActivityDate=system.today()));      
    }
    }    
    }
    
    public void saveVendors(){
    update vendorList;            
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Vendor Information Saved Successfully'));
    }
        
    public void createTask(){ 
    
    
    update oppList; 
       
    List<Opportunity> oppList2 = [select id,name,Legal_Company_Name_Look__c,Owner_Email__c,Owner_Full_Name__c,Contract_Manager_Email__c,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Equipment_Delivery_Timeline__c,Anticipated_Equipment_Delivery_Date__c,CloseDate,Equipment_Cost__c,Equipment_Totals__c,Credit_Analyst_Email_ID__c,Manager_Email__c,Expiration_Date__c  from Opportunity where id in:oppList];
      
    List<Messaging.SingleEmailMessage> mails = new list<Messaging.SingleEmailMessage>();     
    
    
    
    
  
    for(Opportunity oppt :oppList2){
    for(Task openTask :taskList){
    openTask.Equipment_Totals__c=oppt.Equipment_Totals__c;
    openTask.Equipment_Cost__c=oppt.Equipment_Cost__c;
    openTask.Close_Date__c=oppt.CloseDate;
    openTask.Anticipated_Equipment_Delivery_Date__c=oppt.Anticipated_Equipment_Delivery_Date__c;
    openTask.Expiration_Date__c=oppt.Expiration_Date__c;
    openTask.Opp_Owner_Email__c=oppt.Owner_Email__c;
    openTask.Opp_Owner_Mgr_Email__c=oppt.Manager_Email__c;
    openTask.Credit_Analyst_Email__c=oppt.Credit_Analyst_Email_ID__c;
    
    if(openTask.Funder_List__c=='Funder1'){
    openTask.Contract_Manager_Email__c='Funder1@test.com.invalid';       
    openTask.ownerid=Label.Funder1_ID;
    }else if(openTask.Funder_List__c=='Funder2'){
    openTask.Contract_Manager_Email__c='Funder2@test.com.invalid';    
    openTask.ownerid=Label.Funder2_ID;
    }else if(openTask.Funder_List__c=='Funder3'){    
    openTask.Contract_Manager_Email__c='Funder3@test.com.invalid';    
    openTask.ownerid=Label.Funder3_ID;
    }else{
    openTask.Contract_Manager_Email__c=oppt.Contract_Manager_Email__c;
    
    }
    insert taskList;
        
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();   
    String[] toAddresses = new String[] {openTask.Contract_Manager_Email__c};    
    String[] CcAddresses = new String[] {oppt.Credit_Analyst_Email_ID__c,oppt.Manager_Email__c,oppt.Owner_Email__c};   
    
    String openTaskUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/'+openTask.Id;
    String oppUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/'+oppt.Id;
    
    mail.setToAddresses(toAddresses);   
    
    if(oppt.Equipment_Cost__c >= 500000.00 || oppt.Equipment_Totals__c >= 500000.00){
    mail.setCcAddresses(CcAddresses);    
    mail.setSubject('Progress Payment Decision Request - President/Credit Approval required - $500K +');    
    openTask.President_Credit_Decision_Required__c=TRUE;
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'President/Credit approval required - $500K+, Task assigned to contract manager succesfully'));
    
    string body1 = 'Hi ' +openTask.Funder_List__c+ ', ';
    body1 += '<br><br> The following Progress Payment Decision open task has been assigned to you.';   
    body1 += '</br></br> <b><h1><font style="color:red"> President/Credit Approval required - $500K+ </font></h1></b>' ;
            
    body1 += 'Legal Company Name : ' +oppt.Legal_Company_Name_Look__c+ ' ';
    body1 += '</br></br> Equipment Totals: $' +oppt.Equipment_Totals__c + ' '; 
    
    body1 += '</br></br> Please review for approval and indicate your decision here:';
    body1 += '</br></br> Open task URL : ' +openTaskUrl+ ' ';     
    
    body1 += '</br></br></br><b> Additional Detail: </b>';       
    body1 += '</br></br> Opportunity URL : ' +oppUrl+ ' ';       
    body1 += '</br></br> Equipment Description : ' +oppt.Equipment_Description__c+ ' '; 
    body1 += '</br></br> Approval Expiration Date : ' +oppt.Expiration_Date__c.format()+ ' ';        
    body1 += '</br></br> Equipment Delivery Date: ' +oppt.Anticipated_Equipment_Delivery_Date__c.format() + ' '; 
    
    body1 += '</br></br></br></br> Equipment Delivery Timeline Notes: ' +oppt.Equipment_Delivery_Timeline__c+ ' '; 
    body1 += '</br></br> Funding Close Date : ' +oppt.CloseDate.format()+ ' '; 
    body1 += '</br></br></br></br> Vendors to Prefund : ' +openTask.Vendor_Name__c+ ' ';
    body1 += '</br></br> Corresponding Invoice Numbers : ' +openTask.Invoice_Number__c+ ' '; 
    body1 += '</br></br> Total $$ Amount to Prefund : $' +openTask.Amount__c+ ' '; 
    body1 += '</br></br> Rep Comments : ' +openTask.description+ ' ';
    body1 += '</br></br> Will additional prefunds be needed? : ' +openTask.Will_additional_prefunds_be_needed__c+ ' ';            
    body1 += '<br><br> Thanks,';
    body1 +=  '<br> '+oppt.Owner_Full_Name__c+ '.' ; 
    mail.setHtmlBody(body1);
    
    }else if(oppt.Anticipated_Equipment_Delivery_Date__c > oppt.Expiration_Date__c){
    mail.setCcAddresses(CcAddresses);    
    mail.setSubject('Progress Payment Decision Request - President/Credit Approval required - Delivery Date vs Approval Exp');    
    openTask.President_Credit_Decision_Required__c=TRUE;
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'President/Credit approval required - Delivery Date vs Approval Exp , Task assigned to contract manager succesfully'));
    
    string body2 = 'Hi ' +openTask.Funder_List__c+ ', ';
    body2 += '<br><br> The following Progress Payment Decision open task has been assigned to you.';   
    body2 += '<br><br><b><h1><font style="color:red"> Delivery Date vs. Approval Exp </font></h1></b>';    
    body2 += '</br></br> Legal Company Name : ' +oppt.Legal_Company_Name_Look__c+ ' ';    
    body2 += '</br></br> The equipment is expected to deliver on ' +oppt.Anticipated_Equipment_Delivery_Date__c.format()+ ' however the approval is set to expire ' +oppt.Expiration_Date__c.format()+ ' ';      
    body2 += '</br></br> Please review for approval and indicate your decision here:';
    body2 += '</br></br> Open task URL : ' +openTaskUrl+ ' ';  
    
    body2 += '</br></br></br><b> Additional Detail: </b>';           
    body2 += '</br></br> Opportunity URL : ' +oppUrl+ ' ';   
    
    body2 += '</br></br> Equipment Description : ' +oppt.Equipment_Description__c+ ' '; 
    body2 += '</br></br> Equipment Totals: $' +oppt.Equipment_Totals__c + ' '; 
    body2 += '</br></br> Approval Expiration Date : ' +oppt.Expiration_Date__c.format()+ ' '; 
    body2 += '</br></br> Equipment Delivery Date: ' +oppt.Anticipated_Equipment_Delivery_Date__c.format() + ' '; 
    
    body2 += '</br></br></br></br> Equipment Delivery Timeline Notes: ' +oppt.Equipment_Delivery_Timeline__c+ ' ';
    body2 += '</br></br> Funding Close Date : ' +oppt.CloseDate.format()+ ' ';      
            
    body2 += '</br></br></br></br> Vendors to Prefund : ' +openTask.Vendor_Name__c+ ' ';
    body2 += '</br></br> Corresponding Invoice Numbers : ' +openTask.Invoice_Number__c+ ' '; 
    body2 += '</br></br> Total $$ Amount to Prefund : $' +openTask.Amount__c+ ' ';      
    body2 += '</br></br> Rep Comments : ' +openTask.description+ ' ';      
    body2 += '</br></br> Will additional prefunds be needed? : ' +openTask.Will_additional_prefunds_be_needed__c+ ' ';            
    body2 += '<br><br> Thanks,';
    body2 +=  '<br> '+oppt.Owner_Full_Name__c+ '.' ;
    mail.setHtmlBody(body2);   
    
    }else if(oppt.CloseDate > oppt.Expiration_Date__c){
    mail.setCcAddresses(CcAddresses);    
    mail.setSubject('Progress Payment Decision Request - President/Credit Approval required - Close Date vs Approval Exp');    
    openTask.President_Credit_Decision_Required__c=TRUE;
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'President/Credit approval required - Close Date vs Approval Exp , Task assigned to contract manager succesfully'));
       
    string body3 = 'Hi ' +openTask.Funder_List__c+ ', ';
    body3 += '<br><br> The following Progress Payment Decision open task has been assigned to you.';   
    body3 += '<br><br><b><h1><font style="color:red"> Close Date vs. Approval Exp </font></h1></b>';  
    body3 += '</br></br> Legal Company Name : ' +oppt.Legal_Company_Name_Look__c+ ' ';
    body3 += '</br></br> This schedule is expected to fund on ' +oppt.CloseDate.format()+ ' however the approval is set to expire ' +oppt.Expiration_Date__c.format()+ ' ';  
    body3 += '</br></br> Please review for approval and indicate your decision here:';
    body3 += '</br></br> Open task URL : ' +openTaskUrl+ ' ';  
    
    body3 += '</br></br></br><b> Additional Detail: </b>';    
    body3 += '</br></br> Opportunity URL : ' +oppUrl+ ' ';   
    
    body3 += '</br></br> Equipment Description : ' +oppt.Equipment_Description__c+ ' '; 
    body3 += '</br></br> Equipment Totals: $' +oppt.Equipment_Totals__c + ' '; 
    body3 += '</br></br> Approval Expiration Date : ' +oppt.Expiration_Date__c.format()+ ' '; 
    body3 += '</br></br> Equipment Delivery Date: ' +oppt.Anticipated_Equipment_Delivery_Date__c.format() + ' '; 
    
    body3 += '</br></br></br></br> Equipment Delivery Timeline Notes: ' +oppt.Equipment_Delivery_Timeline__c+ ' ';
    body3 += '</br></br> Funding Close Date : ' +oppt.CloseDate.format()+ ' ';    
    
    body3 += '</br></br></br></br> Vendors to Prefund : ' +openTask.Vendor_Name__c+ ' ';
    body3 += '</br></br> Corresponding Invoice Numbers : ' +openTask.Invoice_Number__c+ ' '; 
    body3 += '</br></br> Total $$ Amount to Prefund : $' +openTask.Amount__c+ ' ';     
    body3 += '</br></br> Rep Comments : ' +openTask.description+ ' ';        
    body3 += '</br></br> Will additional prefunds be needed? : ' +openTask.Will_additional_prefunds_be_needed__c+ ' ';            
    body3 += '<Br><Br> Thanks,';
    body3 +=  '<Br> '+oppt.Owner_Full_Name__c+ '.' ;
    mail.setHtmlBody(body3);
    
    }else{
    mail.setCcAddresses(new string[] {oppt.Manager_Email__c,oppt.Owner_Email__c});    
    mail.setSubject('Progress Payment Decision Request');    
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Task created and assigned to contract manager successfully'));
       
    string body4 = 'Hi ' +openTask.Funder_List__c+ ', ';
    body4 += '<br><br> The following Progress Payment Decision open task has been assigned to you.';              
    body4 += '</br></br> Open task URL : ' +openTaskUrl+ ' ';             
    body4 += '</br></br> Opportunity URL : ' +oppUrl+ ' ';   
    body4 += '</br></br> Legal Company Name : ' +oppt.Legal_Company_Name_Look__c+ ' ';
    body4 += '</br></br> Equipment Description : ' +oppt.Equipment_Description__c+ ' '; 
    body4 += '</br></br> Equipment Totals: $' +oppt.Equipment_Totals__c + ' '; 
    body4 += '</br></br> Equipment Delivery Date: ' +oppt.Anticipated_Equipment_Delivery_Date__c.format() + ' '; 
    body4 += '</br></br> Funding Close Date : ' +oppt.CloseDate.format()+ ' '; 
    body4 += '</br></br> Approval Expiration Date : ' +oppt.Expiration_Date__c.format()+ ' '; 
    body4 += '</br></br> Equipment Delivery Timeline Notes: ' +oppt.Equipment_Delivery_Timeline__c+ ' '; 
    body4 += '</br></br> Rep Comments : ' +openTask.description+ ' ';        
    body4 += '</br></br> Vendors to Prefund : ' +openTask.Vendor_Name__c+ ' ';
    body4 += '</br></br> Corresponding Invoice Numbers : ' +openTask.Invoice_Number__c+ ' '; 
    body4 += '</br></br> Total $$ Amount to Prefund : $' +openTask.Amount__c+ ' ';            
    body4 += '</br></br> Will additional prefunds be needed? : ' +openTask.Will_additional_prefunds_be_needed__c+ ' ';            
    body4 += '<Br><Br> Thanks,';
    body4 +=  '<Br> '+oppt.Owner_Full_Name__c+ '.' ;
    mail.setHtmlBody(body4);
    }
    mail.setBccAddresses(BccAddresses);
    //mail.setHtmlBody(body); 
    mails.add(mail);   
    
    
    }
        
    Messaging.sendEmail(mails);
    }    
    
    }
    
}
 
@isTest
public class PrefundscreenTest{

    public static testMethod void method1(){
        
        List<Opportunity> oppList =new List<Opportunity>();
        List<Task> taskList =new List<Task>();
         
        Account acc = new Account(name='test');
        insert acc;
        
        Contact con = new Contact(FirstName='test',LastName='test',AccountId=acc.id);
        insert con;
        
        Opportunity opp=new Opportunity(Name='opp test',Credit_Analyst__c='005G0000007b9Ss',AccountId=acc.id,StageName='Application Received',CloseDate=System.today(),Contract_Manager__c='005G00000089MnG',UCC_1_Recorded__c=system.today(),Lien_Search_Required__c=true,
        Insurance_Received__c=true,Lien_Search_Complete__c=system.today(),Debt_Source__c='Sumitomo Mitsui',Expiration_Date__c=system.today(),Approval_Amount__c = 120000.01,
        Equipment_Description__c='equip test',Anticipated_Equipment_Delivery_Date__c=system.today());
        insert opp;
                
        Prefund__c pf= new Prefund__c(OppPrefund__c = opp.id,Prefund_Amount__c=5000,Prefund_Date__c=system.today());
        insert pf;
        
        Approved_Location__c loc = new Approved_Location__c(Approved__c=true,Application__c=opp.id);
        insert loc;

        Test.setCurrentPage(Page.PrefundscreenVFP);    
        ApexPages.currentPage().getParameters().put('id',opp.id);
        
        Prefundscreen prefund= new Prefundscreen();
        prefund.createTask();          
        
        prefund.saveVendors(); 
        
    }
        public static testMethod void method2(){
        
        List<Opportunity> oppList1 =new List<Opportunity>();
        List<Task> taskList1 =new List<Task>();
        
        Account acc1 = new Account(name='test');
        insert acc1;
        
        Contact con1 = new Contact(FirstName='test',LastName='test',AccountId=acc1.id);
        insert con1;
        
        Opportunity opp1=new Opportunity(Name='opp test',Credit_Analyst__c='005G0000007b9Ss',AccountId=acc1.id,StageName='Application Received',CloseDate=System.today(),Contract_Manager__c='005G00000089MnG',UCC_1_Recorded__c=system.today(),Lien_Search_Required__c=true,
        Insurance_Received__c=true,Lien_Search_Complete__c=system.today(),Debt_Source__c='Sumitomo Mitsui',Expiration_Date__c=system.today(),Approval_Amount__c = 120000.01,
        Equipment_Description__c='equip test',Anticipated_Equipment_Delivery_Date__c=system.today(),Equipment_Cost__c=750000);
        insert opp1;
                
        Prefund__c pf1= new Prefund__c(OppPrefund__c = opp1.id,Prefund_Amount__c=5000,Prefund_Date__c=system.today());
        insert pf1;
        
        Approved_Location__c loc1 = new Approved_Location__c(Approved__c=true,Application__c=opp1.id);
        insert loc1;
              
        Test.setCurrentPage(Page.PrefundscreenVFP);    
        ApexPages.currentPage().getParameters().put('id',opp1.id);
        
        Prefundscreen prefund= new Prefundscreen();
        prefund.createTask();   
        prefund.saveVendors(); 
    }
    
        public static testMethod void method3(){
        
        List<Opportunity> oppList2 =new List<Opportunity>();
        List<Task> taskList2 =new List<Task>();
        
        Account acc2 = new Account(name='test');
        insert acc2;
        
        Contact con2 = new Contact(FirstName='test',LastName='test',AccountId=acc2.id);
        insert con2;
        
        Opportunity opp2=new Opportunity(Name='opp test',Credit_Analyst__c='005G0000007b9Ss',AccountId=acc2.id,StageName='Application Received',CloseDate=System.today(),Contract_Manager__c='005G00000089MnB',UCC_1_Recorded__c=system.today(),Lien_Search_Required__c=true,
        Insurance_Received__c=true,Lien_Search_Complete__c=system.today(),Debt_Source__c='Sumitomo Mitsui',Expiration_Date__c=system.today(),Approval_Amount__c = 120000.01,
        Equipment_Description__c='equip test',Anticipated_Equipment_Delivery_Date__c=system.today()+3,Equipment_Cost__c=7500);
        insert opp2;
                
        Prefund__c pf2= new Prefund__c(OppPrefund__c = opp2.id,Prefund_Amount__c=5000,Prefund_Date__c=system.today());
        insert pf2;
        
        Approved_Location__c loc2 = new Approved_Location__c(Approved__c=true,Application__c=opp2.id);
        insert loc2;
       
        Test.setCurrentPage(Page.PrefundscreenVFP);    
        ApexPages.currentPage().getParameters().put('id',opp2.id);
        
        Prefundscreen prefund= new Prefundscreen();
        prefund.createTask();   
        prefund.saveVendors(); 
    }
        public static testMethod void method4(){
        
        List<Opportunity> oppList3 =new List<Opportunity>();
        List<Task> taskList3 =new List<Task>();
        
        Account acc3 = new Account(name='test');
        insert acc3;
        
        Contact con3 = new Contact(FirstName='test',LastName='test',AccountId=acc3.id);
        insert con3;
        
        Opportunity opp3=new Opportunity(Name='opp test',Credit_Analyst__c='005G0000007b9Ss',AccountId=acc3.id,StageName='Application Received',CloseDate=System.today()+3,Contract_Manager__c='0050f000009JnAZ',UCC_1_Recorded__c=system.today(),Lien_Search_Required__c=true,
        Insurance_Received__c=true,Lien_Search_Complete__c=system.today(),Debt_Source__c='Sumitomo Mitsui',Expiration_Date__c=system.today(),Approval_Amount__c = 120000.01,
        Equipment_Description__c='equip test',Anticipated_Equipment_Delivery_Date__c=system.today(),Equipment_Cost__c=7500);
        insert opp3;
               
        Prefund__c pf3= new Prefund__c(OppPrefund__c = opp3.id,Prefund_Amount__c=5000,Prefund_Date__c=system.today());
        insert pf3;
        
        Approved_Location__c loc3 = new Approved_Location__c(Approved__c=true,Application__c=opp3.id);
        insert loc3;

        Test.setCurrentPage(Page.PrefundscreenVFP);    
        ApexPages.currentPage().getParameters().put('id',opp3.id);
        
        Prefundscreen prefund= new Prefundscreen();
        prefund.createTask();   
        prefund.saveVendors(); 
    }
    
        
    
    }

 
is it possible to create table like below on the task description text area?

Task Visual force page
public with sharing class Prefundscreen{

    public String oppId{get;set;}
    //public String accId{get;set;}
    //public String vaccName{get;set;}
    public List<Prefund__c> prefundList{get;set;}
    public List<Vendor__c> vendorList{get;set;}  
    public List<Opportunity> oppList{get;set;}  
    public List<Task> taskList{get;set;}  
    public List<Approved_Location__c> locList{get;set;}  
    public List<Invoice__c> invoiceList{get;set;} 
    
    public Prefundscreen(){
        prefundList = new List<Prefund__c>();
        vendorList = new List<Vendor__c>();
        taskList = new List<Task>();  
        oppList = new List<Opportunity>();
        locList = new List<Approved_Location__c>();
        invoiceList = new List<Invoice__c>();
        oppId = ApexPages.currentpage().getParameters().get('id');
        
         
        if(oppId != null)
        prefundList = [select id,Name,Prefund_Amount__c,Prefund_Date__c from Prefund__c where OppPrefund__c = : oppId ];
        
        if(oppId != null)
        oppList = [select id,Name,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Anticipated_Equipment_Delivery_Date__c,Equipment_Delivery_Timeline__c,CloseDate,Prefund_Eligible__c,UCC_1_Recorded__c,Lien_Search_Required__c,Insurance_Received__c,Lien_Search_Complete__c,Debt_Source_FF__c,Credit_Stips_Cleared__c,Schedule_Number__c,Debt_Source_lookup__c,Document_Type__c,Debt_Source__c,Expiration_Date__c,Approval_Amount__c from Opportunity where id= : oppId];
        
        if(oppId!=null)      
         locList=[select id,Name,Location_Code__c,Address1__c,City__c,State__c,Approved__c  from Approved_Location__c where Approved__c = true and Application__c = : oppId ];
                
        if(oppId!=null)      
         vendorList = [select id,Vendor_Name__c,Account_Name__c,Vendor_Prefund_Letter__c,Vendor_Account_Id__c,Prefund_Eligible__c,Regents_Approval_Status__c,Vendor_W9_Received_Date__c,Vendor_Payment_Instructions_Validated__c,Validation_Date__c from Vendor__c where Prefund_Eligible__c=true];
        
        if(oppId!=null)
          invoiceList = [select id,Vendor_Name__c,Name,Invoice_Number__c,Invoice_Total_Amount__c,InvoiceStatus__c from Invoice__c where OppInvoice__c = : oppId];
        
        for (Opportunity opp : oppList ){              
          taskList.add(new Task(whatid=opp.id,Subject='Prefund-Decision',status='Open',Task_Owner_Name1__c=opp.Contract_Manager_Name__c,ownerid=opp.Contract_Manager__c,ActivityDate=system.today()));         
        }
       
    }
    
    public void saveVendors(){
            update vendorList;            
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Vendor Information Saved Successfully'));
        }
        
    public void createTask(){ 
                
            upsert taskList;  
            update oppList;        
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Task created and assigned to Contract Manager successfully'));
            List<Opportunity> oppList2 = [select id,name,Owner_Email__c,Owner_Full_Name__c,Contract_Manager_Email__c,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Equipment_Delivery_Timeline__c,Anticipated_Equipment_Delivery_Date__c,CloseDate from Opportunity where id in:oppList];
       List<Messaging.SingleEmailMessage> mails = new list<Messaging.SingleEmailMessage>();     
       
       for(Opportunity oppt :oppList2)
       {
       for(Task openTask :taskList)
       {
                                 
           Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
           String[] toAddresses = new String[] {oppt.Contract_Manager_Email__c};
           String[] CcAddresses = new String[] {oppt.Owner_Email__c};
           String[] BccAddresses = new String[] {'priyas@regentscapital.com'};
           String openTaskUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/'+openTask.Id;
           String oppUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/'+oppt.Id;
           system.debug('---> toaddress'+toAddresses);
           string body = 'Hi ' +oppt.Contract_Manager_Name__c+ ', ';
           body += '<br><br> The following Prefund Decision open task has been assigned to you.';           
           body += '</br></br> Open task URL : ' +openTaskUrl+ ' ';             
           body += '</br></br> Opportunity URL : ' +oppUrl+ ' ';           
           body += '</br></br> Equipment Description : ' +oppt.Equipment_Description__c+ ' '; 
           body += '</br></br> Equipment Delivery Date: ' +oppt.Anticipated_Equipment_Delivery_Date__c + ' '; 
           body += '</br></br> Funding Close Date : ' +oppt.CloseDate+ ' '; 
           body += '</br></br> Equipment Delivery Timeline Notes: ' +oppt.Equipment_Delivery_Timeline__c+ ' '; 
           body += '</br></br> Rep Comments : ' +openTask.description+ ' ';        
           body += '<Br><Br> Thanks,';
           body +=  '<Br> '+oppt.Owner_Full_Name__c+ '.' ; 
           mail.setSubject('Prefund Decision Open Task');
           mail.setToAddresses(toAddresses);
           mail.setCcAddresses(CcAddresses);
           mail.setBccAddresses(BccAddresses);
           mail.setHtmlBody(body); 
           mails.add(mail);
           
        }
        }
            Messaging.sendEmail(mails);
        }
}

Test Class Code Coverage is only 58%. Highlighted code above is  not covered in test class

 
@isTest
public class PrefundscreenTest{

    public static testMethod void method1(){
        
        List<Opportunity> oppList =new List<Opportunity>();
        List<Task> taskList =new List<Task>();
        
        Account acc = new Account(name='test');
        insert acc;
        
        Contact con = new Contact(FirstName='test',LastName='test',AccountId=acc.id);
        insert con;
        
        Opportunity opp=new Opportunity(Name='opp test',AccountId=acc.id,StageName='Application Received',CloseDate=System.today(),Contract_Manager__c='005G00000089MnG',UCC_1_Recorded__c=system.today(),Lien_Search_Required__c=true,
        Insurance_Received__c=true,Lien_Search_Complete__c=system.today(),Debt_Source__c='Sumitomo Mitsui',Expiration_Date__c=system.today(),Approval_Amount__c = 120000.01);
        insert opp;
        oppList.add(opp);    
        //insert oppList;
        
        Prefund__c pf= new Prefund__c(OppPrefund__c = opp.id,Prefund_Amount__c=5000,Prefund_Date__c=system.today());
        insert pf;
        
        ApexPages.currentpage().getparameters().put('id',acc.id);
        Prefundscreen prefund= new Prefundscreen();
        prefund.saveVendors();  
        
        for(Opportunity opp1:oppList){
        task tsk = new task(whatid=opp1.id,Subject='Prefund-Decision',status='Open',ownerid=opp1.Contract_Manager__c,Task_Owner_Name1__c='Lauren Barteske',description='prefund decision',ActivityDate=system.today());      
        system.debug('--->tsk'+tsk);
        taskList.add(tsk);
        }
        
        insert taskList;
        
        List<Opportunity> oppList2 = [select id,name,Owner_Email__c,Owner_Full_Name__c,Contract_Manager_Email__c,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Equipment_Delivery_Timeline__c,Anticipated_Equipment_Delivery_Date__c,CloseDate from Opportunity where id in:oppList];
         
        prefund.createTask();
    }
    }

 
Hello,

i have this report snapshot - for same user in 2 different rows 

i want the values in one row to show in report - is this possible?

User-added image
I want to have global search option on campaign member custom field (funding code). I dont search search layout option as well.User-added image

Any workaround for this?
Hello Everyone,
My requirement is to integrate salesforce with third party lead generator (Lending Tree). They provide leads in JSON format. 
I am looking for approaches to push JSON format leads from lending tree into salesforce.

 
Hello Everyone!
How do i write test class for the trigger below. 
Trigger AccountEventTrigger on Event (Before Insert) {
    
/******************************************************************************
It controlls the creation of Events from accounts which are yet to be approved.
*******************************************************************************/
    list<Id> accountIds = new list<Id>();
    Map<Id,Account> accMap = new Map<Id,Account>();
    for(Event Event: Trigger.new){
        if(Event.whatId != null && String.valueof(Event.whatId).startsWith('001'))
            accountIds.add(Event.whatId);
    }
    if(!accountIds.isEmpty()){
        for(Account acc : [select id,Submitted_for_Approval__c from Account where id in : accountIds]){
            accMap.put(acc.id,acc);
        }   
        for(Event Event: Trigger.New){
            if(Event.whatId != null && accMap.containsKey(Event.whatId) && accMap.get(Event.whatId).Submitted_for_Approval__c!= false)
                Event.addError('New Event Cannot be Created');
        }
    } 
}
Hello Folks,

Our company has recently migrated to salesforce crm. we are in need to integrate our Marketo (using for 6+ years) with salesforce.

should we consult marketo consultants or just follow steps http://docs.marketo.com/pages/releaseview.action?pageId=2360372
 
public with sharing class Prefundscreen{

    public String oppId{get;set;}    
    public List<Prefund__c> prefundList{get;set;}
    public List<Vendor__c> vendorList{get;set;}  
    public List<Vendor__c> ppvendorList{get;set;}  
    public List<Opportunity> oppList{get;set;}  
    public List<Opportunity> oppList2{get;set;}  
    public List<Task> taskList{get;set;}  
    public List<Approved_Location__c> locList{get;set;}  
    public List<Invoice__c> invoiceList{get;set;} 
    
    public Prefundscreen(){
    prefundList = new List<Prefund__c>();
    vendorList = new List<Vendor__c>();
    ppvendorList = new List<Vendor__c>();
    taskList = new List<Task>();  
    oppList = new List<Opportunity>();
    oppList2 = new List<Opportunity>();
    locList = new List<Approved_Location__c>();
    invoiceList = new List<Invoice__c>();
    oppId = ApexPages.currentpage().getParameters().get('id');
        
         
    if(oppId != null)
    prefundList = [select id,Name,Prefund_Amount__c,Prefund_Date__c from Prefund__c where OppPrefund__c = : oppId ];
        
    if(oppId != null)
    oppList = [select id,Name,Legal_Company_Name_Look__c,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Anticipated_Equipment_Delivery_Date__c,Equipment_Delivery_Timeline__c,CloseDate,Prefund_Eligible__c,UCC_1_Recorded__c,Lien_Search_Required__c,Insurance_Received__c,Lien_Search_Complete__c,Debt_Source_FF__c,Credit_Stips_Cleared__c,Schedule_Number__c,Debt_Source_lookup__c,Document_Type__c,Debt_Source__c,Expiration_Date__c,Approval_Amount__c,Equipment_Totals__c,Equipment_Cost__c from Opportunity where id= : oppId];
        
    if(oppId != null)
    oppList2 = [select id,Name,Legal_Company_Name_Look__c,Prefund_Eligible_PF__c,Prefund_Elgible__c,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Anticipated_Equipment_Delivery_Date__c,Equipment_Delivery_Timeline__c,CloseDate,Prefund_Eligible__c,UCC_1_Recorded__c,Lien_Search_Required__c,Insurance_Received__c,Lien_Search_Complete__c,Debt_Source_FF__c,Credit_Stips_Cleared__c,Schedule_Number__c,Debt_Source_lookup__c,Document_Type__c,Debt_Source__c,Expiration_Date__c,Approval_Amount__c from Opportunity 
    where Prefund_Eligible_PF__c =true and id= : oppId];
        
    if(oppId != null){
    locList=[select id,Name,Location_Code__c,Address1__c,City__c,State__c,Approved__c  from Approved_Location__c where Approved__c = true and Application__c = : oppId ];
    vendorList = [select id,Vendor_Name__c,Prefund_Credit_Approved__c,Account_Name__c,Prefund_Letter__c,Vendor_Account_Id__c,Prefund_Eligible__c,Regents_Approval_Status__c,Vendor_W9_Received_Date__c,Vendor_Payment_Instructions_Validated__c,Validation_Date__c from Vendor__c where Prefund_Credit_Approved__c = TRUE and Opportunity__c=: oppId];
    ppvendorList = [select id,Vendor_Name__c,Prefund_Credit_Approved__c,Account_Name__c,Prefund_Letter__c,Vendor_Account_Id__c,Prefund_Eligible__c,Regents_Approval_Status__c,Vendor_W9_Received_Date__c,Vendor_Payment_Instructions_Validated__c,Validation_Date__c from Vendor__c where Prefund_Eligible__c = TRUE and Opportunity__c=: oppId];
    invoiceList = [select id,Vendor_Name__c,Name,Invoice_Number__c,Invoice_Total_Amount__c,InvoiceStatus__c from Invoice__c where OppInvoice__c = : oppId];
    }
        
    for (Opportunity opp : oppList ){ 
    if(opp.Equipment_Cost__c >= 500000.00 || opp.Equipment_Totals__c >= 500000.00 || opp.CloseDate > opp.Expiration_Date__c || opp.Anticipated_Equipment_Delivery_Date__c > opp.Expiration_Date__c){              
    //taskList.add(new Task(whatid=opp.id,Subject='Progress Payment Decision',status='Open',Task_Owner_Name1__c=opp.Contract_Manager_Name__c,ownerid=opp.Contract_Manager__c,President_Credit_Decision_Required__c=true,ActivityDate=system.today()));      
    taskList.add(new Task(whatid=opp.id,Subject='Progress Payment Decision',status='Open',President_Credit_Decision_Required__c=true,ActivityDate=system.today()));      
    }else{
    //taskList.add(new Task(whatid=opp.id,Subject='Progress Payment Decision',status='Open',Task_Owner_Name1__c=opp.Contract_Manager_Name__c,ownerid=opp.Contract_Manager__c,ActivityDate=system.today()));      
    taskList.add(new Task(whatid=opp.id,Subject='Progress Payment Decision',status='Open',ActivityDate=system.today()));      
    }
    }    
    }
    
    public void saveVendors(){
    update vendorList;            
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Vendor Information Saved Successfully'));
    }
        
    public void createTask(){ 
    
    
    update oppList; 
       
    List<Opportunity> oppList2 = [select id,name,Legal_Company_Name_Look__c,Owner_Email__c,Owner_Full_Name__c,Contract_Manager_Email__c,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Equipment_Delivery_Timeline__c,Anticipated_Equipment_Delivery_Date__c,CloseDate,Equipment_Cost__c,Equipment_Totals__c,Credit_Analyst_Email_ID__c,Manager_Email__c,Expiration_Date__c  from Opportunity where id in:oppList];
      
    List<Messaging.SingleEmailMessage> mails = new list<Messaging.SingleEmailMessage>();     
    
    
    
    
  
    for(Opportunity oppt :oppList2){
    for(Task openTask :taskList){
    openTask.Equipment_Totals__c=oppt.Equipment_Totals__c;
    openTask.Equipment_Cost__c=oppt.Equipment_Cost__c;
    openTask.Close_Date__c=oppt.CloseDate;
    openTask.Anticipated_Equipment_Delivery_Date__c=oppt.Anticipated_Equipment_Delivery_Date__c;
    openTask.Expiration_Date__c=oppt.Expiration_Date__c;
    openTask.Opp_Owner_Email__c=oppt.Owner_Email__c;
    openTask.Opp_Owner_Mgr_Email__c=oppt.Manager_Email__c;
    openTask.Credit_Analyst_Email__c=oppt.Credit_Analyst_Email_ID__c;
    
    if(openTask.Funder_List__c=='Funder1'){
    openTask.Contract_Manager_Email__c='Funder1@test.com.invalid';       
    openTask.ownerid=Label.Funder1_ID;
    }else if(openTask.Funder_List__c=='Funder2'){
    openTask.Contract_Manager_Email__c='Funder2@test.com.invalid';    
    openTask.ownerid=Label.Funder2_ID;
    }else if(openTask.Funder_List__c=='Funder3'){    
    openTask.Contract_Manager_Email__c='Funder3@test.com.invalid';    
    openTask.ownerid=Label.Funder3_ID;
    }else{
    openTask.Contract_Manager_Email__c=oppt.Contract_Manager_Email__c;
    
    }
    insert taskList;
        
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();   
    String[] toAddresses = new String[] {openTask.Contract_Manager_Email__c};    
    String[] CcAddresses = new String[] {oppt.Credit_Analyst_Email_ID__c,oppt.Manager_Email__c,oppt.Owner_Email__c};   
    
    String openTaskUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/'+openTask.Id;
    String oppUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/'+oppt.Id;
    
    mail.setToAddresses(toAddresses);   
    
    if(oppt.Equipment_Cost__c >= 500000.00 || oppt.Equipment_Totals__c >= 500000.00){
    mail.setCcAddresses(CcAddresses);    
    mail.setSubject('Progress Payment Decision Request - President/Credit Approval required - $500K +');    
    openTask.President_Credit_Decision_Required__c=TRUE;
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'President/Credit approval required - $500K+, Task assigned to contract manager succesfully'));
    
    string body1 = 'Hi ' +openTask.Funder_List__c+ ', ';
    body1 += '<br><br> The following Progress Payment Decision open task has been assigned to you.';   
    body1 += '</br></br> <b><h1><font style="color:red"> President/Credit Approval required - $500K+ </font></h1></b>' ;
            
    body1 += 'Legal Company Name : ' +oppt.Legal_Company_Name_Look__c+ ' ';
    body1 += '</br></br> Equipment Totals: $' +oppt.Equipment_Totals__c + ' '; 
    
    body1 += '</br></br> Please review for approval and indicate your decision here:';
    body1 += '</br></br> Open task URL : ' +openTaskUrl+ ' ';     
    
    body1 += '</br></br></br><b> Additional Detail: </b>';       
    body1 += '</br></br> Opportunity URL : ' +oppUrl+ ' ';       
    body1 += '</br></br> Equipment Description : ' +oppt.Equipment_Description__c+ ' '; 
    body1 += '</br></br> Approval Expiration Date : ' +oppt.Expiration_Date__c.format()+ ' ';        
    body1 += '</br></br> Equipment Delivery Date: ' +oppt.Anticipated_Equipment_Delivery_Date__c.format() + ' '; 
    
    body1 += '</br></br></br></br> Equipment Delivery Timeline Notes: ' +oppt.Equipment_Delivery_Timeline__c+ ' '; 
    body1 += '</br></br> Funding Close Date : ' +oppt.CloseDate.format()+ ' '; 
    body1 += '</br></br></br></br> Vendors to Prefund : ' +openTask.Vendor_Name__c+ ' ';
    body1 += '</br></br> Corresponding Invoice Numbers : ' +openTask.Invoice_Number__c+ ' '; 
    body1 += '</br></br> Total $$ Amount to Prefund : $' +openTask.Amount__c+ ' '; 
    body1 += '</br></br> Rep Comments : ' +openTask.description+ ' ';
    body1 += '</br></br> Will additional prefunds be needed? : ' +openTask.Will_additional_prefunds_be_needed__c+ ' ';            
    body1 += '<br><br> Thanks,';
    body1 +=  '<br> '+oppt.Owner_Full_Name__c+ '.' ; 
    mail.setHtmlBody(body1);
    
    }else if(oppt.Anticipated_Equipment_Delivery_Date__c > oppt.Expiration_Date__c){
    mail.setCcAddresses(CcAddresses);    
    mail.setSubject('Progress Payment Decision Request - President/Credit Approval required - Delivery Date vs Approval Exp');    
    openTask.President_Credit_Decision_Required__c=TRUE;
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'President/Credit approval required - Delivery Date vs Approval Exp , Task assigned to contract manager succesfully'));
    
    string body2 = 'Hi ' +openTask.Funder_List__c+ ', ';
    body2 += '<br><br> The following Progress Payment Decision open task has been assigned to you.';   
    body2 += '<br><br><b><h1><font style="color:red"> Delivery Date vs. Approval Exp </font></h1></b>';    
    body2 += '</br></br> Legal Company Name : ' +oppt.Legal_Company_Name_Look__c+ ' ';    
    body2 += '</br></br> The equipment is expected to deliver on ' +oppt.Anticipated_Equipment_Delivery_Date__c.format()+ ' however the approval is set to expire ' +oppt.Expiration_Date__c.format()+ ' ';      
    body2 += '</br></br> Please review for approval and indicate your decision here:';
    body2 += '</br></br> Open task URL : ' +openTaskUrl+ ' ';  
    
    body2 += '</br></br></br><b> Additional Detail: </b>';           
    body2 += '</br></br> Opportunity URL : ' +oppUrl+ ' ';   
    
    body2 += '</br></br> Equipment Description : ' +oppt.Equipment_Description__c+ ' '; 
    body2 += '</br></br> Equipment Totals: $' +oppt.Equipment_Totals__c + ' '; 
    body2 += '</br></br> Approval Expiration Date : ' +oppt.Expiration_Date__c.format()+ ' '; 
    body2 += '</br></br> Equipment Delivery Date: ' +oppt.Anticipated_Equipment_Delivery_Date__c.format() + ' '; 
    
    body2 += '</br></br></br></br> Equipment Delivery Timeline Notes: ' +oppt.Equipment_Delivery_Timeline__c+ ' ';
    body2 += '</br></br> Funding Close Date : ' +oppt.CloseDate.format()+ ' ';      
            
    body2 += '</br></br></br></br> Vendors to Prefund : ' +openTask.Vendor_Name__c+ ' ';
    body2 += '</br></br> Corresponding Invoice Numbers : ' +openTask.Invoice_Number__c+ ' '; 
    body2 += '</br></br> Total $$ Amount to Prefund : $' +openTask.Amount__c+ ' ';      
    body2 += '</br></br> Rep Comments : ' +openTask.description+ ' ';      
    body2 += '</br></br> Will additional prefunds be needed? : ' +openTask.Will_additional_prefunds_be_needed__c+ ' ';            
    body2 += '<br><br> Thanks,';
    body2 +=  '<br> '+oppt.Owner_Full_Name__c+ '.' ;
    mail.setHtmlBody(body2);   
    
    }else if(oppt.CloseDate > oppt.Expiration_Date__c){
    mail.setCcAddresses(CcAddresses);    
    mail.setSubject('Progress Payment Decision Request - President/Credit Approval required - Close Date vs Approval Exp');    
    openTask.President_Credit_Decision_Required__c=TRUE;
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'President/Credit approval required - Close Date vs Approval Exp , Task assigned to contract manager succesfully'));
       
    string body3 = 'Hi ' +openTask.Funder_List__c+ ', ';
    body3 += '<br><br> The following Progress Payment Decision open task has been assigned to you.';   
    body3 += '<br><br><b><h1><font style="color:red"> Close Date vs. Approval Exp </font></h1></b>';  
    body3 += '</br></br> Legal Company Name : ' +oppt.Legal_Company_Name_Look__c+ ' ';
    body3 += '</br></br> This schedule is expected to fund on ' +oppt.CloseDate.format()+ ' however the approval is set to expire ' +oppt.Expiration_Date__c.format()+ ' ';  
    body3 += '</br></br> Please review for approval and indicate your decision here:';
    body3 += '</br></br> Open task URL : ' +openTaskUrl+ ' ';  
    
    body3 += '</br></br></br><b> Additional Detail: </b>';    
    body3 += '</br></br> Opportunity URL : ' +oppUrl+ ' ';   
    
    body3 += '</br></br> Equipment Description : ' +oppt.Equipment_Description__c+ ' '; 
    body3 += '</br></br> Equipment Totals: $' +oppt.Equipment_Totals__c + ' '; 
    body3 += '</br></br> Approval Expiration Date : ' +oppt.Expiration_Date__c.format()+ ' '; 
    body3 += '</br></br> Equipment Delivery Date: ' +oppt.Anticipated_Equipment_Delivery_Date__c.format() + ' '; 
    
    body3 += '</br></br></br></br> Equipment Delivery Timeline Notes: ' +oppt.Equipment_Delivery_Timeline__c+ ' ';
    body3 += '</br></br> Funding Close Date : ' +oppt.CloseDate.format()+ ' ';    
    
    body3 += '</br></br></br></br> Vendors to Prefund : ' +openTask.Vendor_Name__c+ ' ';
    body3 += '</br></br> Corresponding Invoice Numbers : ' +openTask.Invoice_Number__c+ ' '; 
    body3 += '</br></br> Total $$ Amount to Prefund : $' +openTask.Amount__c+ ' ';     
    body3 += '</br></br> Rep Comments : ' +openTask.description+ ' ';        
    body3 += '</br></br> Will additional prefunds be needed? : ' +openTask.Will_additional_prefunds_be_needed__c+ ' ';            
    body3 += '<Br><Br> Thanks,';
    body3 +=  '<Br> '+oppt.Owner_Full_Name__c+ '.' ;
    mail.setHtmlBody(body3);
    
    }else{
    mail.setCcAddresses(new string[] {oppt.Manager_Email__c,oppt.Owner_Email__c});    
    mail.setSubject('Progress Payment Decision Request');    
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Task created and assigned to contract manager successfully'));
       
    string body4 = 'Hi ' +openTask.Funder_List__c+ ', ';
    body4 += '<br><br> The following Progress Payment Decision open task has been assigned to you.';              
    body4 += '</br></br> Open task URL : ' +openTaskUrl+ ' ';             
    body4 += '</br></br> Opportunity URL : ' +oppUrl+ ' ';   
    body4 += '</br></br> Legal Company Name : ' +oppt.Legal_Company_Name_Look__c+ ' ';
    body4 += '</br></br> Equipment Description : ' +oppt.Equipment_Description__c+ ' '; 
    body4 += '</br></br> Equipment Totals: $' +oppt.Equipment_Totals__c + ' '; 
    body4 += '</br></br> Equipment Delivery Date: ' +oppt.Anticipated_Equipment_Delivery_Date__c.format() + ' '; 
    body4 += '</br></br> Funding Close Date : ' +oppt.CloseDate.format()+ ' '; 
    body4 += '</br></br> Approval Expiration Date : ' +oppt.Expiration_Date__c.format()+ ' '; 
    body4 += '</br></br> Equipment Delivery Timeline Notes: ' +oppt.Equipment_Delivery_Timeline__c+ ' '; 
    body4 += '</br></br> Rep Comments : ' +openTask.description+ ' ';        
    body4 += '</br></br> Vendors to Prefund : ' +openTask.Vendor_Name__c+ ' ';
    body4 += '</br></br> Corresponding Invoice Numbers : ' +openTask.Invoice_Number__c+ ' '; 
    body4 += '</br></br> Total $$ Amount to Prefund : $' +openTask.Amount__c+ ' ';            
    body4 += '</br></br> Will additional prefunds be needed? : ' +openTask.Will_additional_prefunds_be_needed__c+ ' ';            
    body4 += '<Br><Br> Thanks,';
    body4 +=  '<Br> '+oppt.Owner_Full_Name__c+ '.' ;
    mail.setHtmlBody(body4);
    }
    mail.setBccAddresses(BccAddresses);
    //mail.setHtmlBody(body); 
    mails.add(mail);   
    
    
    }
        
    Messaging.sendEmail(mails);
    }    
    
    }
    
}
 
@isTest
public class PrefundscreenTest{

    public static testMethod void method1(){
        
        List<Opportunity> oppList =new List<Opportunity>();
        List<Task> taskList =new List<Task>();
         
        Account acc = new Account(name='test');
        insert acc;
        
        Contact con = new Contact(FirstName='test',LastName='test',AccountId=acc.id);
        insert con;
        
        Opportunity opp=new Opportunity(Name='opp test',Credit_Analyst__c='005G0000007b9Ss',AccountId=acc.id,StageName='Application Received',CloseDate=System.today(),Contract_Manager__c='005G00000089MnG',UCC_1_Recorded__c=system.today(),Lien_Search_Required__c=true,
        Insurance_Received__c=true,Lien_Search_Complete__c=system.today(),Debt_Source__c='Sumitomo Mitsui',Expiration_Date__c=system.today(),Approval_Amount__c = 120000.01,
        Equipment_Description__c='equip test',Anticipated_Equipment_Delivery_Date__c=system.today());
        insert opp;
                
        Prefund__c pf= new Prefund__c(OppPrefund__c = opp.id,Prefund_Amount__c=5000,Prefund_Date__c=system.today());
        insert pf;
        
        Approved_Location__c loc = new Approved_Location__c(Approved__c=true,Application__c=opp.id);
        insert loc;

        Test.setCurrentPage(Page.PrefundscreenVFP);    
        ApexPages.currentPage().getParameters().put('id',opp.id);
        
        Prefundscreen prefund= new Prefundscreen();
        prefund.createTask();          
        
        prefund.saveVendors(); 
        
    }
        public static testMethod void method2(){
        
        List<Opportunity> oppList1 =new List<Opportunity>();
        List<Task> taskList1 =new List<Task>();
        
        Account acc1 = new Account(name='test');
        insert acc1;
        
        Contact con1 = new Contact(FirstName='test',LastName='test',AccountId=acc1.id);
        insert con1;
        
        Opportunity opp1=new Opportunity(Name='opp test',Credit_Analyst__c='005G0000007b9Ss',AccountId=acc1.id,StageName='Application Received',CloseDate=System.today(),Contract_Manager__c='005G00000089MnG',UCC_1_Recorded__c=system.today(),Lien_Search_Required__c=true,
        Insurance_Received__c=true,Lien_Search_Complete__c=system.today(),Debt_Source__c='Sumitomo Mitsui',Expiration_Date__c=system.today(),Approval_Amount__c = 120000.01,
        Equipment_Description__c='equip test',Anticipated_Equipment_Delivery_Date__c=system.today(),Equipment_Cost__c=750000);
        insert opp1;
                
        Prefund__c pf1= new Prefund__c(OppPrefund__c = opp1.id,Prefund_Amount__c=5000,Prefund_Date__c=system.today());
        insert pf1;
        
        Approved_Location__c loc1 = new Approved_Location__c(Approved__c=true,Application__c=opp1.id);
        insert loc1;
              
        Test.setCurrentPage(Page.PrefundscreenVFP);    
        ApexPages.currentPage().getParameters().put('id',opp1.id);
        
        Prefundscreen prefund= new Prefundscreen();
        prefund.createTask();   
        prefund.saveVendors(); 
    }
    
        public static testMethod void method3(){
        
        List<Opportunity> oppList2 =new List<Opportunity>();
        List<Task> taskList2 =new List<Task>();
        
        Account acc2 = new Account(name='test');
        insert acc2;
        
        Contact con2 = new Contact(FirstName='test',LastName='test',AccountId=acc2.id);
        insert con2;
        
        Opportunity opp2=new Opportunity(Name='opp test',Credit_Analyst__c='005G0000007b9Ss',AccountId=acc2.id,StageName='Application Received',CloseDate=System.today(),Contract_Manager__c='005G00000089MnB',UCC_1_Recorded__c=system.today(),Lien_Search_Required__c=true,
        Insurance_Received__c=true,Lien_Search_Complete__c=system.today(),Debt_Source__c='Sumitomo Mitsui',Expiration_Date__c=system.today(),Approval_Amount__c = 120000.01,
        Equipment_Description__c='equip test',Anticipated_Equipment_Delivery_Date__c=system.today()+3,Equipment_Cost__c=7500);
        insert opp2;
                
        Prefund__c pf2= new Prefund__c(OppPrefund__c = opp2.id,Prefund_Amount__c=5000,Prefund_Date__c=system.today());
        insert pf2;
        
        Approved_Location__c loc2 = new Approved_Location__c(Approved__c=true,Application__c=opp2.id);
        insert loc2;
       
        Test.setCurrentPage(Page.PrefundscreenVFP);    
        ApexPages.currentPage().getParameters().put('id',opp2.id);
        
        Prefundscreen prefund= new Prefundscreen();
        prefund.createTask();   
        prefund.saveVendors(); 
    }
        public static testMethod void method4(){
        
        List<Opportunity> oppList3 =new List<Opportunity>();
        List<Task> taskList3 =new List<Task>();
        
        Account acc3 = new Account(name='test');
        insert acc3;
        
        Contact con3 = new Contact(FirstName='test',LastName='test',AccountId=acc3.id);
        insert con3;
        
        Opportunity opp3=new Opportunity(Name='opp test',Credit_Analyst__c='005G0000007b9Ss',AccountId=acc3.id,StageName='Application Received',CloseDate=System.today()+3,Contract_Manager__c='0050f000009JnAZ',UCC_1_Recorded__c=system.today(),Lien_Search_Required__c=true,
        Insurance_Received__c=true,Lien_Search_Complete__c=system.today(),Debt_Source__c='Sumitomo Mitsui',Expiration_Date__c=system.today(),Approval_Amount__c = 120000.01,
        Equipment_Description__c='equip test',Anticipated_Equipment_Delivery_Date__c=system.today(),Equipment_Cost__c=7500);
        insert opp3;
               
        Prefund__c pf3= new Prefund__c(OppPrefund__c = opp3.id,Prefund_Amount__c=5000,Prefund_Date__c=system.today());
        insert pf3;
        
        Approved_Location__c loc3 = new Approved_Location__c(Approved__c=true,Application__c=opp3.id);
        insert loc3;

        Test.setCurrentPage(Page.PrefundscreenVFP);    
        ApexPages.currentPage().getParameters().put('id',opp3.id);
        
        Prefundscreen prefund= new Prefundscreen();
        prefund.createTask();   
        prefund.saveVendors(); 
    }
    
        
    
    }

 
is it possible to create table like below on the task description text area?

Task Visual force page
public with sharing class Prefundscreen{

    public String oppId{get;set;}
    //public String accId{get;set;}
    //public String vaccName{get;set;}
    public List<Prefund__c> prefundList{get;set;}
    public List<Vendor__c> vendorList{get;set;}  
    public List<Opportunity> oppList{get;set;}  
    public List<Task> taskList{get;set;}  
    public List<Approved_Location__c> locList{get;set;}  
    public List<Invoice__c> invoiceList{get;set;} 
    
    public Prefundscreen(){
        prefundList = new List<Prefund__c>();
        vendorList = new List<Vendor__c>();
        taskList = new List<Task>();  
        oppList = new List<Opportunity>();
        locList = new List<Approved_Location__c>();
        invoiceList = new List<Invoice__c>();
        oppId = ApexPages.currentpage().getParameters().get('id');
        
         
        if(oppId != null)
        prefundList = [select id,Name,Prefund_Amount__c,Prefund_Date__c from Prefund__c where OppPrefund__c = : oppId ];
        
        if(oppId != null)
        oppList = [select id,Name,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Anticipated_Equipment_Delivery_Date__c,Equipment_Delivery_Timeline__c,CloseDate,Prefund_Eligible__c,UCC_1_Recorded__c,Lien_Search_Required__c,Insurance_Received__c,Lien_Search_Complete__c,Debt_Source_FF__c,Credit_Stips_Cleared__c,Schedule_Number__c,Debt_Source_lookup__c,Document_Type__c,Debt_Source__c,Expiration_Date__c,Approval_Amount__c from Opportunity where id= : oppId];
        
        if(oppId!=null)      
         locList=[select id,Name,Location_Code__c,Address1__c,City__c,State__c,Approved__c  from Approved_Location__c where Approved__c = true and Application__c = : oppId ];
                
        if(oppId!=null)      
         vendorList = [select id,Vendor_Name__c,Account_Name__c,Vendor_Prefund_Letter__c,Vendor_Account_Id__c,Prefund_Eligible__c,Regents_Approval_Status__c,Vendor_W9_Received_Date__c,Vendor_Payment_Instructions_Validated__c,Validation_Date__c from Vendor__c where Prefund_Eligible__c=true];
        
        if(oppId!=null)
          invoiceList = [select id,Vendor_Name__c,Name,Invoice_Number__c,Invoice_Total_Amount__c,InvoiceStatus__c from Invoice__c where OppInvoice__c = : oppId];
        
        for (Opportunity opp : oppList ){              
          taskList.add(new Task(whatid=opp.id,Subject='Prefund-Decision',status='Open',Task_Owner_Name1__c=opp.Contract_Manager_Name__c,ownerid=opp.Contract_Manager__c,ActivityDate=system.today()));         
        }
       
    }
    
    public void saveVendors(){
            update vendorList;            
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Vendor Information Saved Successfully'));
        }
        
    public void createTask(){ 
                
            upsert taskList;  
            update oppList;        
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Task created and assigned to Contract Manager successfully'));
            List<Opportunity> oppList2 = [select id,name,Owner_Email__c,Owner_Full_Name__c,Contract_Manager_Email__c,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Equipment_Delivery_Timeline__c,Anticipated_Equipment_Delivery_Date__c,CloseDate from Opportunity where id in:oppList];
       List<Messaging.SingleEmailMessage> mails = new list<Messaging.SingleEmailMessage>();     
       
       for(Opportunity oppt :oppList2)
       {
       for(Task openTask :taskList)
       {
                                 
           Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
           String[] toAddresses = new String[] {oppt.Contract_Manager_Email__c};
           String[] CcAddresses = new String[] {oppt.Owner_Email__c};
           String[] BccAddresses = new String[] {'priyas@regentscapital.com'};
           String openTaskUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/'+openTask.Id;
           String oppUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/'+oppt.Id;
           system.debug('---> toaddress'+toAddresses);
           string body = 'Hi ' +oppt.Contract_Manager_Name__c+ ', ';
           body += '<br><br> The following Prefund Decision open task has been assigned to you.';           
           body += '</br></br> Open task URL : ' +openTaskUrl+ ' ';             
           body += '</br></br> Opportunity URL : ' +oppUrl+ ' ';           
           body += '</br></br> Equipment Description : ' +oppt.Equipment_Description__c+ ' '; 
           body += '</br></br> Equipment Delivery Date: ' +oppt.Anticipated_Equipment_Delivery_Date__c + ' '; 
           body += '</br></br> Funding Close Date : ' +oppt.CloseDate+ ' '; 
           body += '</br></br> Equipment Delivery Timeline Notes: ' +oppt.Equipment_Delivery_Timeline__c+ ' '; 
           body += '</br></br> Rep Comments : ' +openTask.description+ ' ';        
           body += '<Br><Br> Thanks,';
           body +=  '<Br> '+oppt.Owner_Full_Name__c+ '.' ; 
           mail.setSubject('Prefund Decision Open Task');
           mail.setToAddresses(toAddresses);
           mail.setCcAddresses(CcAddresses);
           mail.setBccAddresses(BccAddresses);
           mail.setHtmlBody(body); 
           mails.add(mail);
           
        }
        }
            Messaging.sendEmail(mails);
        }
}

Test Class Code Coverage is only 58%. Highlighted code above is  not covered in test class

 
@isTest
public class PrefundscreenTest{

    public static testMethod void method1(){
        
        List<Opportunity> oppList =new List<Opportunity>();
        List<Task> taskList =new List<Task>();
        
        Account acc = new Account(name='test');
        insert acc;
        
        Contact con = new Contact(FirstName='test',LastName='test',AccountId=acc.id);
        insert con;
        
        Opportunity opp=new Opportunity(Name='opp test',AccountId=acc.id,StageName='Application Received',CloseDate=System.today(),Contract_Manager__c='005G00000089MnG',UCC_1_Recorded__c=system.today(),Lien_Search_Required__c=true,
        Insurance_Received__c=true,Lien_Search_Complete__c=system.today(),Debt_Source__c='Sumitomo Mitsui',Expiration_Date__c=system.today(),Approval_Amount__c = 120000.01);
        insert opp;
        oppList.add(opp);    
        //insert oppList;
        
        Prefund__c pf= new Prefund__c(OppPrefund__c = opp.id,Prefund_Amount__c=5000,Prefund_Date__c=system.today());
        insert pf;
        
        ApexPages.currentpage().getparameters().put('id',acc.id);
        Prefundscreen prefund= new Prefundscreen();
        prefund.saveVendors();  
        
        for(Opportunity opp1:oppList){
        task tsk = new task(whatid=opp1.id,Subject='Prefund-Decision',status='Open',ownerid=opp1.Contract_Manager__c,Task_Owner_Name1__c='Lauren Barteske',description='prefund decision',ActivityDate=system.today());      
        system.debug('--->tsk'+tsk);
        taskList.add(tsk);
        }
        
        insert taskList;
        
        List<Opportunity> oppList2 = [select id,name,Owner_Email__c,Owner_Full_Name__c,Contract_Manager_Email__c,Contract_Manager__c,Contract_Manager_Name__c,Equipment_Description__c,Equipment_Delivery_Timeline__c,Anticipated_Equipment_Delivery_Date__c,CloseDate from Opportunity where id in:oppList];
         
        prefund.createTask();
    }
    }

 
I have a client that wants to create a record that is created from an email sent out from Salesforce. I am relatively new and looking for guidance. So an example would be. They create an email to a client in Salesforce and once it is sent creates a new record in a custom object called Service. 
Hello,

When a create button is clicked on Quote, i want to populate some fields with some predifined values, how is it possible to do so ?
I have some lookup, and text fields to populate

Is it possible to do it in trigger ?

thanks for suggestion
  • April 12, 2017
  • Like
  • 0
Hello Everyone,
I'm trying to deploy the components of a SF org (Dev org) to an other one (Test org), But I'm stuck with the following errors :


Could your help me please?Trouble
Thank you 
Hello Everyone,
My requirement is to integrate salesforce with third party lead generator (Lending Tree). They provide leads in JSON format. 
I am looking for approaches to push JSON format leads from lending tree into salesforce.

 
Hello Everyone!
How do i write test class for the trigger below. 
Trigger AccountEventTrigger on Event (Before Insert) {
    
/******************************************************************************
It controlls the creation of Events from accounts which are yet to be approved.
*******************************************************************************/
    list<Id> accountIds = new list<Id>();
    Map<Id,Account> accMap = new Map<Id,Account>();
    for(Event Event: Trigger.new){
        if(Event.whatId != null && String.valueof(Event.whatId).startsWith('001'))
            accountIds.add(Event.whatId);
    }
    if(!accountIds.isEmpty()){
        for(Account acc : [select id,Submitted_for_Approval__c from Account where id in : accountIds]){
            accMap.put(acc.id,acc);
        }   
        for(Event Event: Trigger.New){
            if(Event.whatId != null && accMap.containsKey(Event.whatId) && accMap.get(Event.whatId).Submitted_for_Approval__c!= false)
                Event.addError('New Event Cannot be Created');
        }
    } 
}