• sasmita
  • NEWBIE
  • 35 Points
  • Member since 2016
  • Ms
  • Positive Edge Solution Pvt. Ltd

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
Hi,
   
  Below is the controller 
public with sharing class CForecastSubmitCnt{
    
    public Map<id, Period> periodMap;
    Date todaydate = system.today();
    public List<SelectOption> forecastQtr {get; set;}
    
    public String selectedForecastQ{get;set;}
   
    public List<Collaborative_Forecast_History__c> revenueHFCs {get; set;}
    public List<Collaborative_Forecast_History__c> enhanceHFCs {get; set;}
  //public List<Collaborative_Forecast_History__c> ServiceHFCs {get; set;} 
     
    public list<ForeCastWrap> revenueFC {get; set;} 
    public list<ForeCastWrap> enhanceFC {get; set;}
  //public list<ForeCastWrap> ServiceFC {get; set;}
    List<ForecastingOwnerAdjustment> upsertLst; 
    List<Collaborative_Forecast_History__c> upsertHstLst; //History
    Map<String, Id> forecastingTypeMap;
    
    static string FORECAST_TYPE_REVENUE = 'Opportunity Revenue';
    static string FORECAST_TYPE_ENHANCE = 'Enhanced Tech Amount';
  //static string FORECAST_TYPE_SPLIT   = 'Opportunity Split Revenue';
    
    static string FORECAST_CATEGORY_COMMIT   = 'CommitForecast';
    static string FORECAST_CATEGORY_BESTCASE = 'BestCaseForecast';
       
    public class ForeCastWrap {
        
        public ForeCastWrap(String month, Date StDate){
            this.month = month;
            commitAmt = 0;
            bestCaseAmt = 0;
            this.StDate = StDate;
        }
        public String month {get; set;}
        public String type;
        
        public ID commitID {get; set;}
        public Decimal commitAmt {get; set;}
        public String cComment {get; set;}          
        
        public ID bestCaseID {get; set;}
        public Decimal bestCaseAmt {get; set;}
        public String bcComment {get; set;}
        public Date StDate;
    }    
    
    public CForecastSubmitCnt(){
      
       if( getManagerEmail(UserInfo.getUserId()) ==  null ) {
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'No manager has been set up to receive this Forecast submission.  Please contact the SFDC Team (sfdc@fortinet.com) for assistance'));
          }
       else {     
        // Displays 4 quarter 
        periodMap = new Map<id, Period>([ select id, StartDate, Number, type, EndDate, FullyQualifiedLabel  from Period 
                                         where type in ('Quarter', 'Month') and ( startdate = THIS_QUARTER or startdate=NEXT_N_QUARTERS:3) order by startdate]);
        forecastQtr = new List<SelectOption>();
        for(Period p : periodMap.values()) {
            if(p.type == 'Quarter') {
                forecastQtr.add(new SelectOption(p.id,'Q'+p.Number+' '+p.StartDate.year() ));
                if(selectedForecastQ == null)
                    selectedForecastQ = p.id;
            }
        }                     
          
        displayForecastTable(); 
        displayForecastHistoryTable(); 
        }
    }
    
    public Map<Integer, ForeCastWrap> populateMap () {
        Period qtrPeriod = periodMap.get(selectedForecastQ);
        Map<Integer, ForeCastWrap> fcMap = new Map<Integer, ForeCastWrap>();
        for(Period p : periodMap.values()) {
            if(p.type == 'Month' && p.StartDate >= qtrPeriod.StartDate && p.StartDate <= qtrPeriod.EndDate) {
                fcMap.put(p.StartDate.month(), new ForeCastWrap(p.FullyQualifiedLabel.mid(0, 3), p.StartDate));
            }
        }
        system.debug('__map_' + fcMap);
        return fcMap;
    }
    
    public void displayForecastTable(){
        Period sltdQPeriod = periodMap.get(selectedForecastQ);
        Map<Integer, ForeCastWrap> revenueFCMap = populateMap(); 
        Map<Integer, ForeCastWrap> enhanceFCMap = populateMap();
        Map<Integer, ForeCastWrap> ServiceFCMap = populateMap();
        
        list<ForecastingOwnerAdjustment> forecastLst = [select id,forecastingitemcategory,periodid, startdate,owneradjustedamount,owneradjustmentnote,
                                                        forecastingtype.masterlabel from forecastingowneradjustment 
                                                        where ForecastOwnerId = :UserInfo.getUserId()
                                                        and startdate >= :sltdQPeriod.StartDate and startdate <= :sltdQPeriod.EndDate ];
                                                        
        for(ForecastingOwnerAdjustment foa : forecastLst) {
            
            if( foa.forecastingtype.masterlabel == FORECAST_TYPE_REVENUE) {
                ForeCastWrap fcWrap = revenueFCMap.get(foa.startdate.month());
                if(foa.forecastingitemcategory == FORECAST_CATEGORY_COMMIT){               
                    fcWrap.commitID = foa.id;
                    fcWrap.commitAmt = foa.owneradjustedamount; 
                    fcWrap.cComment = foa.owneradjustmentnote;                              
                }  
                else if( foa.forecastingitemcategory == FORECAST_CATEGORY_BESTCASE) {
                    fcWrap.bestCaseID = foa.id;
                    fcWrap.bestCaseAmt = foa.owneradjustedamount; 
                    fcWrap.bcComment = foa.owneradjustmentnote;                              
                }
            } else if( foa.forecastingtype.masterlabel == FORECAST_TYPE_ENHANCE && foa.forecastingitemcategory == FORECAST_CATEGORY_COMMIT) {
                ForeCastWrap fcWrap = enhanceFCMap.get(foa.startdate.month());
                fcWrap.commitID = foa.id;
                fcWrap.commitAmt = foa.owneradjustedamount; 
                fcWrap.cComment = foa.owneradjustmentnote;                              
                
            } /* else if( foa.forecastingtype.masterlabel == FORECAST_TYPE_SPLIT && foa.forecastingitemcategory == FORECAST_CATEGORY_COMMIT) {
                ForeCastWrap fcWrap = ServiceFCMap.get(foa.startdate.month());
                fcWrap.commitID = foa.id;
                fcWrap.commitAmt = foa.owneradjustedamount; 
                fcWrap.cComment = foa.owneradjustmentnote;                              
            } */
        }
        
        revenueFC = revenueFCMap.values();
        enhanceFC = enhanceFCMap.values();
      //ServiceFC = ServiceFCMap.values();
        system.debug(revenueFC);
        system.debug(enhanceFC);
        //system.debug(ServiceFC);
        
        displayForecastHistoryTable();
   
    }    
    
    
    //Display Forecast History Data
    public void displayForecastHistoryTable(){
    
     Period sltdQPeriod = periodMap.get(selectedForecastQ);
       
      revenueHFCs = [select Quater__c, Start_Date__c ,Comment__c, Commit_Amount__c, Best_Case_Amount__c, Forecast_Type__c,Submission_Date__c,createddate                      
                                                             from Collaborative_Forecast_History__c
                                                             where
                                                             OwnerId = :UserInfo.getUserId() and
                                                             Forecast_Type__c = :FORECAST_TYPE_REVENUE and
                                                             Start_Date__c >= :sltdQPeriod.StartDate and Start_Date__c <= :sltdQPeriod.EndDate order by createddate desc ];
      
      enhanceHFCs = [select Quater__c, Start_Date__c ,Comment__c, Commit_Amount__c, Best_Case_Amount__c, Forecast_Type__c,Submission_Date__c,createddate                     
                                                             from Collaborative_Forecast_History__c
                                                             where
                                                             OwnerId = :UserInfo.getUserId() and
                                                             Forecast_Type__c = :FORECAST_TYPE_ENHANCE and
                                                             Start_Date__c >= :sltdQPeriod.StartDate and Start_Date__c <= :sltdQPeriod.EndDate order by createddate desc];

      
    /*  ServiceHFCs = [select Quater__c, Start_Date__c ,Comment__c, Commit_Amount__c, Best_Case_Amount__c, Forecast_Type__c,Submission_Date__c,createddate                     
                                                             from Collaborative_Forecast_History__c
                                                             where
                                                             OwnerId = :UserInfo.getUserId() and
                                                             Forecast_Type__c = :FORECAST_TYPE_SPLIT and
                                                             Start_Date__c >= :sltdQPeriod.StartDate and Start_Date__c <= :sltdQPeriod.EndDate order by createddate desc]; */
 
    
    }        
      
    
    public void populateDataList(list<ForeCastWrap> lst, String fcType) {
        Period qtrPeriod = periodMap.get(selectedForecastQ);
        String Qlabel = 'Q'+qtrPeriod.Number + ' ' + qtrPeriod.StartDate.year();
        for(ForeCastWrap fc : lst) {
            ForecastingOwnerAdjustment foa = new ForecastingOwnerAdjustment( id = fc.commitID,
                                                                            startdate=fc.stDate,
                                                                            owneradjustedamount = fc.commitAmt,
                                                                            //owneradjustmentnote  = fc.cComment,
                                                                            forecastingitemcategory = FORECAST_CATEGORY_COMMIT,
                                                                            forecastingtypeid = getTypeID(fcType), 
                                                                            forecastownerid = UserInfo.getUserId()                     
                                                                           ); 
            upsertLst.add(foa);
            system.debug('kkk__' + foa);                                                              
            Collaborative_Forecast_History__c  foaH =  new Collaborative_Forecast_History__c (
                Quater__c = Qlabel,
                Start_Date__c=fc.stDate,
                Submission_Date__c = System.today(),
                Commit_Amount__c = fc.commitAmt, 
                Comment__c =  fc.cComment,
                Forecast_Type__c = fcType
            );

            
            if(fcType == FORECAST_TYPE_REVENUE) {
                
                foa = new ForecastingOwnerAdjustment(id = fc.bestCaseID,
                                                     startdate=fc.stDate,
                                                     owneradjustedamount = fc.bestCaseAmt,
                                                     //owneradjustmentnote  = fc.bcComment,
                                                     forecastingitemcategory = FORECAST_CATEGORY_BESTCASE,
                                                     forecastingtypeid = getTypeID(FORECAST_TYPE_REVENUE), 
                                                     forecastownerid = UserInfo.getUserId()                                                                      
                                                    ); 
                upsertLst.add(foa); 
                system.debug('kkk__' + foa);
                foaH.Best_Case_Amount__c = fc.bestCaseAmt; 
                //foaH.Comment__c =  fc.cComment;
                
            }
            upsertHstLst.add(foaH);
        }        
        
    }
    
    public void submit() {
      
        upsertHstLst = new List<Collaborative_Forecast_History__c>();
        upsertLst = new List<ForecastingOwnerAdjustment>();     
        populateDataList(revenueFC, FORECAST_TYPE_REVENUE);
        populateDataList(enhanceFC, FORECAST_TYPE_ENHANCE);
     // populateDataList(ServiceFC, FORECAST_TYPE_SPLIT);
 
            upsert upsertLst ID;
            Insert upsertHstLst;
        
            sendEmail();
            displayForecastTable();
        
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Forecast submitted to '  + getManagerEmail(UserInfo.getUserId()) + '  on  ' + system.now() ));
              
    }
    
    public ID getTypeID(String label){
        if(forecastingTypeMap == null) {
            forecastingTypeMap = new Map<String, Id>();
            for (ForecastingType ft : [select id, masterlabel from Forecastingtype where isactive=true])  {
                forecastingTypeMap.put(ft.masterlabel, ft.id);
            }
        }
        return forecastingTypeMap.get(label);
    } 
    
    public String getManagerEmail(Id userId) {
        User curUser;
        String managerEmail = null;
        
        // Get User Parent Id
        curUser = [select Id,name,UserRole.ForecastUserId,Email,UserRoleId,Userrole.name, UserRole.ParentRoleid from User where id = :UserInfo.getUserId()];
        if( curUser.Userrole.name == 'Administrator')
            managerEmail = curUser.email;
        // Get Forecast Manager role id
        if(curUser.UserRole.ParentRoleid <> null) {
            Userrole managerRole = [select Id,ForecastUserId, ParentRoleid from userrole where id = :curUser.UserRole.ParentRoleid];
            user mUser = [select id,name,email from user where id = :managerRole.ForecastUserId];
            system.debug('Manager Name : ' + mUser.name);  
            managerEmail =  mUser.email;
            system.debug('Forecast Manager Email :' + managerEmail);
        }   
        return managerEmail;
    }
   
    public void sendEmail() {
        
      Period qtrPeriod = periodMap.get(selectedForecastQ);
      String Qlabel = 'Q'+qtrPeriod.Number + ' ' + qtrPeriod.StartDate.year();
      List<String> toAddresses = new List<String>();
      String htmlBody;      
      String MgrMail;
      
      // Check Manager Email to add
      MgrMail = getManagerEmail(UserInfo.getUserId());
       
       if(MgrMail <> null){     
          toAddresses.add(MgrMail); 
        }
      
      //Copy user mail     
      toAddresses.add(UserInfo.getUserEmail());
      //toAddresses.add('sudhirn@fortinet.com');
      
      if(toAddresses.size() >0 && toAddresses != null){
      
         Messaging.reserveSingleEmailCapacity(2);
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
         mail.setToAddresses(toAddresses);
         mail.setSenderDisplayName('Collaborative Forecasting Submission Alert');
         mail.setSubject('Collaborative Forecasting Submission Alert :'+userinfo.getname()+' - '+Qlabel);
        
         htmlBody= userinfo.getname() +  ' has submitted the below forecast for  : ' + Qlabel + ' on ' + system.now() + '<br/><br/>';
         
         htmlBody += '<head><style> table, th, td { border: 1px solid black; } </style> </head>';
         
         //************************************Total Revenue Forecast******************************************
         htmlBody+='<table class="list" border="1" cellpadding="0" cellspacing="0" width="100%">';  
         htmlBody+='<thead class=""><tr class=" headerRow">';
         htmlBody+='<thead> <th class="dataCell" colspan="5" style="color:black">'+'Total Revenue Forecast'+'</th></thead></tr>';
         htmlBody+='<tr> <th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Forecast Period</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Commit (Core) Forecast</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Best Case (Stretch) Forecast</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Comment</th>';
         htmlBody+='</tr></thead>';
         htmlBody+='<tbody>';          
         
         for(ForeCastWrap rc: revenueFC){        
         htmlBody+='<tr class="dataRow even first">'; 
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="20%">'+rc.month+'</td>';  
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="20%">'+rc.commitAmt+'</td>';        
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="20%">'+rc.bestCaseAmt+'</td>';
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="50%">'+rc.cComment+'</td>';
         htmlBody+='</tr>';            
         }
         htmlBody+='</tbody></table><br/><br/>';
          
         //************************************Enhanced Tech Forecast******************************************
         htmlBody+='<table class="list" border="1" cellpadding="0" cellspacing="0" width="100%">';
         htmlBody+='<thead class=""><tr class=" headerRow">';         
         htmlBody+='<thead> <th class="dataCell" colspan="4" style="color:black">'+'Enhanced Tech Forecast'+'</th></thead></tr>';
         htmlBody+='<tr> <th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Forecast Period</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Commit (Core) Forecast</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Comment</th>';
         htmlBody+='</tr></thead>';
         htmlBody+='<tbody>';          
         
         for(ForeCastWrap ec: enhanceFC){        
         htmlBody+='<tr class="dataRow even first">';        
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="20%">'+ec.month+'</td>';   
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="20%">'+ec.commitAmt+'</td>';
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="85%">'+ec.cComment+'</td>';
         htmlBody+='</tr>';            
         } 
          
         htmlBody+='</tbody></table><br/><br/>'; 
         
         //************************************Service Forecast******************************************
       /*  htmlBody+='<table class="list" style="width:100%" border="1" cellpadding="0" cellspacing="0">';
         htmlBody+='<thead class=""><tr class=" headerRow">';
         htmlBody+='<thead> <th class="dataCell" colspan="3" style="color:black">'+'Enhanced Tech Forecast'+'</th></thead></tr>';
         htmlBody+='<tr> <th class=" headerRow" scope="col" colspan="1">Commit (Core) Forecast</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1">Comment</th>';
         htmlBody+='</tr></thead>';
         htmlBody+='<tbody>';          
         
         for(ForeCastWrap sc: ServiceFC){        
         htmlBody+='<tr class="dataRow even first">';         
         htmlBody+='<td class="dataCell" colspan="1" style="color:black">'+sc.commitAmt+'</td>';
         htmlBody+='<td class="dataCell" colspan="1" style="color:black">'+sc.cComment+'</td>';
         htmlBody+='</tr>';            
         } 
          
         htmlBody+='</tbody></table><br/><br/>'; */
         
         mail.setUseSignature(false);            
         mail.setHtmlBody(htmlBody);
         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
         //ApexPages.Message myMsg2 = new ApexPages.Message(ApexPages.Severity.Info,'Manager email address to send email: '+toAddresses);
         //ApexPages.addMessage(myMsg2);  
      
       }
    
    
    }
    
    
        
}
Below is the test class which is having only 45 code coverage. 
@isTest(seealldata=true)
private class CForecastSubmitCnt_Test {

 static testMethod void myTest() {


  Period P = [Select id,EndDate, Number, PeriodLabel, QuarterLabel, StartDate,  Type 
              from Period
              where startdate = THIS_YEAR and Type = 'Month' limit 1]; 
              
  ForecastingType F = [select Id,MasterLabel from ForecastingType
                       where isactive = true and MasterLabel = 'Opportunity Revenue' limit 1];             

  ForecastingOwnerAdjustment foa = new ForecastingOwnerAdjustment(
                                                            startdate= p.startdate,
                                                            owneradjustedamount = 100,
                                                            forecastingitemcategory = 'CommitForecast',
                                                            forecastingtypeid = F.id, 
                                                            forecastownerid = UserInfo.getUserId()                     
                                                            ); 
   
  insert foa;
   

  ForecastingOwnerAdjustment foau =  new ForecastingOwnerAdjustment(
                                                id = foa.id,
                                                owneradjustedamount = 100);
                                                   
  update foau;
  
  
  test.StartTest();
  
  PageReference pageRef = Page.EditOppLines;
  Test.setCurrentPage(pageRef);
  CForecastSubmitCnt controller = new CForecastSubmitCnt();
  controller.selectedForecastQ = p.id;
 
  controller.populateMap();
  
  test.StopTest();  
 
   
  }
}

I was to call the wrapper below from class in test class please suggest me how to call.

public class ForeCastWrap {
        
        public ForeCastWrap(String month, Date StDate){
            this.month = month;
            commitAmt = 0;
            bestCaseAmt = 0;
            this.StDate = StDate;
        }
        public String month {get; set;}
        public String type;
        
        public ID commitID {get; set;}
        public Decimal commitAmt {get; set;}
        public String cComment {get; set;}          
        
        public ID bestCaseID {get; set;}
        public Decimal bestCaseAmt {get; set;}
        public String bcComment {get; set;}
        public Date StDate;
    }    

Thanks
Sudhir
 
Hi,

I would like to create a similar section "Users in Assigned territories" on Opportunity as its available in Account. How Could I add these Territory users in opportunity too?

Opportunity has only one lookup territory2 field and no other ways to add Territory teams to the Opportunity.  Any standard way to achieve this rather adding any custom UI!

If anyone could help?
Hi,

Does any one help to get dumps for Spring 17 Service Cloud consultant? After April 19 2017, Service could questions are changed. Hence I need help to get the materials. 
Hi,

Can any one help me in resolving issue with custom field with long text Area while using in where clause?
Query: Select ID, Name, Customer_Comments__c from Contact where 
Customer_Comments__c !=  null
Customer_Comments__c  is a type of Long Text Area- of length 30,000.

I wanted to use this field in SOQL query. But salesforce throws error while using this field in the filtered critieria in where clause.

Thanks,
Sasmita

 
Hi All-
     I need your help in writing a test class for the following batch apex class. This batch creates new child records on being processed. I saw multiple posts where batches update the exisiting record and understood how to writes a test class for the same. But since my batch is creating completely new records I am having difficulty in writing its test class. I have written something but that does not cover the entire execute methos , it covers everything else. Please help me.

Batch Class: 

global class CreateNewSummaryFormRecords implements Database.Batchable<Sobject>, Database.Stateful {

    global Database.QueryLocator start(Database.BatchableContext bc) {
        //first, you gather all the records you want to create a new record with
        String query = 'Select Id,Risk_Assessment_Active__c,Project_Manager__c,Chair_Reviewer__c from Project_Risk_Review__c where Risk_Assessment_Active__c = true and Review_Meeting_Date_Tentative__c = False and Number_Of_Days_For_Next_Review__c=2';
        //below checks to see if the batch is being called from a test class. If the record count
        //returned by the query above is over 200, the test will fail
        if(Test.isRunningTest())
            query += ' limit 200';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext bc, List<Project_Risk_Review__c> originalrecords){
        //now we want to loop through the records from the query above and create the new records
        //and store them in a list
        List<Project_Form__c> newrecords = new List<Project_Form__c>();
        
        for(Project_Risk_Review__c yo1:originalrecords){ // this is the loop
            Project_Form__c yo2 = new Project_Form__c(); //this sets up a new record to be created
            yo2.Project_Risk_Assessment__c= yo1.Id;
            yo2.RecordTypeId=Label.PRAS_Project_Summary_Form_Record_Type;
            yo2.Project_Manager__c=yo1.Project_Manager__c;
            yo2.Chair_Reviewer__c=yo1.Chair_Reviewer__c;
            //add any other fields on the new record that you want to set
            newrecords.add(yo2); 
            //add to list to insert into SFDC later
        }

        //this checks to see if there are any records to insert. If there are, then it will 
        //create them
        if(!newrecords.isEmpty())
            database.insert(newrecords,false); 
        //newrecords is the list of records you put in during the for loop. The "false" is saying,
        //if one records fails to insert, still insert the rest (All or Nothing)
    }
    
    global void finish(Database.BatchableContext bc) {}
}

Sample Test Class:


@isTest
public class CreateNewSummaryFormRecordsTest
{
 
  static testMethod void testMethod1(){
        Account testAccount = TestUtil.generateTestAccount();
        insert testAccount;

        Opportunity testOpp = new Opportunity();
        testOpp.Name = 'Opportunity For Unit Test';
        testOpp.AccountId = testAccount.Id;
        testOpp.StageName = 'Qualification';
        testOpp.CloseDate = Date.Today().AddDays(365);
        testOpp.Org__c= '1010101';
        testOpp.Project_Director__c = UserInfo.getUserId();
        testOpp.RAQ_Human_Subjects__c='Yes';
        testOpp.Amount=1000000;
        testOpp.Estimated_Subcontractor_Amount__c=1000000;
        insert testOpp;
        
       
        List<User> u1= [SELECT Id,IsActive FROM User WHERE isActive=True and ProfileId=:Label.PRAS_RTI_BusinessDevelopment_Profile_Id Limit 4];
        List<User> u2= [SELECT Id,IsActive FROM User WHERE isActive=False and ProfileId=:Label.PRAS_RTI_BusinessDevelopment_Profile_Id Limit 1];
        
        Costpoint_Project__c testCostpointProject = new Costpoint_Project__c();
        testCostpointProject.Name = '0281300.003';
        testCostpointProject.Project_Name__c = '0281300.003';
        testCostpointProject.Project_Number__c = '0281300.003';
        testCostpointProject.Owning_Reorg_Level_6__c='1.2.1.30.03.03';
        testCostpointProject.Contract_Type__c='GRANT';
        testCostpointProject.Contract_Value__c=100000000;
        testCostpointProject.Business_Unit__c='SSES';
        testCostpointProject.Unit__c='EHS';
        testCostpointProject.Division__c='Environment';
        testCostpointProject.Review_Required__c=False;
        testCostpointProject.Project_Manager__c=u1[0].Id;
        insert testCostpointProject;
        
       
        //Fetch related Project Risk Review form.
        Project_Risk_Review__c ProRiskRev=[Select id,DVP__c,Project_Manager__c,Chair_Reviewer__c,Delegate__c 
                                           from Project_Risk_Review__c where Costpoint_Project__c=:testCostpointProject.Id Limit 1];
                                            ProRiskRev.Chair_Reviewer__c=u1[0].Id;
        ProRiskRev.DVP__c=u1[1].Id;
        ProRiskRev.Project_Manager__c=u1[2].Id;
        ProRiskRev.Delegate__c=u1[3].Id;
        Update ProRiskRev;
        ProRiskRev.Chair_Reviewer__c=u1[3].Id;
        ProRiskRev.DVP__c=u1[2].Id;
        ProRiskRev.Project_Manager__c=u1[1].Id;
        ProRiskRev.Delegate__c=u1[0].Id;
        Update ProRiskRev;
        
        Project_Form__c ProForm=new Project_Form__c();
        ProForm.Project_Risk_Assessment__c=ProRiskRev.Id;
        ProForm.RecordTypeId=Label.PRAS_Project_Summary_Form_Record_Type;
        ProForm.Project_Manager__c=ProRiskRev.Project_Manager__c;
        ProForm.Chair_Reviewer__c=ProRiskRev.Chair_Reviewer__c;
        insert ProForm;
        
        
        Test.startTest();
        CreateNewSummaryFormRecords obj = new CreateNewSummaryFormRecords();
        DataBase.executeBatch(obj);
        Test.stopTest();

 
         
 }

}
 
Hi I am beginner i am not able to open My developr account. 
 
Hi,
   
  Below is the controller 
public with sharing class CForecastSubmitCnt{
    
    public Map<id, Period> periodMap;
    Date todaydate = system.today();
    public List<SelectOption> forecastQtr {get; set;}
    
    public String selectedForecastQ{get;set;}
   
    public List<Collaborative_Forecast_History__c> revenueHFCs {get; set;}
    public List<Collaborative_Forecast_History__c> enhanceHFCs {get; set;}
  //public List<Collaborative_Forecast_History__c> ServiceHFCs {get; set;} 
     
    public list<ForeCastWrap> revenueFC {get; set;} 
    public list<ForeCastWrap> enhanceFC {get; set;}
  //public list<ForeCastWrap> ServiceFC {get; set;}
    List<ForecastingOwnerAdjustment> upsertLst; 
    List<Collaborative_Forecast_History__c> upsertHstLst; //History
    Map<String, Id> forecastingTypeMap;
    
    static string FORECAST_TYPE_REVENUE = 'Opportunity Revenue';
    static string FORECAST_TYPE_ENHANCE = 'Enhanced Tech Amount';
  //static string FORECAST_TYPE_SPLIT   = 'Opportunity Split Revenue';
    
    static string FORECAST_CATEGORY_COMMIT   = 'CommitForecast';
    static string FORECAST_CATEGORY_BESTCASE = 'BestCaseForecast';
       
    public class ForeCastWrap {
        
        public ForeCastWrap(String month, Date StDate){
            this.month = month;
            commitAmt = 0;
            bestCaseAmt = 0;
            this.StDate = StDate;
        }
        public String month {get; set;}
        public String type;
        
        public ID commitID {get; set;}
        public Decimal commitAmt {get; set;}
        public String cComment {get; set;}          
        
        public ID bestCaseID {get; set;}
        public Decimal bestCaseAmt {get; set;}
        public String bcComment {get; set;}
        public Date StDate;
    }    
    
    public CForecastSubmitCnt(){
      
       if( getManagerEmail(UserInfo.getUserId()) ==  null ) {
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'No manager has been set up to receive this Forecast submission.  Please contact the SFDC Team (sfdc@fortinet.com) for assistance'));
          }
       else {     
        // Displays 4 quarter 
        periodMap = new Map<id, Period>([ select id, StartDate, Number, type, EndDate, FullyQualifiedLabel  from Period 
                                         where type in ('Quarter', 'Month') and ( startdate = THIS_QUARTER or startdate=NEXT_N_QUARTERS:3) order by startdate]);
        forecastQtr = new List<SelectOption>();
        for(Period p : periodMap.values()) {
            if(p.type == 'Quarter') {
                forecastQtr.add(new SelectOption(p.id,'Q'+p.Number+' '+p.StartDate.year() ));
                if(selectedForecastQ == null)
                    selectedForecastQ = p.id;
            }
        }                     
          
        displayForecastTable(); 
        displayForecastHistoryTable(); 
        }
    }
    
    public Map<Integer, ForeCastWrap> populateMap () {
        Period qtrPeriod = periodMap.get(selectedForecastQ);
        Map<Integer, ForeCastWrap> fcMap = new Map<Integer, ForeCastWrap>();
        for(Period p : periodMap.values()) {
            if(p.type == 'Month' && p.StartDate >= qtrPeriod.StartDate && p.StartDate <= qtrPeriod.EndDate) {
                fcMap.put(p.StartDate.month(), new ForeCastWrap(p.FullyQualifiedLabel.mid(0, 3), p.StartDate));
            }
        }
        system.debug('__map_' + fcMap);
        return fcMap;
    }
    
    public void displayForecastTable(){
        Period sltdQPeriod = periodMap.get(selectedForecastQ);
        Map<Integer, ForeCastWrap> revenueFCMap = populateMap(); 
        Map<Integer, ForeCastWrap> enhanceFCMap = populateMap();
        Map<Integer, ForeCastWrap> ServiceFCMap = populateMap();
        
        list<ForecastingOwnerAdjustment> forecastLst = [select id,forecastingitemcategory,periodid, startdate,owneradjustedamount,owneradjustmentnote,
                                                        forecastingtype.masterlabel from forecastingowneradjustment 
                                                        where ForecastOwnerId = :UserInfo.getUserId()
                                                        and startdate >= :sltdQPeriod.StartDate and startdate <= :sltdQPeriod.EndDate ];
                                                        
        for(ForecastingOwnerAdjustment foa : forecastLst) {
            
            if( foa.forecastingtype.masterlabel == FORECAST_TYPE_REVENUE) {
                ForeCastWrap fcWrap = revenueFCMap.get(foa.startdate.month());
                if(foa.forecastingitemcategory == FORECAST_CATEGORY_COMMIT){               
                    fcWrap.commitID = foa.id;
                    fcWrap.commitAmt = foa.owneradjustedamount; 
                    fcWrap.cComment = foa.owneradjustmentnote;                              
                }  
                else if( foa.forecastingitemcategory == FORECAST_CATEGORY_BESTCASE) {
                    fcWrap.bestCaseID = foa.id;
                    fcWrap.bestCaseAmt = foa.owneradjustedamount; 
                    fcWrap.bcComment = foa.owneradjustmentnote;                              
                }
            } else if( foa.forecastingtype.masterlabel == FORECAST_TYPE_ENHANCE && foa.forecastingitemcategory == FORECAST_CATEGORY_COMMIT) {
                ForeCastWrap fcWrap = enhanceFCMap.get(foa.startdate.month());
                fcWrap.commitID = foa.id;
                fcWrap.commitAmt = foa.owneradjustedamount; 
                fcWrap.cComment = foa.owneradjustmentnote;                              
                
            } /* else if( foa.forecastingtype.masterlabel == FORECAST_TYPE_SPLIT && foa.forecastingitemcategory == FORECAST_CATEGORY_COMMIT) {
                ForeCastWrap fcWrap = ServiceFCMap.get(foa.startdate.month());
                fcWrap.commitID = foa.id;
                fcWrap.commitAmt = foa.owneradjustedamount; 
                fcWrap.cComment = foa.owneradjustmentnote;                              
            } */
        }
        
        revenueFC = revenueFCMap.values();
        enhanceFC = enhanceFCMap.values();
      //ServiceFC = ServiceFCMap.values();
        system.debug(revenueFC);
        system.debug(enhanceFC);
        //system.debug(ServiceFC);
        
        displayForecastHistoryTable();
   
    }    
    
    
    //Display Forecast History Data
    public void displayForecastHistoryTable(){
    
     Period sltdQPeriod = periodMap.get(selectedForecastQ);
       
      revenueHFCs = [select Quater__c, Start_Date__c ,Comment__c, Commit_Amount__c, Best_Case_Amount__c, Forecast_Type__c,Submission_Date__c,createddate                      
                                                             from Collaborative_Forecast_History__c
                                                             where
                                                             OwnerId = :UserInfo.getUserId() and
                                                             Forecast_Type__c = :FORECAST_TYPE_REVENUE and
                                                             Start_Date__c >= :sltdQPeriod.StartDate and Start_Date__c <= :sltdQPeriod.EndDate order by createddate desc ];
      
      enhanceHFCs = [select Quater__c, Start_Date__c ,Comment__c, Commit_Amount__c, Best_Case_Amount__c, Forecast_Type__c,Submission_Date__c,createddate                     
                                                             from Collaborative_Forecast_History__c
                                                             where
                                                             OwnerId = :UserInfo.getUserId() and
                                                             Forecast_Type__c = :FORECAST_TYPE_ENHANCE and
                                                             Start_Date__c >= :sltdQPeriod.StartDate and Start_Date__c <= :sltdQPeriod.EndDate order by createddate desc];

      
    /*  ServiceHFCs = [select Quater__c, Start_Date__c ,Comment__c, Commit_Amount__c, Best_Case_Amount__c, Forecast_Type__c,Submission_Date__c,createddate                     
                                                             from Collaborative_Forecast_History__c
                                                             where
                                                             OwnerId = :UserInfo.getUserId() and
                                                             Forecast_Type__c = :FORECAST_TYPE_SPLIT and
                                                             Start_Date__c >= :sltdQPeriod.StartDate and Start_Date__c <= :sltdQPeriod.EndDate order by createddate desc]; */
 
    
    }        
      
    
    public void populateDataList(list<ForeCastWrap> lst, String fcType) {
        Period qtrPeriod = periodMap.get(selectedForecastQ);
        String Qlabel = 'Q'+qtrPeriod.Number + ' ' + qtrPeriod.StartDate.year();
        for(ForeCastWrap fc : lst) {
            ForecastingOwnerAdjustment foa = new ForecastingOwnerAdjustment( id = fc.commitID,
                                                                            startdate=fc.stDate,
                                                                            owneradjustedamount = fc.commitAmt,
                                                                            //owneradjustmentnote  = fc.cComment,
                                                                            forecastingitemcategory = FORECAST_CATEGORY_COMMIT,
                                                                            forecastingtypeid = getTypeID(fcType), 
                                                                            forecastownerid = UserInfo.getUserId()                     
                                                                           ); 
            upsertLst.add(foa);
            system.debug('kkk__' + foa);                                                              
            Collaborative_Forecast_History__c  foaH =  new Collaborative_Forecast_History__c (
                Quater__c = Qlabel,
                Start_Date__c=fc.stDate,
                Submission_Date__c = System.today(),
                Commit_Amount__c = fc.commitAmt, 
                Comment__c =  fc.cComment,
                Forecast_Type__c = fcType
            );

            
            if(fcType == FORECAST_TYPE_REVENUE) {
                
                foa = new ForecastingOwnerAdjustment(id = fc.bestCaseID,
                                                     startdate=fc.stDate,
                                                     owneradjustedamount = fc.bestCaseAmt,
                                                     //owneradjustmentnote  = fc.bcComment,
                                                     forecastingitemcategory = FORECAST_CATEGORY_BESTCASE,
                                                     forecastingtypeid = getTypeID(FORECAST_TYPE_REVENUE), 
                                                     forecastownerid = UserInfo.getUserId()                                                                      
                                                    ); 
                upsertLst.add(foa); 
                system.debug('kkk__' + foa);
                foaH.Best_Case_Amount__c = fc.bestCaseAmt; 
                //foaH.Comment__c =  fc.cComment;
                
            }
            upsertHstLst.add(foaH);
        }        
        
    }
    
    public void submit() {
      
        upsertHstLst = new List<Collaborative_Forecast_History__c>();
        upsertLst = new List<ForecastingOwnerAdjustment>();     
        populateDataList(revenueFC, FORECAST_TYPE_REVENUE);
        populateDataList(enhanceFC, FORECAST_TYPE_ENHANCE);
     // populateDataList(ServiceFC, FORECAST_TYPE_SPLIT);
 
            upsert upsertLst ID;
            Insert upsertHstLst;
        
            sendEmail();
            displayForecastTable();
        
            ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Forecast submitted to '  + getManagerEmail(UserInfo.getUserId()) + '  on  ' + system.now() ));
              
    }
    
    public ID getTypeID(String label){
        if(forecastingTypeMap == null) {
            forecastingTypeMap = new Map<String, Id>();
            for (ForecastingType ft : [select id, masterlabel from Forecastingtype where isactive=true])  {
                forecastingTypeMap.put(ft.masterlabel, ft.id);
            }
        }
        return forecastingTypeMap.get(label);
    } 
    
    public String getManagerEmail(Id userId) {
        User curUser;
        String managerEmail = null;
        
        // Get User Parent Id
        curUser = [select Id,name,UserRole.ForecastUserId,Email,UserRoleId,Userrole.name, UserRole.ParentRoleid from User where id = :UserInfo.getUserId()];
        if( curUser.Userrole.name == 'Administrator')
            managerEmail = curUser.email;
        // Get Forecast Manager role id
        if(curUser.UserRole.ParentRoleid <> null) {
            Userrole managerRole = [select Id,ForecastUserId, ParentRoleid from userrole where id = :curUser.UserRole.ParentRoleid];
            user mUser = [select id,name,email from user where id = :managerRole.ForecastUserId];
            system.debug('Manager Name : ' + mUser.name);  
            managerEmail =  mUser.email;
            system.debug('Forecast Manager Email :' + managerEmail);
        }   
        return managerEmail;
    }
   
    public void sendEmail() {
        
      Period qtrPeriod = periodMap.get(selectedForecastQ);
      String Qlabel = 'Q'+qtrPeriod.Number + ' ' + qtrPeriod.StartDate.year();
      List<String> toAddresses = new List<String>();
      String htmlBody;      
      String MgrMail;
      
      // Check Manager Email to add
      MgrMail = getManagerEmail(UserInfo.getUserId());
       
       if(MgrMail <> null){     
          toAddresses.add(MgrMail); 
        }
      
      //Copy user mail     
      toAddresses.add(UserInfo.getUserEmail());
      //toAddresses.add('sudhirn@fortinet.com');
      
      if(toAddresses.size() >0 && toAddresses != null){
      
         Messaging.reserveSingleEmailCapacity(2);
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
         mail.setToAddresses(toAddresses);
         mail.setSenderDisplayName('Collaborative Forecasting Submission Alert');
         mail.setSubject('Collaborative Forecasting Submission Alert :'+userinfo.getname()+' - '+Qlabel);
        
         htmlBody= userinfo.getname() +  ' has submitted the below forecast for  : ' + Qlabel + ' on ' + system.now() + '<br/><br/>';
         
         htmlBody += '<head><style> table, th, td { border: 1px solid black; } </style> </head>';
         
         //************************************Total Revenue Forecast******************************************
         htmlBody+='<table class="list" border="1" cellpadding="0" cellspacing="0" width="100%">';  
         htmlBody+='<thead class=""><tr class=" headerRow">';
         htmlBody+='<thead> <th class="dataCell" colspan="5" style="color:black">'+'Total Revenue Forecast'+'</th></thead></tr>';
         htmlBody+='<tr> <th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Forecast Period</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Commit (Core) Forecast</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Best Case (Stretch) Forecast</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Comment</th>';
         htmlBody+='</tr></thead>';
         htmlBody+='<tbody>';          
         
         for(ForeCastWrap rc: revenueFC){        
         htmlBody+='<tr class="dataRow even first">'; 
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="20%">'+rc.month+'</td>';  
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="20%">'+rc.commitAmt+'</td>';        
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="20%">'+rc.bestCaseAmt+'</td>';
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="50%">'+rc.cComment+'</td>';
         htmlBody+='</tr>';            
         }
         htmlBody+='</tbody></table><br/><br/>';
          
         //************************************Enhanced Tech Forecast******************************************
         htmlBody+='<table class="list" border="1" cellpadding="0" cellspacing="0" width="100%">';
         htmlBody+='<thead class=""><tr class=" headerRow">';         
         htmlBody+='<thead> <th class="dataCell" colspan="4" style="color:black">'+'Enhanced Tech Forecast'+'</th></thead></tr>';
         htmlBody+='<tr> <th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Forecast Period</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Commit (Core) Forecast</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1" bgcolor="#E5E5E5">Comment</th>';
         htmlBody+='</tr></thead>';
         htmlBody+='<tbody>';          
         
         for(ForeCastWrap ec: enhanceFC){        
         htmlBody+='<tr class="dataRow even first">';        
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="20%">'+ec.month+'</td>';   
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="20%">'+ec.commitAmt+'</td>';
         htmlBody+='<td class="dataCell" colspan="1" style="color:black" width="85%">'+ec.cComment+'</td>';
         htmlBody+='</tr>';            
         } 
          
         htmlBody+='</tbody></table><br/><br/>'; 
         
         //************************************Service Forecast******************************************
       /*  htmlBody+='<table class="list" style="width:100%" border="1" cellpadding="0" cellspacing="0">';
         htmlBody+='<thead class=""><tr class=" headerRow">';
         htmlBody+='<thead> <th class="dataCell" colspan="3" style="color:black">'+'Enhanced Tech Forecast'+'</th></thead></tr>';
         htmlBody+='<tr> <th class=" headerRow" scope="col" colspan="1">Commit (Core) Forecast</th>';
         htmlBody+='<th class=" headerRow" scope="col" colspan="1">Comment</th>';
         htmlBody+='</tr></thead>';
         htmlBody+='<tbody>';          
         
         for(ForeCastWrap sc: ServiceFC){        
         htmlBody+='<tr class="dataRow even first">';         
         htmlBody+='<td class="dataCell" colspan="1" style="color:black">'+sc.commitAmt+'</td>';
         htmlBody+='<td class="dataCell" colspan="1" style="color:black">'+sc.cComment+'</td>';
         htmlBody+='</tr>';            
         } 
          
         htmlBody+='</tbody></table><br/><br/>'; */
         
         mail.setUseSignature(false);            
         mail.setHtmlBody(htmlBody);
         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
         //ApexPages.Message myMsg2 = new ApexPages.Message(ApexPages.Severity.Info,'Manager email address to send email: '+toAddresses);
         //ApexPages.addMessage(myMsg2);  
      
       }
    
    
    }
    
    
        
}
Below is the test class which is having only 45 code coverage. 
@isTest(seealldata=true)
private class CForecastSubmitCnt_Test {

 static testMethod void myTest() {


  Period P = [Select id,EndDate, Number, PeriodLabel, QuarterLabel, StartDate,  Type 
              from Period
              where startdate = THIS_YEAR and Type = 'Month' limit 1]; 
              
  ForecastingType F = [select Id,MasterLabel from ForecastingType
                       where isactive = true and MasterLabel = 'Opportunity Revenue' limit 1];             

  ForecastingOwnerAdjustment foa = new ForecastingOwnerAdjustment(
                                                            startdate= p.startdate,
                                                            owneradjustedamount = 100,
                                                            forecastingitemcategory = 'CommitForecast',
                                                            forecastingtypeid = F.id, 
                                                            forecastownerid = UserInfo.getUserId()                     
                                                            ); 
   
  insert foa;
   

  ForecastingOwnerAdjustment foau =  new ForecastingOwnerAdjustment(
                                                id = foa.id,
                                                owneradjustedamount = 100);
                                                   
  update foau;
  
  
  test.StartTest();
  
  PageReference pageRef = Page.EditOppLines;
  Test.setCurrentPage(pageRef);
  CForecastSubmitCnt controller = new CForecastSubmitCnt();
  controller.selectedForecastQ = p.id;
 
  controller.populateMap();
  
  test.StopTest();  
 
   
  }
}

I was to call the wrapper below from class in test class please suggest me how to call.

public class ForeCastWrap {
        
        public ForeCastWrap(String month, Date StDate){
            this.month = month;
            commitAmt = 0;
            bestCaseAmt = 0;
            this.StDate = StDate;
        }
        public String month {get; set;}
        public String type;
        
        public ID commitID {get; set;}
        public Decimal commitAmt {get; set;}
        public String cComment {get; set;}          
        
        public ID bestCaseID {get; set;}
        public Decimal bestCaseAmt {get; set;}
        public String bcComment {get; set;}
        public Date StDate;
    }    

Thanks
Sudhir