• Adam Lee
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 14
    Replies
Hi all.

Hope you can help.

I've created a visualforce page of a custom object with ext controller but it would'n't save to the Contact (Master Detail).

I'm quite new to SF coding.

Here's the VF
 
<apex:page standardcontroller="Fact_Find__c" extensions="FactFindClass" tabstyle="Fact_Find__c">
<apex:form >   
<apex:sectionheader title="My Life Fact-Find"/>
    
<Apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!edit}" value="Edit"/>
</apex:pageBlockButtons>
    
<apex:pageBlocksection id="FFContact"  title="Contact" columns="2" collapsible="false" showheader="true">    
<apex:inputField value="{!ff.Contact__c}" label=""/>
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF"  title="Application Method" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="When you are away from the office and completing an application, which method do you usually use?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Application_Method__c}" label=""/>  
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF2"  title="Further Calls Required?" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="When you submit an application using an online system, without the customer present, how often do you usually have to call them back to gather additional information from when you originally met with them?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Callback_Question__c}" label=""/>  
</apex:pageBlocksection>
<apex:pageBlocksection id="FF3"  title="Mobile/Tablet" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="Would you find a mobile/ tablet version of OLPC useful?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Mobile_Tablet_Question__c}" label=""/>    
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF4"  title="Customer Broadband" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="If you don’t already, would you be comfortable using your customer’s broadband to complete an application online?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Customer_Broadband_Question__c}" label=""/> 
<apex:inputField value="{!Fact_Find__c.My_Life_Customer_Broadband_Question_Add__c}" label="Why?"/>
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF5"  title="Medical Questions" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="If you had the capability to “hand off” the medical questions to the customer so that they could complete them on their own and even at a different time, would you find this useful and appealing for your sales process and the customer journey?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Hand_Off_Medical_Questions__c}" label=""/> 
<apex:inputField value="{!Fact_Find__c.My_Life_Medical_Questions_A__c}" label="Why?" style="width:360px; height:40px"/> 
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF6"  title="Underwriting Answers" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="Would some customers like the option to prohibit you from seeing their underwriting answers?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Prohibit_U_W_Answers_Question__c}" label=""/>    
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>

Here's the ext:
 
public with Sharing class FactFindClass {

    Public Contact con {get;set;}
    Public Contact FFContact {get;set;}
    Public Fact_Find__c ff {get; set;}
    
    public FactFindClass(ApexPages.StandardController sc){
        con = [Select ID, First_Last_Name__c from Contact limit 1];
    ff = [Select Id, Contact__c from Fact_Find__c limit 1];
        ff.Contact__c=con.Id;
    }
    
    
}


Can someone help?

Thanks in advance

Adam
Hi guys.

Hope you can help.

I am quite new with Visualforce and was wondering how I go about creating all the fields below into a matrix table. 

The fields on Salesforce
User-added image

How I want it

User-added image
Thanks in advance

Adam




 
Hi guys,

Any ideas why the formatting of an HTML table looks fine in a PageBlock and all over the place in a pgaeblocksection?

PageBlock
User-added image

PageBlockSection
User-added image

I already have a pageblock you see and dont want another pageblock within a pageblock. 

Any advice would be greatly appreciated

Thanks

Adam
Hi all.

I'm new to VF and APEX and only know the basics.

I am trying to create a VF section on a custom object. I'm trying display certain fields depending on the the type of picklist value is selected.

e.g. if I select picklist 1, A,B and C field shows.
if I select picklist 2, D,E and F field shows.

Would any have any idea on how to do this and have any sample code?

thanks in advance.

Adam
Hi all,

I am creating a trigger to prevent users entering the same "Business_Planning__c" record for the same Month ("Broker_BPMonth__c" field).

How do I refer this trigger to only look at the current Account and not all accounts on SF?
 
trigger ForecastPreventDup on Business_Planning__c (before insert, before update) {
    
    Map<String, Business_Planning__c> monthMap = new Map <String, Business_Planning__c>();
    //Map<Id, Business_Planning__c> accMap = new Map <Id, Business_Planning__c>();
    for (Business_Planning__c b:System.Trigger.new){
        if((b.Broker_BPMonth__c!=null)&&
            (System.Trigger.isInsert ||
            ((b.Broker_BPMonth__c!=
             System.Trigger.oldMap.get(b.Id).Broker_BPMonth__c )
             && b.Account__c == System.Trigger.oldMap.get(b.Id).Account__c))){
                 
                 if(monthMap.containsKey(b.Broker_BPMonth__c)){
                     b.Broker_BPMonth__c.addError('Forecast for this month already exists');
                 }else{
                     monthMap.put(b.Broker_BPMonth__c, b);
                 }
             }
    }
    
    for(Business_Planning__c b:[Select Broker_BPMonth__c From Business_Planning__c 
                                WHERE Broker_BPMonth__c IN :monthMap.keySet()]){
                                    Business_Planning__c newBP = monthMap.get(b.Broker_BPMonth__c);
                                    newBP.Broker_BPMonth__c.addError('Forecast for this month already exists');
                                }
    
    

}


Thanks

Adam
Hi all,

We're quite new to Apex.

we're trying to get a test class for a controller but only covered 40% code coverage.

We cannot get our head round to achieve 100%

Hope you can help

This is the Controller. The 2 parts aren't covered are Task and Hist
public with Sharing class DQMBulkUpdate{
    
    private final Account Account;
   
    public Account getAccount() {
        return Account;
    }
    public DQM_History__c DQMHistory {get; set;}
    
    public DQM_History__c getDQMHistory() {
        return DQMHistory;
    }
    
  /*  public void setDQMHistory(DQM_History__c DQMHistory) {
        this.DQMHistory = DQMHistory;
    }*/
    public List<wrapReview> wrapReviewList {get; set;}
    public List<wrapReview> getwrapReviewList() {
        return wrapReviewList;
    }
    
    public List<DQM_Review__c> selectedReviews{get;set;}
    public List<DQM_Review__c> getDQMReview() {
        return selectedReviews;
    }
   
    public DQMBulkUpdate(){
        Account = [SELECT Id, Name, BillingPostalCode, FRN__c FROM Account 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        DQMHistory = new DQM_History__c();    
        if(wrapReviewList == null) {
            wrapReviewList = new List<wrapReview>();
            
            for(DQM_Review__c a: [SELECT Id
                                  , Name
                                  , Agency_Number__c
                                  , Agency_Number__r.Primary_Contact__c
                                  , Agency_Number__r.Agency_Name__c
                                  , Type__c
                                  , Trigger_Target_Value__c
                                  , Triggered_Date__c
                                  , Triggered_Metric_Value__c
                                  , Owner_Name__c
                                  , Status__c
                                  , CreatedDate
                                  , Account_Id__c
                                  , Account__c
                                  , Generated_From__c
                                  FROM DQM_Review__c
                                  WHERE Status__c = 'Open' And
                                  Account_Id__c = :ApexPages.currentPage().getParameters().get('id')]) 
            {
				wrapReviewList.add(new wrapReview(a));                
			}
        }
    }
    
    public PageReference Save(){
        List<DQM_History__c> history = new List<DQM_History__c>();
  		
        If (DQMHistory.Generate_Task__c == true) {
                Task task = new Task ();   
                task.WhatId = ApexPages.currentPage().getParameters().get('id');
                //task.WhoId = DQMHistory.Contact_Reviewed_With__c;
                task.ActivityDate = DQMHistory.Review_Date__c;
                task.Duration_Mins__c = 10;                    
                task.Status = 'Completed';
                task.OwnerId = Userinfo.getUserId();                      
                task.Priority = 'Normal';   
                task.Subject = 'DQM Review';                  
                task.IsReminderSet = false;
                task.Completed_Date__c = DQMHistory.Review_Date__c;
                task.IP_Category__c = 'S Q & R Research';
                task.Description = DQMHistory.Comments__c; 
                If (DQMHistory.Contact_Type__c == 'Telephone'){
                    task.Type = 'Outbound Call';
                } else if (DQMHistory.Contact_Type__c == 'Face to Face') {
                    task.Type = 'Meeting';
                } else if (DQMHistory.Contact_Type__c == 'Email') {
                    task.Type = 'Email';
                } else {
                    task.Type = 'Note'; 
                } 
            	insert task;
        }
        
        for(DQM_Review__c addrev : selectedReviews)
        {
            DQM_History__c hist = new DQM_History__c ();
            hist.RecordTypeId = Schema.SObjectType.DQM_History__c.getRecordTypeInfosByName().get('Salesforce DQM History').getRecordTypeId();                     
            hist.Review_Date__c = DQMHistory.Review_Date__c;
            hist.Due_Date__c = DQMHistory.Due_Date__c ;   
            hist.Outcome__c = DQMHistory.Outcome__c;
            hist.Comments__c = DQMHistory.Comments__c;
            hist.Contact_Type__c = DQMHistory.Contact_Type__c;     
            hist.Review__c = addrev.id;
            hist.Generate_Task__c = false;
            history.add(hist);  
        }

        insert history; 

        PageReference acctPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        acctPage.setRedirect(false);
        return acctPage;
    }

    public void processSelected() {
        selectedReviews = new List<DQM_Review__c>();
        
        for(wrapReview wrapReviewObj : wrapReviewList) {
            if(wrapReviewObj.selected == true) {
                selectedReviews.add(wrapReviewObj.rev);
            }
        }
    }
    
    // This is our wrapper/container class. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value
    public class wrapReview {
        public DQM_Review__c rev {get; set;}
        public Boolean selected {get; set;}
        
        public wrapReview(DQM_Review__c r) {
            rev = r;
            selected = false;
        }
    }
    
  //  public ApexPages.StandardController myDQMHistoryController {get; set;}
  //  public DQM_History__c DQMHistory {get; set;}
    
}
Here's the test class so far
 
@istest
public class TestDQMBulkUpdate {
    static testMethod void TestDQMBulkUpdateController(){
        
        String txt = 'TESTING123';
        
        //List active User
        List<User> Owner = [Select Id from User where IsActive = true LIMIT 1];
                
        //Insert new Account
        Account acc = new Account(Name='TESTACCOUNT', OwnerId = Owner[0].Id); 
        upsert(acc);

           
     Test.startTest();           
        PageReference pageRef = new PageReference('/apex/DQMBulkUpdate?id=' + acc.Id);
        Test.setCurrentPage(pageRef);
		
	    DQMBulkUpdate controller = new DQMBulkUpdate();

     // ApexPages.currentPage().getParameters().put('Account',acc.Id);	
        
        controller = new DQMBulkUpdate(); 
        controller.getAccount();
        controller.processSelected();
        controller.getDQMHistory();
        controller.getDQMReview();
        controller.getwrapReviewList();
       	controller.Save();
         
 
        String nextPage = controller.Save().geturl();
        System.assertEquals('/' + acc.id, nextPage);

        Boolean error = ApexPages.hasMessages();
        System.assertequals(false,error);
        
       // system.debug(rlist[0].id);  
        
    }
      
}

Thanks in advance for your help
 
Hi all,

Im new to test classes and I am stuck on writing a test class hope you can help.

I have 68% coverage which is obviously not enough.

The trigger updates the parent (Review) when the history is 'Outcome' is Plans in Place - Satisfied. If this is the outcome, the trigger fires and updates the review 'Closed Metric Formula Description' to "REMIT_CFO_APE / REMIT_COMP_APE".

There are multiple of these and these are not covered in the script.
@istest
private class TestUpdateDQMTriggeredValues {
	static testMethod void TestUpdateDQMTriggeredValuesMethod(){
        
         //List active User
        List<User> Owner = [Select Id from User where IsActive = true LIMIT 1];
                
        //Insert new Account
        Account acc = new Account(Name='TESTACCOUNT', OwnerId = Owner[0].Id); 
        upsert(acc);
        
        //Insert new agency
        Agency__c a = new agency__c(Account__c = acc.Id );
        upsert a;
        
        List<DQM_Review__c> reviews = new List <DQM_Review__c>();
        
        DQM_Review__c rev1 = new DQM_Review__c();
        rev1.Generated_From__c = 'Salesforce';
        rev1.Type__c = 'CFO'; 
        rev1.Agency_Number__c=a.id;
        reviews.add(rev1);
        
		DQM_Review__c rev2 = new DQM_Review__c();
        rev2.Generated_From__c = 'Salesforce';
        rev2.Type__c = 'NTU';
        rev2.Agency_Number__c=a.id;
        reviews.add(rev2);
        
  		DQM_Review__c rev3 = new DQM_Review__c();
        rev3.Generated_From__c = 'Salesforce';
        rev3.Type__c = 'Lapse Year 1';
        
        rev3.Triggered_Lapse_Year_1_APE__c = 1234567;
        rev3.Agency_Number__c=a.id;
        reviews.add(rev3);
        
        DQM_Review__c rev4 = new DQM_Review__c();
        rev4.Generated_From__c = 'Salesforce';
        rev4.Type__c = 'Lapse Year 2';
        rev4.Closed_Metric_Value__c = rev4.Current_Lapse_Year_2_APE_Percent__c;     
        rev4.Triggered_Metric_Formula_Description__c ='REMIT_LPS_2_APE / REMIT_LPS_2_APE_EXP';
        rev4.Agency_Number__c=a.id;
        reviews.add(rev4);
        
        DQM_Review__c rev5 = new DQM_Review__c();
        rev5.Generated_From__c = 'Salesforce';
        rev5.Type__c = 'Lapse Year 3';
        rev5.Agency_Number__c=a.id;
        reviews.add(rev5);
        
        DQM_Review__c rev6 = new DQM_Review__c();
        rev6.Generated_From__c = 'Salesforce';
        rev6.Type__c = 'Lapse Year 4';
        rev6.Agency_Number__c=a.id;
        reviews.add(rev6);
        
        DQM_Review__c rev7 = new DQM_Review__c();
        rev7.Generated_From__c = 'Salesforce';
        rev7.Type__c = 'CYD Amend';
        rev7.Agency_Number__c=a.id;
        reviews.add(rev7);
        
        DQM_Review__c rev8 = new DQM_Review__c();
        rev8.Generated_From__c = 'Salesforce';
        rev8.Type__c = 'CYD Return';
        rev8.Agency_Number__c=a.id;
        reviews.add(rev8);
        
        DQM_Review__c rev9 = new DQM_Review__c();
        rev9.Generated_From__c = 'Salesforce';
        rev9.Type__c = 'ND';
        rev9.Agency_Number__c=a.id;
        reviews.add(rev9);
        
        DQM_Review__c rev10 = new DQM_Review__c();
        rev10.Generated_From__c = 'Salesforce';
        rev10.Type__c = 'Relevant ND';
        rev10.Agency_Number__c=a.id;
        reviews.add(rev10);
        
        insert reviews;
                 
        DQM_History__c his1 = new DQM_History__c();
        his1.Review__c = rev1.id;
        his1.Outcome__c = 'Plans in Place - Satisfied';
                                         
       Upsert his1;
       
       \\All of the above works fine

  rev1.Closed_Metric_Formula_Description__c = 'REMIT_CFO_APE / REMIT_COMP_APE';
       Update rev1;
        
    }   
}



Thanks for your help in advance
Hi All,

I am trying to create a trigger to update the record type on the parent based on a field on the latest child record and struggling to do so.

Has anyone done anything like this before?

Hope you can help.

thanks
Hi all.

I'm new with Apex. I want a trigger that will update a text field on the Account with the MAX value from a child object field. I know I can use the Roll up summary but users cannot search the value for this field. Can anyone help?

Thank You

Adam
Hi all.

Hope you can help.

I've created a visualforce page of a custom object with ext controller but it would'n't save to the Contact (Master Detail).

I'm quite new to SF coding.

Here's the VF
 
<apex:page standardcontroller="Fact_Find__c" extensions="FactFindClass" tabstyle="Fact_Find__c">
<apex:form >   
<apex:sectionheader title="My Life Fact-Find"/>
    
<Apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!edit}" value="Edit"/>
</apex:pageBlockButtons>
    
<apex:pageBlocksection id="FFContact"  title="Contact" columns="2" collapsible="false" showheader="true">    
<apex:inputField value="{!ff.Contact__c}" label=""/>
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF"  title="Application Method" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="When you are away from the office and completing an application, which method do you usually use?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Application_Method__c}" label=""/>  
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF2"  title="Further Calls Required?" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="When you submit an application using an online system, without the customer present, how often do you usually have to call them back to gather additional information from when you originally met with them?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Callback_Question__c}" label=""/>  
</apex:pageBlocksection>
<apex:pageBlocksection id="FF3"  title="Mobile/Tablet" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="Would you find a mobile/ tablet version of OLPC useful?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Mobile_Tablet_Question__c}" label=""/>    
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF4"  title="Customer Broadband" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="If you don’t already, would you be comfortable using your customer’s broadband to complete an application online?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Customer_Broadband_Question__c}" label=""/> 
<apex:inputField value="{!Fact_Find__c.My_Life_Customer_Broadband_Question_Add__c}" label="Why?"/>
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF5"  title="Medical Questions" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="If you had the capability to “hand off” the medical questions to the customer so that they could complete them on their own and even at a different time, would you find this useful and appealing for your sales process and the customer journey?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Hand_Off_Medical_Questions__c}" label=""/> 
<apex:inputField value="{!Fact_Find__c.My_Life_Medical_Questions_A__c}" label="Why?" style="width:360px; height:40px"/> 
</apex:pageBlocksection>
    
<apex:pageBlocksection id="FF6"  title="Underwriting Answers" columns="2" collapsible="false" showheader="true">
<apex:outputText style="font-style:italic;font-weight:900;" value="Would some customers like the option to prohibit you from seeing their underwriting answers?"/>
<apex:inputField value="{!Fact_Find__c.My_Life_Prohibit_U_W_Answers_Question__c}" label=""/>    
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>

Here's the ext:
 
public with Sharing class FactFindClass {

    Public Contact con {get;set;}
    Public Contact FFContact {get;set;}
    Public Fact_Find__c ff {get; set;}
    
    public FactFindClass(ApexPages.StandardController sc){
        con = [Select ID, First_Last_Name__c from Contact limit 1];
    ff = [Select Id, Contact__c from Fact_Find__c limit 1];
        ff.Contact__c=con.Id;
    }
    
    
}


Can someone help?

Thanks in advance

Adam
Hi guys.

Hope you can help.

I am quite new with Visualforce and was wondering how I go about creating all the fields below into a matrix table. 

The fields on Salesforce
User-added image

How I want it

User-added image
Thanks in advance

Adam




 
Hi guys,

Any ideas why the formatting of an HTML table looks fine in a PageBlock and all over the place in a pgaeblocksection?

PageBlock
User-added image

PageBlockSection
User-added image

I already have a pageblock you see and dont want another pageblock within a pageblock. 

Any advice would be greatly appreciated

Thanks

Adam
Hi all,

I am creating a trigger to prevent users entering the same "Business_Planning__c" record for the same Month ("Broker_BPMonth__c" field).

How do I refer this trigger to only look at the current Account and not all accounts on SF?
 
trigger ForecastPreventDup on Business_Planning__c (before insert, before update) {
    
    Map<String, Business_Planning__c> monthMap = new Map <String, Business_Planning__c>();
    //Map<Id, Business_Planning__c> accMap = new Map <Id, Business_Planning__c>();
    for (Business_Planning__c b:System.Trigger.new){
        if((b.Broker_BPMonth__c!=null)&&
            (System.Trigger.isInsert ||
            ((b.Broker_BPMonth__c!=
             System.Trigger.oldMap.get(b.Id).Broker_BPMonth__c )
             && b.Account__c == System.Trigger.oldMap.get(b.Id).Account__c))){
                 
                 if(monthMap.containsKey(b.Broker_BPMonth__c)){
                     b.Broker_BPMonth__c.addError('Forecast for this month already exists');
                 }else{
                     monthMap.put(b.Broker_BPMonth__c, b);
                 }
             }
    }
    
    for(Business_Planning__c b:[Select Broker_BPMonth__c From Business_Planning__c 
                                WHERE Broker_BPMonth__c IN :monthMap.keySet()]){
                                    Business_Planning__c newBP = monthMap.get(b.Broker_BPMonth__c);
                                    newBP.Broker_BPMonth__c.addError('Forecast for this month already exists');
                                }
    
    

}


Thanks

Adam
Hi guys. Hope you can advice me.

On my VF section on the page layout, I have managed to get it to display the list. However, the filter (input field) does not work. e.g. When I select "Jan", I want just the records for Jan to display.

User-added image

VF
<apex:page Controller="AccountBrokerGWP" showHeader="True" sidebar="True"> 
    <apex:form >
        <apex:outputPanel id="pnlAll">
      <apex:pageBlock >
          
            <apex:pageblockSection title="Forecasts" collapsible="false" columns="1">
                 
                
                <apex:inputField value="{!forecastMonth.Broker_BPMonth__c}" >
                            <apex:actionSupport event="onchange" status="refreshstatus2" action="{!BPMonth}" reRender="pnlAll"/>
                        </apex:inputField>
                <apex:facet name="header">
                                <apex:outputText value="Forecasts"></apex:outputText>
               			 
                                </apex:facet>
               
                            </apex:pageblockSection>
 
          <apex:pageBlockTable id="table" value="{!ForecastListWrap}" var="BPWrap"  title="All Forecasts" columnsWidth="40px, 40px, 40px, 40px, 40px, 40px, 40px">
			<apex:column headervalue="GWP Forecasts" >
                    	<apex:outputLink value="{!URLFOR($Action.Business_Planning__c.View, BPWrap.BP.id)}" target="_parent">{!BPWrap.BP.Name}</apex:outputLink>
                    </apex:column>				   
                                   
              
			<apex:column value="{!BPWrap.BP.Broker_BPMonth__c}" headerValue="Month" />
            <apex:column value="{!BPWrap.BP.Broker_BP_Planned_GWP__c}" headerValue="Planned GWP" />
            <apex:column value="{!BPWrap.BP.Broker_BP_Actual_GWP__c}" headerValue="Actual GWP" />                   
              </apex:pageBlockTable>
                                      
          </apex:pageBlock>
        </apex:outputPanel>
          
    </apex:form>
    
</apex:page>
Controller
public with sharing class AccountBrokerGWP {

    public Business_Planning__c GWPForecast {get; set;}
    public ID idAcc = ApexPages.currentPage().getParameters().get('id');
    public String fMonth= ApexPages.currentPage().getParameters().get('Broker_BPMonth__c');
    public Boolean  showGWPforecast {get; set;}
    public Boolean ownForecasts {get; set;}
    public Business_Planning__c BPDetails {get; set;}
    public Business_Planning__c forecastMonth {get; set;}
    public Business_Planning__c getBP() {
        return forecastMonth;
    }
    public Boolean ExpandedView {get; set;}
    private Integer noGWPforecast {get; set;}
    public String pnlHeight {get; set;}
    private final Account acc;
    
 

    public AccountBrokerGWP(ApexPages.StandardController controller){
        this.acc = (Account) controller.getRecord();
        showGWPforecast=true;
        
    ownForecasts = True;
    String strOwnforecasts = ApexPages.currentPage().getParameters().get('OwnForecasts');
    ownForecasts = (strOwnForecasts == null) ? true : Boolean.ValueOf(strOwnForecasts);

        forecastMonth = new Business_Planning__c(Broker_BPMonth__c='');
        
    }   
    
    public void BPMonth(){  
        ownForecasts = True;
    }
    
 private final Account Account;
   
    public Account getAccount() {
        return Account;   
    }
    
     public class wrapForecast {
        public Business_Planning__c BP {get; set;}
        public Boolean selected {get; set;}
        
        public wrapForecast(Business_Planning__c r) {
            BP = r;
            selected = false;
        }

    }

    public List<wrapForecast> ForecastListWrap {get; set;}
    

   public AccountBrokerGWP(){
 
        Account = [Select Id, Name FROM Account
            WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        
        if(ForecastListWrap == null){
            ForecastListWrap = new list <wrapForecast>();
            
            for(Business_Planning__c b: [Select Id, Broker_BPMonth__c,
            Broker_BP_Planned_GWP__c, Broker_BP_Actual_GWP__c, Name,  Broker_to_Target__c FROM Business_Planning__c
            WHERE Account__c = :idAcc])
            {
                ForecastListWrap.add(new wrapForecast(b));
            }
               
               
        }
    }

   

}


Any ideas? Ive spent hours on this and Im new to VF and APEX.

Thanks
Hi all,

We're quite new to Apex.

we're trying to get a test class for a controller but only covered 40% code coverage.

We cannot get our head round to achieve 100%

Hope you can help

This is the Controller. The 2 parts aren't covered are Task and Hist
public with Sharing class DQMBulkUpdate{
    
    private final Account Account;
   
    public Account getAccount() {
        return Account;
    }
    public DQM_History__c DQMHistory {get; set;}
    
    public DQM_History__c getDQMHistory() {
        return DQMHistory;
    }
    
  /*  public void setDQMHistory(DQM_History__c DQMHistory) {
        this.DQMHistory = DQMHistory;
    }*/
    public List<wrapReview> wrapReviewList {get; set;}
    public List<wrapReview> getwrapReviewList() {
        return wrapReviewList;
    }
    
    public List<DQM_Review__c> selectedReviews{get;set;}
    public List<DQM_Review__c> getDQMReview() {
        return selectedReviews;
    }
   
    public DQMBulkUpdate(){
        Account = [SELECT Id, Name, BillingPostalCode, FRN__c FROM Account 
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
        DQMHistory = new DQM_History__c();    
        if(wrapReviewList == null) {
            wrapReviewList = new List<wrapReview>();
            
            for(DQM_Review__c a: [SELECT Id
                                  , Name
                                  , Agency_Number__c
                                  , Agency_Number__r.Primary_Contact__c
                                  , Agency_Number__r.Agency_Name__c
                                  , Type__c
                                  , Trigger_Target_Value__c
                                  , Triggered_Date__c
                                  , Triggered_Metric_Value__c
                                  , Owner_Name__c
                                  , Status__c
                                  , CreatedDate
                                  , Account_Id__c
                                  , Account__c
                                  , Generated_From__c
                                  FROM DQM_Review__c
                                  WHERE Status__c = 'Open' And
                                  Account_Id__c = :ApexPages.currentPage().getParameters().get('id')]) 
            {
				wrapReviewList.add(new wrapReview(a));                
			}
        }
    }
    
    public PageReference Save(){
        List<DQM_History__c> history = new List<DQM_History__c>();
  		
        If (DQMHistory.Generate_Task__c == true) {
                Task task = new Task ();   
                task.WhatId = ApexPages.currentPage().getParameters().get('id');
                //task.WhoId = DQMHistory.Contact_Reviewed_With__c;
                task.ActivityDate = DQMHistory.Review_Date__c;
                task.Duration_Mins__c = 10;                    
                task.Status = 'Completed';
                task.OwnerId = Userinfo.getUserId();                      
                task.Priority = 'Normal';   
                task.Subject = 'DQM Review';                  
                task.IsReminderSet = false;
                task.Completed_Date__c = DQMHistory.Review_Date__c;
                task.IP_Category__c = 'S Q & R Research';
                task.Description = DQMHistory.Comments__c; 
                If (DQMHistory.Contact_Type__c == 'Telephone'){
                    task.Type = 'Outbound Call';
                } else if (DQMHistory.Contact_Type__c == 'Face to Face') {
                    task.Type = 'Meeting';
                } else if (DQMHistory.Contact_Type__c == 'Email') {
                    task.Type = 'Email';
                } else {
                    task.Type = 'Note'; 
                } 
            	insert task;
        }
        
        for(DQM_Review__c addrev : selectedReviews)
        {
            DQM_History__c hist = new DQM_History__c ();
            hist.RecordTypeId = Schema.SObjectType.DQM_History__c.getRecordTypeInfosByName().get('Salesforce DQM History').getRecordTypeId();                     
            hist.Review_Date__c = DQMHistory.Review_Date__c;
            hist.Due_Date__c = DQMHistory.Due_Date__c ;   
            hist.Outcome__c = DQMHistory.Outcome__c;
            hist.Comments__c = DQMHistory.Comments__c;
            hist.Contact_Type__c = DQMHistory.Contact_Type__c;     
            hist.Review__c = addrev.id;
            hist.Generate_Task__c = false;
            history.add(hist);  
        }

        insert history; 

        PageReference acctPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        acctPage.setRedirect(false);
        return acctPage;
    }

    public void processSelected() {
        selectedReviews = new List<DQM_Review__c>();
        
        for(wrapReview wrapReviewObj : wrapReviewList) {
            if(wrapReviewObj.selected == true) {
                selectedReviews.add(wrapReviewObj.rev);
            }
        }
    }
    
    // This is our wrapper/container class. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value
    public class wrapReview {
        public DQM_Review__c rev {get; set;}
        public Boolean selected {get; set;}
        
        public wrapReview(DQM_Review__c r) {
            rev = r;
            selected = false;
        }
    }
    
  //  public ApexPages.StandardController myDQMHistoryController {get; set;}
  //  public DQM_History__c DQMHistory {get; set;}
    
}
Here's the test class so far
 
@istest
public class TestDQMBulkUpdate {
    static testMethod void TestDQMBulkUpdateController(){
        
        String txt = 'TESTING123';
        
        //List active User
        List<User> Owner = [Select Id from User where IsActive = true LIMIT 1];
                
        //Insert new Account
        Account acc = new Account(Name='TESTACCOUNT', OwnerId = Owner[0].Id); 
        upsert(acc);

           
     Test.startTest();           
        PageReference pageRef = new PageReference('/apex/DQMBulkUpdate?id=' + acc.Id);
        Test.setCurrentPage(pageRef);
		
	    DQMBulkUpdate controller = new DQMBulkUpdate();

     // ApexPages.currentPage().getParameters().put('Account',acc.Id);	
        
        controller = new DQMBulkUpdate(); 
        controller.getAccount();
        controller.processSelected();
        controller.getDQMHistory();
        controller.getDQMReview();
        controller.getwrapReviewList();
       	controller.Save();
         
 
        String nextPage = controller.Save().geturl();
        System.assertEquals('/' + acc.id, nextPage);

        Boolean error = ApexPages.hasMessages();
        System.assertequals(false,error);
        
       // system.debug(rlist[0].id);  
        
    }
      
}

Thanks in advance for your help
 
Hi all,

Im new to test classes and I am stuck on writing a test class hope you can help.

I have 68% coverage which is obviously not enough.

The trigger updates the parent (Review) when the history is 'Outcome' is Plans in Place - Satisfied. If this is the outcome, the trigger fires and updates the review 'Closed Metric Formula Description' to "REMIT_CFO_APE / REMIT_COMP_APE".

There are multiple of these and these are not covered in the script.
@istest
private class TestUpdateDQMTriggeredValues {
	static testMethod void TestUpdateDQMTriggeredValuesMethod(){
        
         //List active User
        List<User> Owner = [Select Id from User where IsActive = true LIMIT 1];
                
        //Insert new Account
        Account acc = new Account(Name='TESTACCOUNT', OwnerId = Owner[0].Id); 
        upsert(acc);
        
        //Insert new agency
        Agency__c a = new agency__c(Account__c = acc.Id );
        upsert a;
        
        List<DQM_Review__c> reviews = new List <DQM_Review__c>();
        
        DQM_Review__c rev1 = new DQM_Review__c();
        rev1.Generated_From__c = 'Salesforce';
        rev1.Type__c = 'CFO'; 
        rev1.Agency_Number__c=a.id;
        reviews.add(rev1);
        
		DQM_Review__c rev2 = new DQM_Review__c();
        rev2.Generated_From__c = 'Salesforce';
        rev2.Type__c = 'NTU';
        rev2.Agency_Number__c=a.id;
        reviews.add(rev2);
        
  		DQM_Review__c rev3 = new DQM_Review__c();
        rev3.Generated_From__c = 'Salesforce';
        rev3.Type__c = 'Lapse Year 1';
        
        rev3.Triggered_Lapse_Year_1_APE__c = 1234567;
        rev3.Agency_Number__c=a.id;
        reviews.add(rev3);
        
        DQM_Review__c rev4 = new DQM_Review__c();
        rev4.Generated_From__c = 'Salesforce';
        rev4.Type__c = 'Lapse Year 2';
        rev4.Closed_Metric_Value__c = rev4.Current_Lapse_Year_2_APE_Percent__c;     
        rev4.Triggered_Metric_Formula_Description__c ='REMIT_LPS_2_APE / REMIT_LPS_2_APE_EXP';
        rev4.Agency_Number__c=a.id;
        reviews.add(rev4);
        
        DQM_Review__c rev5 = new DQM_Review__c();
        rev5.Generated_From__c = 'Salesforce';
        rev5.Type__c = 'Lapse Year 3';
        rev5.Agency_Number__c=a.id;
        reviews.add(rev5);
        
        DQM_Review__c rev6 = new DQM_Review__c();
        rev6.Generated_From__c = 'Salesforce';
        rev6.Type__c = 'Lapse Year 4';
        rev6.Agency_Number__c=a.id;
        reviews.add(rev6);
        
        DQM_Review__c rev7 = new DQM_Review__c();
        rev7.Generated_From__c = 'Salesforce';
        rev7.Type__c = 'CYD Amend';
        rev7.Agency_Number__c=a.id;
        reviews.add(rev7);
        
        DQM_Review__c rev8 = new DQM_Review__c();
        rev8.Generated_From__c = 'Salesforce';
        rev8.Type__c = 'CYD Return';
        rev8.Agency_Number__c=a.id;
        reviews.add(rev8);
        
        DQM_Review__c rev9 = new DQM_Review__c();
        rev9.Generated_From__c = 'Salesforce';
        rev9.Type__c = 'ND';
        rev9.Agency_Number__c=a.id;
        reviews.add(rev9);
        
        DQM_Review__c rev10 = new DQM_Review__c();
        rev10.Generated_From__c = 'Salesforce';
        rev10.Type__c = 'Relevant ND';
        rev10.Agency_Number__c=a.id;
        reviews.add(rev10);
        
        insert reviews;
                 
        DQM_History__c his1 = new DQM_History__c();
        his1.Review__c = rev1.id;
        his1.Outcome__c = 'Plans in Place - Satisfied';
                                         
       Upsert his1;
       
       \\All of the above works fine

  rev1.Closed_Metric_Formula_Description__c = 'REMIT_CFO_APE / REMIT_COMP_APE';
       Update rev1;
        
    }   
}



Thanks for your help in advance
Hi All,

I am trying to create a trigger to update the record type on the parent based on a field on the latest child record and struggling to do so.

Has anyone done anything like this before?

Hope you can help.

thanks