• PeaceMaker
  • NEWBIE
  • 180 Points
  • Member since 2009


  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 39
    Replies
Hey there,

I have a trigger which is designed to autofill 4 lookup fields. I have attempted to write a test code, it passes except that it only fills 61% code coverage. I was hoping to get some tips on how I may get this over 75% prefereably 100%.

This is my test code:

@isTest
private class TestOfficeCommission_GrabReference {
  
    static testMethod void myGrabTest() {
        
        //name a Office commission record
       
        Date monFirstStart = System.today().addMonths(-2).toStartOfMonth();
Date monFirstEnd = monFirstStart.addDays(Date.daysInMonth(monFirstStart.year(), monFirstStart.month()) - 1);
Date monSecondStart = System.today().addMonths(-1).toStartOfMonth();
Date monSecondEnd = monFirstStart.addDays(Date.daysInMonth(monFirstStart.year(), monFirstStart.month()) - 1).addMonths(1);
Date monThirdStart = System.today().toStartOfMonth();
Date monThirdEnd = monFirstStart.addDays(Date.daysInMonth(monFirstStart.year(), monFirstStart.month()) - 1).addMonths(2);
Date monFourthStart = System.today().toStartOfMonth().addMonths(2);
Date monFourthEnd = monFirstStart.addDays(Date.daysInMonth(monFirstStart.year(), monFirstStart.month()) - 1).addMonths(3);
Date OffComStart = System.today().toStartOfMonth();
Date OffComEnd = OffComStart.addDays(Date.daysInMonth(OffComStart.year(), OffComStart.month()) - 1);


Office__c Off = new Office__c(Name = 'Test');
insert Off;



Commission_period__c NOVJAN = new Commission_period__c(Name = 'NOVJAN', Point_Calculation_Period_Start__c = monFirstStart , Point_Calculation_Period_End__c = monFirstEnd , Office__c = Off.id);
insert NOVJAN;
Commission_period__c DECFEB = new Commission_period__c(Name = 'DECFEB', Point_Calculation_Period_Start__c = monSecondStart , Point_Calculation_Period_End__c = monSecondEnd, Office__c = Off.id );
insert DECFEB;
Commission_period__c JANMAR = new Commission_period__c(Name = 'JANMAR', Point_Calculation_Period_Start__c = monThirdStart , Point_Calculation_Period_End__c = monThirdEnd, Office__c = Off.id );
insert JANMAR;
Commission_period__c FEBAPR = new Commission_period__c(Name = 'FEBAPR', Office__c = Off.id, Point_Calculation_Period_Start__c = monFourthStart, Point_Calculation_Period_End__c = monFourthEnd);
insert FEBAPR;

       Office_Commission__c OffCom = new Office_Commission__c ( Commission_Period_start__c = OffComStart, Commission_Period_End__c = OffComEnd,
       Office__c = Off.id);
        insert OffCom;
              
       
        //build a test dp record with the picklist field set to your previous record


                     
        //query for the record, now that it's been inserted and the trigger has been fired

        OffCom = [ SELECT Bonus_Points_In__C, Bonus_Points_out__c, Bonus_Points_out_2__c, Bonus_Points_out_3__c FROM Office_Commission__c WHERE Id = :OffCom.Id ];    

        //asert that the trigger's field change was made
  

    }
}

This is my trigger:

trigger OfficeCommission_GrabReference on Office_Commission__c (before insert) {

    // Query all the values from the Commision Period
   





List<Commission_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c, Office__c from Commission_Period__c];


for(Office_Commission__c Off:trigger.new)
{
    for(Commission_Period__c  b:comperiodlist){
   
 

// This is for your first If condition , Trying to print all the four values to compare and decide whether it is getting inside the if condition or not. if it is not getting inside the if condition obviously it wont populate the value.


if(Off.Commission_Period_Start__c.addMonths(-2).month() == b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.month() == b.Point_Calculation_Period_End__c.month() && Off.Office__c == b.Office__c)
            Off.Bonus_Points_Out__c = b.Id;


if(Off.Commission_Period_Start__c.addMonths(-1).month() == b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.addMonths(1).month() == b.Point_Calculation_Period_End__c.month() && Off.Office__c == b.Office__c)
            Off.Bonus_Points_Out_2__c = b.Id;
 

if(Off.Commission_Period_Start__c.month() == b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.addMonths(2).month() == b.Point_Calculation_Period_End__c.month()&& Off.Office__c == b.Office__c)
            Off.Bonus_Points_Out_3__c = b.Id;
           
if(Off.Commission_Period_Start__c.addMonths(-3).month() == b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.addMonths(-1).month() == b.Point_Calculation_Period_End__c.month() && Off.Office__c == b.Office__c)
            Off.Bonus_Points_In__c = b.Id;
           

     }

}

}
I have a custom object. And I have a field Name and ID.. How can I display these fileds in Visual Force page, using custom controller.
Thank you in advance.
  • March 04, 2014
  • Like
  • 0
Hey there,

My trigger is designed to fill 3 lookup fields upon record creation..however it is not filling the field Bonus_points_out__c.

Please help.

trigger OfficeCommissionOut_GrabReference on Office_Commission__c (before insert) {
Integer monFirstStart = null;
Integer monFirstEnd = null;
Integer monSecondStart = null;
Integer monSecondEnd = null;
Integer monThirdStart = null;
Integer monThirdEnd = null;
ID Office = null;

    //Figure out minimum and maximum date
    for(Office_Commission__c  Off:trigger.new)
    {

        monFirstStart = Off.Commission_Period_Start__c.month()-2;
        monFirstEnd = Off.Commission_Period_End__c.month();
        monSecondStart = Off.Commission_Period_Start__c.month()-1;
        monSecondEnd = Off.Commission_Period_End__c.month()+1;
        monThirdStart = Off.Commission_Period_Start__c.month();
        monThirdEnd = Off.Commission_Period_End__c.month()+2;
 
    Office = Off.Office__c;
   
       
    }
  
    if(monFirstStart!= null && monThirdEnd!= null)
     {  
        //Get all office commission in that range

  List<Commission_Period__c> CommissionPeriods = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)=:monFirstStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monFirstEnd];

        List<Commission_Period__c> CommissionPeriods2 = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)=:monSecondStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monSecondEnd and office__c=:Office];
         List<Commission_Period__c> CommissionPeriods3 = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)=:monThirdStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monThirdEnd and office__c=:Office];



       
        if(CommissionPeriods.size()>0||CommissionPeriods2.size()>0||CommissionPeriods3.size()>0)
        {
            for(Office_Commission__c Off:trigger.new)
            {
               
                if(Off.Point_Calculation_Period_Start__c !=null&&Off.Point_Calculation_Period_End__c !=null)
                {
                    //check if any office commission apply
                    for(Commission_Period__c oc : CommissionPeriods)
                    {
                     
                       
                        Off.Bonus_Points_Out__c = oc.id;
                    
                       break;
              
                   
                    }
                      for(Commission_Period__c oc2 : CommissionPeriods2)
                    {
                      
                       
                        Off.Bonus_Points_Out_2__c = oc2.id;
                        break;
                       
              
                   
                    }
                      for(Commission_Period__c oc3 : CommissionPeriods3)
                    {
                      
                       
                        Off.Bonus_Points_Out_3__c = oc3.id;
                        break;
                       
              
                   
                }
            }
        }
    }
}
}

Hi All,

I would like to add a Button to the Case layout that allows a user to add themselves to the Case Team with one click.  Is this possible?  Following on Chatter is not an option.  
 

Thanks,
Shane

Hi,

I have a visualforce page showing some data from an object. one of the field has a value  <3/g  , when i tried to export the same page data to excel using contenttype, this particular value is missing in Excel.

Any help?

I tried prefixing  space, &nbsp; ' , ` .. no luck so far..

Hey there,

I have a trigger which is designed to autofill 4 lookup fields. I have attempted to write a test code, it passes except that it only fills 61% code coverage. I was hoping to get some tips on how I may get this over 75% prefereably 100%.

This is my test code:

@isTest
private class TestOfficeCommission_GrabReference {
  
    static testMethod void myGrabTest() {
        
        //name a Office commission record
       
        Date monFirstStart = System.today().addMonths(-2).toStartOfMonth();
Date monFirstEnd = monFirstStart.addDays(Date.daysInMonth(monFirstStart.year(), monFirstStart.month()) - 1);
Date monSecondStart = System.today().addMonths(-1).toStartOfMonth();
Date monSecondEnd = monFirstStart.addDays(Date.daysInMonth(monFirstStart.year(), monFirstStart.month()) - 1).addMonths(1);
Date monThirdStart = System.today().toStartOfMonth();
Date monThirdEnd = monFirstStart.addDays(Date.daysInMonth(monFirstStart.year(), monFirstStart.month()) - 1).addMonths(2);
Date monFourthStart = System.today().toStartOfMonth().addMonths(2);
Date monFourthEnd = monFirstStart.addDays(Date.daysInMonth(monFirstStart.year(), monFirstStart.month()) - 1).addMonths(3);
Date OffComStart = System.today().toStartOfMonth();
Date OffComEnd = OffComStart.addDays(Date.daysInMonth(OffComStart.year(), OffComStart.month()) - 1);


Office__c Off = new Office__c(Name = 'Test');
insert Off;



Commission_period__c NOVJAN = new Commission_period__c(Name = 'NOVJAN', Point_Calculation_Period_Start__c = monFirstStart , Point_Calculation_Period_End__c = monFirstEnd , Office__c = Off.id);
insert NOVJAN;
Commission_period__c DECFEB = new Commission_period__c(Name = 'DECFEB', Point_Calculation_Period_Start__c = monSecondStart , Point_Calculation_Period_End__c = monSecondEnd, Office__c = Off.id );
insert DECFEB;
Commission_period__c JANMAR = new Commission_period__c(Name = 'JANMAR', Point_Calculation_Period_Start__c = monThirdStart , Point_Calculation_Period_End__c = monThirdEnd, Office__c = Off.id );
insert JANMAR;
Commission_period__c FEBAPR = new Commission_period__c(Name = 'FEBAPR', Office__c = Off.id, Point_Calculation_Period_Start__c = monFourthStart, Point_Calculation_Period_End__c = monFourthEnd);
insert FEBAPR;

       Office_Commission__c OffCom = new Office_Commission__c ( Commission_Period_start__c = OffComStart, Commission_Period_End__c = OffComEnd,
       Office__c = Off.id);
        insert OffCom;
              
       
        //build a test dp record with the picklist field set to your previous record


                     
        //query for the record, now that it's been inserted and the trigger has been fired

        OffCom = [ SELECT Bonus_Points_In__C, Bonus_Points_out__c, Bonus_Points_out_2__c, Bonus_Points_out_3__c FROM Office_Commission__c WHERE Id = :OffCom.Id ];    

        //asert that the trigger's field change was made
  

    }
}

This is my trigger:

trigger OfficeCommission_GrabReference on Office_Commission__c (before insert) {

    // Query all the values from the Commision Period
   





List<Commission_Period__c> comperiodlist = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c, Office__c from Commission_Period__c];


for(Office_Commission__c Off:trigger.new)
{
    for(Commission_Period__c  b:comperiodlist){
   
 

// This is for your first If condition , Trying to print all the four values to compare and decide whether it is getting inside the if condition or not. if it is not getting inside the if condition obviously it wont populate the value.


if(Off.Commission_Period_Start__c.addMonths(-2).month() == b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.month() == b.Point_Calculation_Period_End__c.month() && Off.Office__c == b.Office__c)
            Off.Bonus_Points_Out__c = b.Id;


if(Off.Commission_Period_Start__c.addMonths(-1).month() == b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.addMonths(1).month() == b.Point_Calculation_Period_End__c.month() && Off.Office__c == b.Office__c)
            Off.Bonus_Points_Out_2__c = b.Id;
 

if(Off.Commission_Period_Start__c.month() == b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.addMonths(2).month() == b.Point_Calculation_Period_End__c.month()&& Off.Office__c == b.Office__c)
            Off.Bonus_Points_Out_3__c = b.Id;
           
if(Off.Commission_Period_Start__c.addMonths(-3).month() == b.Point_Calculation_Period_Start__c.month()  && Off.Commission_Period_End__c.addMonths(-1).month() == b.Point_Calculation_Period_End__c.month() && Off.Office__c == b.Office__c)
            Off.Bonus_Points_In__c = b.Id;
           

     }

}

}
for some reason, when i view my debug logs after i submit and call an action, i only see the data from when the page reloads, and not the code that was working behind the scenes. i have a save and advance button and i want to see whats going on during the advancing part but all i see if the resultant log from the page reloading...
Thanks in advance.

Requirement is to have a text field or drop down list that the users enters/chooses a product and then clicks search.  The search button then displays all of the opps and quotes where this product is listed.

What would be the best way to achieve this?

Regards,
Hello Everyone,

  I have a strange scenerio that I am not sure is possible.  What I am trying to do is take a date/time field and a number field and get another date time field.  So the use case is the client has a start date and time (date/time field) and a the duration (number field) the duration is the total hours worked.  The idea is to get the end time from the start date and time and the duration.  Now I if this does not work I may propose trying to use two date/time fields to get the duration.  If that is easier what would the formula be for the duration field.  Thank you for your help.  

Greetings! We are in search of someone who is expertly familiar with Salesforce as a Biz Dev tool to customize the platform for our business processes (we are a philanthropic consulting firm). Let me know if you are interested in this relatively straightforward job and I will give you further details about the exact KPI tracking and functionality we envision. 
 

Thank you!

 

Hi Everyone,

Do you know how to customize the Save button in a visualforce page, to open the new record created in edit mode, not in view mode (standard) ?

User-added image


how to create through vf page please give that code 
Hey there,

My trigger is designed to fill 3 lookup fields upon record creation..however it is not filling the field Bonus_points_out__c.

Please help.

trigger OfficeCommissionOut_GrabReference on Office_Commission__c (before insert) {
Integer monFirstStart = null;
Integer monFirstEnd = null;
Integer monSecondStart = null;
Integer monSecondEnd = null;
Integer monThirdStart = null;
Integer monThirdEnd = null;
ID Office = null;

    //Figure out minimum and maximum date
    for(Office_Commission__c  Off:trigger.new)
    {

        monFirstStart = Off.Commission_Period_Start__c.month()-2;
        monFirstEnd = Off.Commission_Period_End__c.month();
        monSecondStart = Off.Commission_Period_Start__c.month()-1;
        monSecondEnd = Off.Commission_Period_End__c.month()+1;
        monThirdStart = Off.Commission_Period_Start__c.month();
        monThirdEnd = Off.Commission_Period_End__c.month()+2;
 
    Office = Off.Office__c;
   
       
    }
  
    if(monFirstStart!= null && monThirdEnd!= null)
     {  
        //Get all office commission in that range

  List<Commission_Period__c> CommissionPeriods = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)=:monFirstStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monFirstEnd];

        List<Commission_Period__c> CommissionPeriods2 = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)=:monSecondStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monSecondEnd and office__c=:Office];
         List<Commission_Period__c> CommissionPeriods3 = [Select Id, Point_Calculation_Period_Start__c, Point_Calculation_Period_End__c from Commission_Period__c where CALENDAR_MONTH(Point_Calculation_Period_Start__c)=:monThirdStart and CALENDAR_MONTH(Point_Calculation_Period_End__c)= :monThirdEnd and office__c=:Office];



       
        if(CommissionPeriods.size()>0||CommissionPeriods2.size()>0||CommissionPeriods3.size()>0)
        {
            for(Office_Commission__c Off:trigger.new)
            {
               
                if(Off.Point_Calculation_Period_Start__c !=null&&Off.Point_Calculation_Period_End__c !=null)
                {
                    //check if any office commission apply
                    for(Commission_Period__c oc : CommissionPeriods)
                    {
                     
                       
                        Off.Bonus_Points_Out__c = oc.id;
                    
                       break;
              
                   
                    }
                      for(Commission_Period__c oc2 : CommissionPeriods2)
                    {
                      
                       
                        Off.Bonus_Points_Out_2__c = oc2.id;
                        break;
                       
              
                   
                    }
                      for(Commission_Period__c oc3 : CommissionPeriods3)
                    {
                      
                       
                        Off.Bonus_Points_Out_3__c = oc3.id;
                        break;
                       
              
                   
                }
            }
        }
    }
}
}
Hi All

I would like to create a visualforce page replacing the standard related list. This is because of the long list of records we have and we would like to see only he records from last 3 months.

Can you please help me to write the code for it.

Here is what I have now:

public class ActiveHistoryClass
{
  
    public String LastModifiedDate { get; set; }
    public String ActivityDate { get; set; }
    public String IsTask { get; set; }
    public String Subject { get; set; }
    public String Name { get; set; }
    public String id { get; set; }
    public String OutbaseActivityHistory { get; set; }

    private ApexPages.StandardSetController controller;
   
    public List<Account> getActiveHistory(){
        return [SELECT (SELECT Subject,IsTask, ActivityDate,
                 LastModifiedDate  FROM ActivityHistories)
                FROM Account];
}}





<apex:page controller="ActiveHistoryClass" tabStyle="Report" >

    <apex:pageBlock >
      <apex:pageBlockTable value="{!OutbaseActivityHistory}" var="c">
            <apex:column title="Activity History">
               <apex:outputLink value="/{!Id }" target="_blank">{!Name}</apex:outputLink>
            </apex:column>     
             '<apex:column value="{!c}" onclick="window.open('https://cs17.salesforce.com/{!id}','_blank')"/>'
           
            <apex:column value="{!Subject}"/>
            <apex:column value="{!IsTask}"/>
            <apex:column value="{!ActivityDate}"/> 
            <apex:column value="{!LastModifiedDate    }"/>    
                 
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>


At the moment it does not show anything! I think I need to map Account with the activity but I am not sure how!

Thank you.

Looking for apex and visualforce coder who can work over skype with me to do a few hours of work occasionally.  

skype:clintjohnson119
Location does not matter.
This can be your part time job.

Experience and Attitude matters. Seasoned developers required who can work fast and deliver output quickly.

Look for Apex and Visualforce developers.

I am building a large project and need developers with good attitude and caliber.

Express your interest to to raj.ahuja987@gmail.com
Hi

I am utilising a datatable to display some data, I am using css from an html website that we are transferring.

At the moment the headers and the columns do not align (rather than justified) - see screenshot

User-added image

I know that I will have to create some additional css & insert some styleclasses into the VF page but this really isnt my thing any help greatly appreciated
code as follows:

<apex:dataTable value="{!CourseResults}" var="item" styleClass="table" rowClasses="tr1,tr2">
                        <apex:column headerValue="Date & Start Time">
                            <apex:outputField value="{!item.Start_Date_and_Time__c}" />
                        </apex:column>
                        <apex:column headerValue="Clinician" >
                            <apex:outputLink value="{!$Page.speaker_details}?id={!item.speaker__r.Id}">{!item.speaker__r.name}</apex:outputLink>
                        </apex:column>
                        <apex:column headerValue="Location" >
                            <apex:outputLink value="{!$Page.venue_details}?id={!item.Venue__r.Id}">{!item.Venue__r.name}</apex:outputLink>
                        </apex:column>
                        <apex:column headerValue="Availability">
                            <apex:outputLink value="{!$Page.speaker_details}" style=" color:#FF0033; text-decoration: blink; text-align:centre;">Free of charge, Book Now !</apex:outputLink>                                                 
                        </apex:column>
                    </apex:dataTable>