• Derek Bisson
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
I have a requirement to query on a custom object's history data for a specific time period. 

General Requirement:

I have a field on a custom object called 'Visits'. Each time a user navigates to a custom VisualForce page, the particular record (id is passed through URL) associated with the VF page is updated to increment 'Visits' by 1.
The requirement is to display the top 5 visited records of all time, while providing the ability for our users to filter on different time periods (either custom or pre-defined).

Solution Approach:

Based on how my solution works, the only way to accomplish this is to use the Custom Object's History (Custom_Object__History) to query the necessary data I need. 

Challenges:

I attempted to use GROUP BY in my SOQL query to distinctly group by ParentId, but I found that he Custom Object's History 'NewValue' field does not support aggregate functions so I cannot use MAX(NewValue). 
Does anyone have a solution for allowing custom date range selection via a selectlist or other means?​Any and all help is MUCH appreciated! Please let me know if further clarification is needed. Thanks!
I have a requirement to query on a custom object's history data for a specific time period. 

General Requirement:

I have a field on a custom object called 'Visits'. Each time a user navigates to a custom VisualForce page, the particular record (id is passed through URL) associated with the VF page is updated to increment 'Visits' by 1.
The requirement is to display the top 5 visited records of all time, while providing the ability for our users to filter on different time periods (either custom or pre-defined).

Solution Approach:

Based on how my solution works, the only way to accomplish this is to use the Custom Object's History (Custom_Object__History) to query the necessary data I need. 

Challenges:

I attempted to use GROUP BY in my SOQL query to distinctly group by ParentId, but I found that he Custom Object's History 'NewValue' field does not support aggregate functions so I cannot use MAX(NewValue). 
Does anyone have a solution for allowing custom date range selection via a selectlist or other means?​Any and all help is MUCH appreciated! Please let me know if further clarification is needed. Thanks!
Hi.

I am trying to deploy a trigger and test class to prodcution with code coverage of 100% .
My production coverage is 92% But when i validate my change set it says code coverage error-71% ..need 75%.

All my classes and triggers are almost 89-90% .

I just refreshed sandbox too to make sure both are in same settings.Stil same error.

Please help..I need this to solve ASAP!!! please.
Hi,

I'm new to Apex and Visualforce and hoping you guys can help me out with something to save me scratching my head any more than I have been!

I'm trying to create a simple proof of concept Visualforce dashboard with an Apex chart with a filter which determines what data is shown in the chart.  The idea being that the filter would show a list of users and upon selecting a user, I see that user's data in the chart.  

I have the filter working fine and passing the selected value back to the Apex class into a variable called 'reps;.  However, I am then struggling to use that 'reps' value in the SOQL query which is used to populate the chart.
 
public List<Opportunity> getAccountList () {
//reps = '005J0000001ftxkIAA';
System.Debug(reps);
   List<Opportunity> con = [SELECT Name, Type,createddate, Amount, Closedate FROM Opportunity WHERE OwnerID =: reps];
   System.Debug('Got to here aswell' ) ;
            System.Debug(reps);

   return con;
}

From the debug lines, I can tell that the 'reps' variable is holding the correct value, populated from the select list dropdown, before and after the SOQL query is executed but I can see my SOQL query is returning zero records.  However, if i uncomment the line to force the exact same value into the 'reps' variable, the query executes fine and returns three rows.

Can anyone give me some pointers as to where I could be going wrong?

Many thanks in advance,
Linda

 
Hi 

I created a Viasulaforce page and apex class and  write trigger of that but its code coverage is not 75%.pleas tell mw where is my wrong

if possible post the test class of my code

Apex class
----------------
public with sharing class sendemail1 
{
   public String TaskId{ get;set; }
   private final Task ta;   
   Task  T;
public sendemail1 (ApexPages.StandardController stdController) 
{       
   this.ta= (Task )stdController.getRecord();
   TaskId = Apexpages.currentPage().getParameters().get('id');    
   system.debug( 'id is'+TaskId );
  
   T=[SELECT id,OwnerId,Subject,Priority,Description,ActivityDate,Email_CC__c,Email_To__c,Email_Bcc__c from Task where id=:TaskId];    
    system.debug( 'taskkkk'+T );
}

 public PageReference sendEmailMethod()
 {
    User theUser = [select Name, Email from User where id = :T.OwnerId LIMIT 1];  
    system.debug( 'uuuuu'+theUser );

 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    
         String[] toAddresses = new String[] {theUser.Email};
        
        
       
       
       
       if(T.Email_Bcc__c!=null)
        {
        string[] BccAddresses =String.valueOf(T.Email_Bcc__c).Split(',');
         mail.setBccAddresses(BccAddresses);
       }
         
       if(T.Email_To__c!=null)
        {
         string[] toaddress =String.valueOf(T.Email_To__c).Split(',');
         mail.setToAddresses(toaddress);
        }
       if(T.Email_CC__c!=null)
         {
         string[] ccAddresses =String.valueOf(T.Email_CC__c).Split(',');
         mail.setCcAddresses(ccAddresses);
         mail.setSubject('New Task Created by  '+ Userinfo.getName()  +'');
         mail.setTargetObjectId(theUser.id);
         }
     //---------------------------------------- Creating Template----------------------------------
String template =  'New Task \n\nTo: '+theUser.Name+',\n\n '+ Userinfo.getName()  +' has assigned you the following task: \n\n';
      
        template+= 'Subject - {1}\n';
        template+= 'Due Date - {2}\n';
        template+= 'Priority - {3}\n';
        String duedate = '';
        if (T.ActivityDate==null)
            duedate = '';
        else
            duedate = T.ActivityDate.format();

     if(T.Description!=null)
        {
            template+='Description - '+T.Description+'\n';
          
        }

        List<String> args = new List<String>();
        args.add(theUser.Name);
        args.add(T.Subject);
        args.add(duedate);
        args.add(T.Priority);
// -----------------------For Creating Task Link--------------------------
        template+= '\n\nFor more details, click the following link: \n\n';
        template+= URL.getSalesforceBaseUrl().toExternalForm() + '/' + T.Id; 
          
        mail.setSaveAsActivity(false);
        mail.setPlainTextBody(template);
     
        // Here's the String.format() call.
        String formattedHtml = String.format(template, args);
     
        mail.setPlainTextBody(formattedHtml);
        
       
        Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});
         PageReference pageRef = new PageReference('/'+TaskId );
        return pageRef ;
       }
      }

Vf Page
-----------
<apex:page standardController="Task" extensions="sendemail1" action="{!sendEmailMethod}" >
  
</apex:page>

test class
--------------

@isTest
public class Test_sendemail1{
static testmethod void createTask(){
    task t = new task();
    t.priority = 'low';
    t.status = 'In Progress';
    t.description = 'testing description';
    t.Email_To__c = 'a@b.com';
    t.Email_Bcc__c = 'a@b.com';
    t.Email_CC__c = 'a@b.com';
    
    test.startTest();
    
    insert t;
    
    test.stopTest();
}
}