• andyaldis1.3969086903835708E12
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 6
    Replies
We are redesigning a large custom application are starting to run into test errors in the old classes and triggers that are no longer needed.   We would like to know if commenting out the old unused code would be an effective method of raising our orgs test coverage.  Does anyone know how that will affect coverage?
Hello,

I have to write a if statement that will check if the ActivityDate on a task is in the current quarter.  Does anyone have a quick trick on how I can do that?  I figure it has to be a pretty common formula.  
I am trying to figure out how to access the TargetObjectId of a batch email to use in the Email Template VF Component.  I set the target Id in my batch and tried assigning it as an Attribute in my template and component but it does not seem to access the record I in my controller.  How do I access that value in my controller?

Here is my component:
<apex:component access="global" controller="RACnSACEmailClass">
<apex:attribute name="recordId" description="Record Id" type="id" assignTo="{!userId}"/>

</apex:component>

Email Template

<messaging:emailTemplate subject="" recipientType="User" relatedToType="User">
  <messaging:htmlEmailBody >
     <c:RACnSACDigestEmailComponent recordId="{!recipient.id}" />
  </messaging:htmlEmailBody>
</messaging:emailTemplate>

Batch Class:
global class RACnSACDigestSCRevisionBatch implements Database.Batchable<sObject> {



    String userRegions = 'select id, Region__c, Email from user where Region__c != Null and isActive = True Order by Region__c asc';

    global RACnSACDigestSCRevisionBatch() {

    }

    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator(userRegions);
    }

    global void execute(Database.BatchableContext BC, List<User> scope) {
        List<Messaging.SingleEmailMessage> emailList = new list<Messaging.SingleEmailMessage>();
        List<emailTemplate> emailTemplateList =[select id from emailTemplate Where name = 'RACnSACDigestEmail'];
        string templateId = emailTemplateList[0].Id;
        List<string> emailAddress = new list<string>();
        emailAddress.add('aaldis@ofiglobal.com');
        system.debug('***** scope size is '+scope.size());
        for(User u: scope){

            System.debug('***** user id is '+u.Id+' region in '+u.region__c+' email is '+u.email);
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            //email.setToAddresses(emailAddress);
            email.setTargetObjectId(u.Id);
            email.setWhatId(u.Id);
            email.setTemplateId(templateId);
            email.setSaveAsActivity(false);
            email.setCcAddresses(emailAddress);
            emailList.add(email);
            //Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        }
        system.debug('***** email list size is '+emailList.size());
        Messaging.sendEmail(emailList);

    }

    global void finish(Database.BatchableContext BC) {

    }


}
 and Controller:
global with sharing class RACnSACEmailClass {

    public User userRecord {get; set;}
    public Id userId {get; set;}
    public Id recordId {get;set;}
    public list<Task> taskList {get; set;}
    public list<Event> eventList{get; set;}
    public string emailAdd {get; set;}
    public string region {get; set;}
    public list<activityWrapper> actList {get; set;}
    public list<activityWrapperImp> actListImp {get; set;}
    public string firm;
    public string name;
    public id cId;
    public string emailHeader {get; set;}
    public datetime todaysDate = system.now();
    public string weekDay {get; set;}
    public date queryRange {get; set;}

    public Id getUserId(){
      return userId;
    }

    public string getUserRecord(string user){
      userId = user;
      userRecord = [select Id, Region__c from User Where Id = :userId];
      if(userRecord != Null){
        region = userRecord.Region__c;
      }
      return region;
    }

    public RACnSACEmailClass() {

        actList = new list<activityWrapper>();
        actListImp = new list<activityWrapperImp>();



        weekDay = todaysDate.format('EEEE');
        system.debug('***** the date is '+weekDay);
        IF(weekDay != 'Monday'){
            queryRange = todaysDate.Date().addDays(-1) ;
        }else{
            queryRange = todaysDate.Date().addDays(-3);
        }
        taskList = [SELECT Id, Region__c, Description, Priority, Activity_Type__c, Meeting_Type__c, Subject, CreatedBy.FirstName,
                    CreatedBy.LastName, ActivityDate,  Activity_Status__c, Owner.Name,     CreatedDate
                    FROM task
                    WHERE /*CreatedDate >= :queryRange AND*/  Region__c = :region AND Activity_Type__c != 'Email' limit 3] ;
        system.debug('***** there are '+taskList.size()+' tasks.');
        IF(taskList.size() > 0){
            FOR(integer i = 0; i < taskList.size(); i++){
                List<taskRelation> tr = [select relationId from taskRelation where taskId = :taskList[i].Id Order By CreatedDate asc limit 1];
                IF(tr.size() > 0){
                    List<contact> c = [select id, Name, Account.Name from contact where Id = :tr[0].relationId];
                    firm = c[0].Account.Name;
                    name = c[0].Name;
                    cId = c[0].Id;
                }
                If(taskList[i].Priority != 'High'){
                    actList.add(new activityWrapper(taskList[i], firm, name, cId));
                }else{
                    actListImp.add(new activityWrapperImp(taskList[i], firm, name, cId));
                }
            }
            firm = null;
            name = null;
            cId = null;
        }

        eventList = [SELECT Id, Region__c, Description, StartDateTime, Activity_Priority__c, Activity_Type__c, Meeting_Type__c, Subject,
                     CreatedBy.LastName, CreatedBy.firstName, Activity_Status__c, Owner.Name, CreatedDate
                     FROM event
                     WHERE /*CreatedDate >= :queryRange AND */ Region__c = :region  AND Activity_Type__c != 'Email' limit 3] ;
        IF(eventList.size() > 0){
            FOR(integer i = 0; i < eventList.size(); i++){
                List<eventRelation> ev = [select relationId from eventRelation where eventId = :eventList[i].Id Order By CreatedDate asc limit 1];
                IF(ev.size() == 1){
                    List<contact> c = [select id, Name, Account.Name from contact where Id = :ev[0].relationId];
                    firm = c[0].Account.Name;
                    name = c[0].Name;
                    cId = c[0].Id;
                }
                If(eventList[i].Activity_Priority__c != 'High'){
                    actList.add(new activityWrapper(eventList[i], firm, name, cId));
                }else{
                    actListImp.add(new activityWrapperImp(eventList[i], firm, name, cId));
                }
            }
            firm = null;
            name = null;
            cId = null;
        }
        IF(eventList.size() == 0 && taskList.size() == 0){
            EmailHeader ='No activities were logged yesterday in region - '+region;
        }else{
            EmailHeader ='All activities logged yesterday in region - '+region;
        }
    }

    public class activityWrapper{
        public string type{get; set;}
        public string actId {get; set;}
        public string actType {get; set;}
        public string actSubType {get; set;}
        public string actSubject {get; set;}
        public DateTime actDate {get; set;}
        public DateTime actCreatedDate {get; set;}
        public string actOwnerName {get; set;}
        public string actDescription {get; set;}
        public string actStatus {get; set;}
        public string actFirm {get; set;}
        public string contactName{get; set;}
        public Id contactId {get; set;}
        public boolean important = false;

        public activityWrapper(task tsk, string firm, string name, id cId){
            actId = tsk.Id;
            actType = tsk.Activity_Type__c;
            actSubType  = tsk.Meeting_Type__c;
            actSubject = tsk.Subject;
            actDate = tsk.ActivityDate;
            actCreatedDate  = tsk.CreatedDate;
            actOwnerName = tsk.Owner.Name;
            actDescription  = tsk.Description;
            actStatus = tsk.Activity_Status__c;
            contactName = name;
            actFirm = firm;
            contactId = cId;
        }

        public activityWrapper(event evt, string firm, string name, id cID){
            actId = evt.Id;
            actType = evt.Activity_Type__c;
            actSubType  = evt.Meeting_Type__c;
            actSubject = evt.Subject;
            actDate = evt.StartDateTime;
            actCreatedDate  = evt.CreatedDate;
            actOwnerName = evt.Owner.Name;
            actDescription  = evt.Description;
            actStatus = evt.Activity_Status__c;
            contactName = name;
            actFirm = firm;
            contactId = cId;
        }
    }

    public class activityWrapperImp{
        public string type{get; set;}
        public string actId {get; set;}
        public string actType {get; set;}
        public  string actSubType {get; set;}
        public  string actSubject {get; set;}
        public  DateTime actDate {get; set;}
        public  DateTime actCreatedDate {get; set;}
        public  string actOwnerName {get; set;}
        public  string actDescription {get; set;}
        public  string actStatus {get; set;}
        public string actFirm {get; set;}
        public string contactName{get; set;}
        public Id contactId {get; set;}

        public activityWrapperImp(task tsk, string firm, string name, id cId){
            actId = tsk.Id;
            actType = tsk.Activity_Type__c;
            actSubType  = tsk.Meeting_Type__c;
            actSubject = tsk.Subject;
            actDate = tsk.ActivityDate;
            actCreatedDate  = tsk.CreatedDate;
            actOwnerName = tsk.Owner.Name;
            actDescription  = tsk.Description;
            actStatus = tsk.Activity_Status__c;
            contactName = name;
            actFirm = firm;
            contactId = cId;
        }

        public activityWrapperImp(event evt, string firm, string name, id cID){
            actId = evt.Id;
            actType = evt.Activity_Type__c;
            actSubType  = evt.Meeting_Type__c;
            actSubject = evt.Subject;
            actDate = evt.ActivityDate;
            actCreatedDate  = evt.CreatedDate;
            actOwnerName = evt.Owner.Name;
            actDescription  = evt.Description;
            actStatus = evt.Activity_Status__c;
            contactName = name;
            actFirm = firm;
            contactId = cId;
        }
    }

    public List<activityWrapper> getActivityList(){
        system.debug('***** public List');
        return actList;
    }
    public List<activityWrapperImp> getActivityListImp(){
        system.debug('***** public List');
        return actListImp;
    }
}




 

I have a email that is being sent out by a scheduled batch class that I need to pass a Recordc Id paramerter to.  I am using a VF email template with a component and class that generates a table of activities based on information related to the recipients user record.  The batch and email work fine but in order to get the components table to populate correctly I need to pass the user ID to the VF Components controller, and cannot figure out how to do that.  Bleow is a snippet from my controller and accomodating classes.

Controller:

public with sharing class RACnSACEmailClass {

    public List<User> userRecord = new List<User>();
    public Id userId {get; set;}
    public list<Task> taskList {get; set;}
    public list<Event> eventList{get; set;}
    public string emailAdd {get; set;}
    public string region {get; set;}
    public list<activityWrapper> actList {get; set;}
    public list<activityWrapperImp> actListImp {get; set;}
    public string firm;
    public string name;
    public id cId;
    public string emailHeader {get; set;}
    public datetime todaysDate = system.now();
    public string weekDay {get; set;}
    public date queryRange {get; set;}
    Public Id setuserId(ID a){
         userId = a;
         return userId;

         }
    public RACnSACEmailClass() {
        actList = new list<activityWrapper>();
        actListImp = new list<activityWrapperImp>();

        userRecord = [select Id, Region__c from User Where Id = :userId];
        region = userRecord[0].Region__c;
        weekDay = todaysDate.format('EEEE');
        system.debug('***** the date is '+weekDay);
        IF(weekDay != 'Monday'){
            queryRange = todaysDate.Date().addDays(-1) ;
        }else{
            queryRange = todaysDate.Date().addDays(-3);
        }
        taskList = [SELECT Id, Region__c, Description, Priority, Activity_Type__c, Meeting_Type__c, Subject, CreatedBy.FirstName,
                    CreatedBy.LastName, ActivityDate,  Activity_Status__c, Owner.Name,     CreatedDate
                    FROM task
                    WHERE CreatedDate >= :queryRange AND  Region__c = :region AND Activity_Type__c != 'Email'] ;
        system.debug('***** there are '+taskList.size()+' tasks.');
        IF(taskList.size() > 0){

Component

<apex:component access="global" controller="RACnSACEmailClass">
<apex:attribute name="recordId" description="Record Id" type="id" assignTo="{!userId}"/> 
<body>
  <p>
  <apex:outputtext value="{!emailHeader}" style="font-weight:bold; font-size: 14px"/>
</p>
  <table class = "deviceWidth" cellpadding="0" cellspacing="0" border="0" id="backgroundTable">
    <tr>
      <th bgcolor="#E67300" style="font-size:14; font-family:Sans-SerIF; font-weight:bold;text-align:center;width:20%;white-space:nowrap;">
      <font color="#FFFFFE">High Importance Activities</font>
      </th>
    </tr>
    <apex:repeat value="{!actListImp}" var="a">
    <tr valign="center" bgcolor="#DDDDDD" style="font-size:12;font-family:Sans-SerIF;font-weight:bold; width:100%">
      <td>
        <apex:outputLink value="/{!a.contactId}" id="theContactLink">{!a.ContactName}</apex:outputLink><apex:outputText Value=" - {!a.actFirm}"/>
      </td>
    </tr>
    <tr style="font-size:12; font-family:Sans-SerIF; line-height:125%;">
      <td>
        <Div>Activity Date: {!a.actDate}
        <br/>
        <apex:outputLink value="/{!a.actId}" id="theActivityLink">{!a.actSubject}</apex:outputLink><apex:outputText Value=" - {!a.actSubType}"/>
        <br/>Logged By: {!a.actOwnerName}
        <br/>
        <b> Desc:</b>{!a.actDescription}
        </Div>
      </td>
    </tr>
    </apex:repeat>
  </table>
  <br/>
  <table cellpadding="0" cellspacing="0" border="0" id="backgroundTable">
    <tr>
      <th bgcolor="#C8C88C"  style="font-size:14;font-family:Sans-SerIF;font-weight:bold;text-align:center;width:20%;white-space:nowrap;">
      <font color="#FFFFFE">Other Activities</font>
    </th>
    </tr>
    <apex:repeat value="{!actList}" var="a">
    <tr valign="center" bgcolor="#DDDDDD" style="font-size:12;font-family:Sans-SerIF;font-weight:bold; width:100%">
      <td>
        <apex:outputLink value="/{!a.contactId}" id="theContactLink">{!a.ContactName}</apex:outputLink><apex:outputText Value=" - {!a.actFirm}"/>
      </td>
    </tr>
    <tr style="font-size:12; font-family:Sans-SerIF; line-height:125%;">
      <td>
        <Div>Activity Date: {!a.actDate}
        <br/>
        <apex:outputLink value="/{!a.actId}" id="theActivityLink">{!a.actSubject}</apex:outputLink><apex:outputText Value=" - {!a.actSubType}"/>
        <br/>Logged By: {!a.actOwnerName}
        <br/>
        <b> Desc:</b>{!a.actDescription}
        </Div>
      </td>
    </tr>
    </apex:repeat>
  </table>
</body>

</apex:component>

VF Email

<messaging:emailTemplate subject="RAC and SAC Daily Digest [ EXTERNAL ]" recipientType="User" relatedToType="User">
  <messaging:htmlEmailBody >
    <c:RACnSACDigestEmailComponent recordId="{!RelatedTo.ID}" />
  </messaging:htmlEmailBody>
</messaging:emailTemplate>

 

Batch class

global class RACnSACDigestSCRevisionBatch implements Database.Batchable<sObject> {
    
    
    
    String userRegions = 'select id, Region__c, Email from user where Region__c != Null Order by Region__c asc';
    
    global RACnSACDigestSCRevisionBatch() {
        
    }
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator(userRegions);
    }
    
    global void execute(Database.BatchableContext BC, List<User> scope) {
        List<Messaging.SingleEmailMessage> emailList = new list<Messaging.SingleEmailMessage>();
        List<emailTemplate> emailTemplateList =[select id from emailTemplate Where name = 'RACnSACDigestEmail'];
        string templateId = emailTemplateList[0].Id;
        List<string> emailAddress = new list<string>();
        emailAddress.add('aaldis@ofiglobal.com');
        system.debug('***** scope size is '+scope.size());
        for(User u: scope){
            Id userID = u.Id;
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setToAddresses(emailAddress);
            email.setTargetObjectId(userId);
            email.setWhatId(userId);
            email.setTemplateId(templateId);
            email.setSaveAsActivity(false);
            email.setTreatTargetObjectAsRecipient(false);
            system.debug('***** scope size is '+email);
            emailList.add(email);
            //Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        }
        system.debug('***** email list size is '+emailList.size());
        Messaging.sendEmail(emailList);
        
    }
    
    global void finish(Database.BatchableContext BC) {
        
    }
    
    
}

I have a visualforce page which is embedded in a standard page layout for tasks that seems to be working fine but for 1 user whenever they save the page refreshes the entire window and only shows the visualforce page.  The user is using IE.

Here is my code below.

PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());

    public pageReference saveContacts(){
     List<eventRelation> addeventRelation = new List<eventRelation>();
     for(cContacts c: getTeamMember()){
         IF(Test.isRunningTest()){
            c.selectBox =  true;
            c.participated = false;
        }     
        IF(c.selectBox ==  true && c.participated == false){
            eventRelation ev = new eventRelation();
            ev.RelationId =  c.cId;
            ev.eventId =  eId;
            addeventRelation.add(ev);
     }
    }
    insert addeventRelation;
    pageRef.setRedirect(true);
    return pageRef;

    }

 
I wrote several batch classes to update fields on tasks and events with information with several custom objects.  Originally I wrote the classes to only update those tasks and events which were not archived, but recently the decision was made to update all tasks and events including archived tasks and events.  My original query to update the tasks and events was simple 'Select ID from Event'  which pulled all non archived events, can I rewrite my query to 'select Id from Evetn where is Archived = true or isArchived = false to pull both types?  An example of one of the batch classes is below.

global class ActivitySidecarRefactorEventCampaign implements Database.Batchable<sObject> {

     global Id primaryCampaign {get; set;}
     global Id campaign2 {get; set;}
     global Id campaign3 {get; set;}
     global Id campaign4 {get; set;}
     global Id campaign5 {get; set;}
     global string activityId {get; set;}
     global Id eventId {get; set;}
     Global Boolean insertList {get; set;}
      global Boolean activityRelation = false;
     global String query = 'select Id from Event Where IsArchived = true or IsArchived = false';

        global Database.QueryLocator start(Database.BatchableContext BC) {
            return Database.getQueryLocator(query);
        }

           global void execute(Database.BatchableContext BC, List<event> scope) {
                System.Debug('!! Batch size for event '+scope.size());
                    List<event> eventList = New List<event>();
                    List<Activity_Relation__c> activityRelationList =  New List<Activity_Relation__c>();
                    for(event t: Scope){
                    List<Activity_Campaign__c> activityCampaign = [Select Campaign__c, Activity_Id__c, Activity_Sidecar__r.Primary_Campaign__c
                                                                                                                From Activity_Campaign__c
                                                                                                                Where Activity_Sidecar__r.Is_Task__c = false AND Activity_Id__c = :t.Id order by createdDate asc Limit 6];
                    System.debug('$$ activityCampaign is '+activityCampaign.size());
                    IF(activityCampaign.Size() > 0){
              insertList = true;
                        eventId = activityCampaign[0].Activity_Id__c;
                        activityId = activityCampaign[0].Activity_Id__c;
                        IF(activityCampaign[0].Activity_Sidecar__r.Primary_Campaign__c == Null){
                            primaryCampaign = activityCampaign[0].Campaign__c;
                                IF(activityCampaign.Size() > 1){
                                    activityRelation = true;
                                    campaign2 = activityCampaign[1].Campaign__c;}
                                    IF(activityCampaign.Size() > 2){campaign3 = activityCampaign[2].Campaign__c;}
                                            IF(activityCampaign.Size() > 3){campaign4 = activityCampaign[3].Campaign__c;}
                                                    IF(activityCampaign.Size() > 4){campaign5 = activityCampaign[4].Campaign__c;}
                      }else{
                primaryCampaign = activityCampaign[0].Activity_Sidecar__r.Primary_Campaign__c;
                            IF(activityCampaign.Size() > 1){
                                    activityRelation = true;
                                    campaign2 = activityCampaign[0].Campaign__c;}
                                IF(activityCampaign.Size() > 2){campaign3 = activityCampaign[1].Campaign__c;}
                                        IF(activityCampaign.Size() > 3){campaign4 = activityCampaign[2].Campaign__c;}
                                                IF(activityCampaign.Size() > 4){campaign5 = activityCampaign[3].Campaign__c;}
                    }
                    System.Debug('@@ Activity Campaign fields are '+primaryCampaign+' '+campaign2+' '+ campaign3+' '+ campaign4+' '+ campaign5);
                    IF(insertList == true){
              event ev = new event();
                      ev.Id = eventId;
                      ev.Primary_Campaign__c = primaryCampaign;
                      eventList.add(ev);
              System.debug(eventList);
                IF(activityRelation == True){
                        Activity_Relation__c ar = new Activity_Relation__c();
                        ar.Activity_Id__c = eventId;
                      ar.Campaign_2__c = campaign2;
                      ar.Campaign_3__c = campaign3;
                      ar.Campaign_4__c = campaign4;
                      ar.Campaign_5__c = campaign5;
                      activityRelationList.add(ar);
              system.debug(activityRelationList);}
          }
                }
                }
                System.debug('## event List size is '+eventList.size());
                System.debug('## activity relation List size is '+activityRelationList.size());
                try {
            system.debug('$$ Inserting Activity Relations record - try statement');
                    insert activityRelationList;
            System.debug('$$ updating event list - try statement');
            update eventList;
                } Catch(DmlException d){
                    system.debug('^^ DML Exception is '+d.getMessage());
                for (Integer i = 0; i < d.getNumDml(); i++) {
           System.debug('^^ DML Exception Message is '+d.getDmlMessage(i));
               System.debug('^^ DML Exception row is '+d.getDmlIndex(i));
                 System.debug('^^ DML Exception Id is '+d.getDmlId(i));
                 System.debug('^^ DML Exception Index is '+d.getDmlIndex(i));
                 System.debug('^^ DML Excetion Field name is '+d.getDmlFieldNames(i));
                 System.debug('^^ DML Exception Id is '+d.getDmlFields(i));
                 System.debug('^^ DML Exception status is '+d.getDmlStatusCode(i));
                 System.debug('^^ DML Excetion type is '+d.getDmlType(i));
         }
                } finally {
            System.Debug('&& updating event list - finally statement');
            Database.update(eventList, false);
            system.debug('&& updating activity relatiion list - finally statement');
                Database.insert(activityRelationList, false);


                }{

                }
        }

        global void finish(Database.BatchableContext BC) {
        AsyncApexJob a = [Select Id, Status, ExtendedStatus, NumberOfErrors, JobItemsProcessed, ApexClassId, CompletedDate, TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =:BC.getJobId()];
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresses = new String[] {'aaldis@test.com'};
                mail.setToAddresses(toAddresses);
                mail.setSubject('Batch ActivitySidecareRefactorCampaign '+a.ApexClassId+' is ' + a.Status);
                mail.setPlainTextBody('Batch ActivitySidecareRefactorCampaign '+a.ApexClassId+' is ' + a.Status+' at '+a.CompletedDate+'.  There were '+ a.TotalJobItems +' records processed with '+ a.NumberOfErrors + ' failures.');
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                            Database.executeBatch(new ActivitySidecarRefactorTaskProdUpdate(), 32);




        }
 
I am writing a test class and am having trouble getting a mthod to test correctly.  The method looks at a couple of parameters and I am not sure how to pass the parameters to the method through my test class.  Can anyone help me?

I need to pass the SelectBox = True and the Participated = false paramerters to this method.  
    public pageReference saveContacts(){
     List<eventRelation> addeventRelation = new List<eventRelation>();
     for(cContacts c: getTeamMember()){
        IF(c.selectBox ==  true && c.participated == false){
            eventRelation ev = new eventRelation();
            ev.RelationId =  c.cId;
            ev.eventId =  eId;
            addeventRelation.add(ev);
     }
    }
    insert addeventRelation;
    pageRef.setRedirect(true);
    return pageRef;
    }
My test method.
 PageReference page = new PageReference('/apex/EventTeamMemberSelection?scontrolCaching=1&id=' + testEvent.Id);
        Test.setCurrentPage(page);
        Test.StartTest();
        ApexPages.StandardController stdCont = new ApexPages.StandardController(testEvent);
        EventTeamMemberSelection extCont = new EventTeamMemberSelection(stdCont); 
        pageReference addCon = extCont.saveContacts();
        pageReference delCon = extCont.deleteContacts();
        Test.StopTest();
I need to query a set of records but every time I try I get an error message "Illegal assignment from List to Set".
      {Public <Team_Contact__c>   contacts = [Select Contact__c, Contact__r.Name, Contact__r.Account.Name, Contact__r.Branch_Id__c, Contact__r.MailingAddress, Contact__r.Type__c, Contact__r.Focus_List_Member__c  from  Team_Contact__c where Team__c = :primaryTeam  or  Team__c = :team2 or Team__c = :team3 or Team__c = :team4 or Team__c = :team5 ];
I am trying to write a class to create a combined list of events and tasks in descending order of created dates.  I need to limit the list to the last 50 records.  I am using a for loop to compare the created dates of tasks and events then trying to assign the record the wrapper class to get the correct order.  When I try to assign the task or activity I get an error that states. "undefinedConstructor not defined: [CTRL_MCContacActivities.activityWrapper].(Event)undefined" and  "undefinedConstructor not defined: [CTRL_MCContacActivities.activityWrapper].(Task)undefined".  I have found mulitple examples and have not been able to find out what is wrong.  My code is below.

public with sharing class CTRL_MCContactActivities {

    private Contact theContact;
    public Map<String, String> params {get;set;}
    public Integer getRetailActivitesCount {get;set;}
    public String conId;
    public List<Activity_Contact__c> activities {set;get;}
    Public List<Task> taskList {get; set;}
    Public List<Event> eventList {get; set;}
    Public integer tc = 0;
    Public integer ec = 0;
    public List<activityWrapper> activityList {get; set;}

    public CTRL_MCContactActivities(ApexPages.StandardController controller) {
        theContact = (Contact) controller.getRecord();
        If (theContact != null) {
          activityList = new List<activityWrapper>();
          taskList = [SELECT Id, Activity_Type__c, CreatedDate, Meeting_Type__c, Subject, ActivityDate, Description, Activity_Status__c, Owner.Name
                      FROM task
                      WHERE Id IN (Select taskId from taskRelation where Relationid = :theContact.Id) order by CreatedDate DESC] ;
          eventList = [SELECT Id, Activity_Type__c, CreatedDate, Meeting_Type__c, Subject, ActivityDate, Description,Activity_Status__c, Owner.Name
                      FROM event
                      WHERE Id IN (Select eventId from eventRelation where Relationid = :theContact.Id) order by CreatedDate DESC] ;
          IF(taskList.size() > 0 && eventList.size() > 0){
            FOR(integer i = 0; i < 50; i++){
              system.debug(i+' ***** task CreatedDate '+taskList[tc].CreatedDate+' event CreatedDate '+eventList[ec].CreatedDate);
              IF(taskList[tc].CreatedDate  > eventList[ec].CreatedDate){
                activityList.add(new activityWrapper(taskList[tc]));
                tc++;
              }else{
                activityList.add(new activityWrapper(eventList[ec]));
                ec++;
              }
            }

    }
  }
//Wrapper Class
    public class activityWrapper{
Task t {get; set;}
Event e {get; set;}

      }


  
I am trying to write a wrapper class so I can create a combined lists of tasks and events, I have found several examples and documents that say to define a new public list, but whenever I try to add the list (below in bold).  I get the following error: Invalid type: accountWrapper.  Every example I see looks like they are doing the exact same thing so why do I get the error?

public with sharing class CTRL_MCContactActivities {
    private Contact theContact;
    public Map<String, String> params {get;set;}
    public Integer getRetailActivitesCount {get;set;}
    public String conId;
    public List<Activity_Contact__c> activities {set;get;}
    public List<accountWrapper> display_list {get; set;}
    Public List<Task> taskList {get; set;}
    Public List<Event> eventList {get; set;}
    Public integer tC = 0;
    Public integer eC = 0;
    public string activityId {get; set;}
    public string activityType {get; set;}
    public string createdDate {get; set;}
    public string meetingType {get; set;}
    public string subject {get; set;}
    public string activityDate {get; set;}
    public string description {get; set;}
    public string activityStatus {get; set;}
    public string ownerName {get; set;}

    public CTRL_MCContactActivities(ApexPages.StandardController controller) {
        theContact = (Contact) controller.getRecord();
        If (theContact != null) {
            activities = [SELECT Contact__c, Activity_Type__c, Activity_Subtype__c, Subject__c, Due_Date__c,
                                 Short_Description__c, Activity_Status__c, Assigned_To__c
                         FROM Activity_Contact__c
                         WHERE Contact__c = :theContact.Id
                         ORDER BY Due_Date__c DESC
                         LIMIT 50];
        } else {
            activities = new List<Activity_Contact__c>();
      }
    }
  //  remove this comment }

    public class activityWapper{
      
    }
    public Integer getRetailActivitesCount() {
           return  [SELECT count() FROM Task WHERE Id in (Select taskId from taskRelation where Relationid = :conId)  AND (RecordTypeId = '0126000000018NT' OR RecordTypeId = '0126000000018NU')];
    }






}
 
I am looking for a way to to add Look up Ids from a query to a set without using a for loop.  I am essentially looking for the most efficient way to write the code below.  I have found techniques using keyset() but that only pulls in the Id of the task relation object.

set<Id> retActivityIdList = new Set<Id>();
List<taskRelation> taskRelationList = [SELECT TaskId FROM taskRelation WHERE relationId = :contId ORDER BY CreatedDate DESC ];
        IF(!taskRelationList.isEmpty()){
          for(taskRelation tr: taskRelationList){
            retActivityIdList.add(tr.TaskId);
          }
        }
If we switch to tasks and events with multiple contacts will the who Id still be relevent or will the primary contacts only be in the task.event relation tables?
I need to run several apex batches that will update non-archived Tasks and Events with some additional information.  I have a total of 16 apex classes that I need to run, and I am looking for some advice to figure out the best way to run them.  9 classes that I am going to run first but do not need to run in a specific order, but the other 7 have to be run in sequence after the completion of the first 9 classes. 

What is the best way to acheive this will I have to do it manually and monitor the results or can I write something?
Can I run all 9 of my beginning classes simultainously event though they will all update tasks and events?
Is there a way to write a class to run the remaining classes in sequence?  

 
I am writing a batch apex class to insert Task Relations,  The class is basically going to query a custom object that we used to add multiple contacts to a class.  The custom object is not actually related to the task itself but does have a text field that was updated with the Record Id from the original task.  Now that SF allows users to add multiple contacts to a task we want to correct our data and add the contacts to the task.  My question is how will that work with the 50 contact limit for the multiple contacts.  There may or may not be instances where there are more than 50 contacts related to a task in our custom object.  Our plan is to only create the taskRelation records for the first 50 entered and we are not going to worry about the rest.  If the class runs into the 50 record limit while creating the taskRelation records what will happen will the entire batch fail and roll back, or will 50 taskRelation records be created and the records that went over fail?

my class is below.


    global DataBase.QueryLocator start(Database.BatchableContext BC) {
        string contactQuery = 'Select Activity_Id__c, Contact__c From Custom_Activity_Contact__c';
        return Database.getQueryLocator(contactQuery);
    }

       global void execute(Database.BatchableContext BC, List<task> taskList) {
     List<TaskRelation> taskRelationList = new List<TaskRelation>();
            TaskRelation tr = new TaskRelation();
            Tr.TaskId = Custom_Activity_Contact__c.Activity_Id__c;
            Tr.RelationId = Custom_Activity_Contact__c.Contact__c;
            Tr.IsWhat = False;
            taskRelationList.add(tr);

            }
                insert taskRelationList;
            }
    
    }
    
    global void finish(Database.BatchableContext BC) {
        AsyncApexJob job = [SELECT Id, Status, NumberOfErrors, 
            JobItemsProcessed,
            TotalJobItems, CreatedBy.Email
            FROM AsyncApexJob
            WHERE Id = :bc.getJobId()];
        EmailUtils.sendMessage(a, recordsProcessed);

    }
I need to write an apex class to do a batch update on activities.  My question is do I need to query Tasks and Events seperately in my class like I would if were using the workbench or can I query all the activites together?  If so how.  I will be writing a batch class to update basically all of our open and closed actvities to update some new lookup fields we recently added.
I have a customer button on a custom object that is set up to send an email when it is clicked.  I would like to also have it update a date field on the object when it is clicked so users can see if when the email was sent.  The button is set to URL and Open in a new window.  The URL is below.  Is this possible and how can it be done?


https://login.salesforce.com/_ui/core/email/author/EmailAuthor?rtype=003&p3_lkid={!Client_Workbook__c.Id}&retURL=%2F{!Client_Workbook__c.Id}&p5={!$User.Email}&template_id=00X3400000204Mw&p24={!Client_Workbook__c.Engangement_Manager_Email__c}
I am looking for a little help I am pretty much brand new to VF and other than training I have never actually done anything functional in it.  I am trying to create a form from a custom object but keep getting the error Coul not resolvve the entity from <apex:inputField> value binding '{!Initial_Investment_Costs__c}", <apex:inputField> can only be sused with SObjects, or objects that are Visualforce field component resolvable.  But I cannot figure out what is the problem.  My VF page is below.

<apex:page standardController="CapEx_OpEx_Initial_Investment_Costs__c">
    <apex:form>
        <apex:pageBlock title="Add Initial Investment Costs">
            <apex:inputField value="{! Initial_Investment_Costs__c}"/>
            <apex:inputField value="{! If_Other_Please_Specify__c}"/>
            <apex:inputField value="{! Year_0__c}"/>
            <apex:inputField value="{! Year_1__c}"/>
            <apex:inputField value="{! Year_2__c}"/>
            <apex:inputField value="{! Year_3__c}"/>
            <apex:inputField value="{! Additional_Notes__c}"/>
             
            <apex:pageBlockButtons>
                <apex:commandButton action="{! save }" value="Save" />  
                <apex:commandButton action="{! save&New }" value="Save & New" />   
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Hi all,

I am brand new to Salesforce but have some HTML, JQuery, CSS, and Java experience so I am able to figure somethings out.  I am trying to create a visual force page to a cutom object I created called recipes.  Every time I try to enter it using the following tag <apex:page standardController="Recipe"/>  I get an error message telling me it does not know what Recipe is.  Although there may be some problems with my tag in this post please ignore it my tag is right on the visual force editor.  Is there another contoller or Apex code I should use?
I am writing a test class and am having trouble getting a mthod to test correctly.  The method looks at a couple of parameters and I am not sure how to pass the parameters to the method through my test class.  Can anyone help me?

I need to pass the SelectBox = True and the Participated = false paramerters to this method.  
    public pageReference saveContacts(){
     List<eventRelation> addeventRelation = new List<eventRelation>();
     for(cContacts c: getTeamMember()){
        IF(c.selectBox ==  true && c.participated == false){
            eventRelation ev = new eventRelation();
            ev.RelationId =  c.cId;
            ev.eventId =  eId;
            addeventRelation.add(ev);
     }
    }
    insert addeventRelation;
    pageRef.setRedirect(true);
    return pageRef;
    }
My test method.
 PageReference page = new PageReference('/apex/EventTeamMemberSelection?scontrolCaching=1&id=' + testEvent.Id);
        Test.setCurrentPage(page);
        Test.StartTest();
        ApexPages.StandardController stdCont = new ApexPages.StandardController(testEvent);
        EventTeamMemberSelection extCont = new EventTeamMemberSelection(stdCont); 
        pageReference addCon = extCont.saveContacts();
        pageReference delCon = extCont.deleteContacts();
        Test.StopTest();
I need to query a set of records but every time I try I get an error message "Illegal assignment from List to Set".
      {Public <Team_Contact__c>   contacts = [Select Contact__c, Contact__r.Name, Contact__r.Account.Name, Contact__r.Branch_Id__c, Contact__r.MailingAddress, Contact__r.Type__c, Contact__r.Focus_List_Member__c  from  Team_Contact__c where Team__c = :primaryTeam  or  Team__c = :team2 or Team__c = :team3 or Team__c = :team4 or Team__c = :team5 ];
I am trying to write a class to create a combined list of events and tasks in descending order of created dates.  I need to limit the list to the last 50 records.  I am using a for loop to compare the created dates of tasks and events then trying to assign the record the wrapper class to get the correct order.  When I try to assign the task or activity I get an error that states. "undefinedConstructor not defined: [CTRL_MCContacActivities.activityWrapper].(Event)undefined" and  "undefinedConstructor not defined: [CTRL_MCContacActivities.activityWrapper].(Task)undefined".  I have found mulitple examples and have not been able to find out what is wrong.  My code is below.

public with sharing class CTRL_MCContactActivities {

    private Contact theContact;
    public Map<String, String> params {get;set;}
    public Integer getRetailActivitesCount {get;set;}
    public String conId;
    public List<Activity_Contact__c> activities {set;get;}
    Public List<Task> taskList {get; set;}
    Public List<Event> eventList {get; set;}
    Public integer tc = 0;
    Public integer ec = 0;
    public List<activityWrapper> activityList {get; set;}

    public CTRL_MCContactActivities(ApexPages.StandardController controller) {
        theContact = (Contact) controller.getRecord();
        If (theContact != null) {
          activityList = new List<activityWrapper>();
          taskList = [SELECT Id, Activity_Type__c, CreatedDate, Meeting_Type__c, Subject, ActivityDate, Description, Activity_Status__c, Owner.Name
                      FROM task
                      WHERE Id IN (Select taskId from taskRelation where Relationid = :theContact.Id) order by CreatedDate DESC] ;
          eventList = [SELECT Id, Activity_Type__c, CreatedDate, Meeting_Type__c, Subject, ActivityDate, Description,Activity_Status__c, Owner.Name
                      FROM event
                      WHERE Id IN (Select eventId from eventRelation where Relationid = :theContact.Id) order by CreatedDate DESC] ;
          IF(taskList.size() > 0 && eventList.size() > 0){
            FOR(integer i = 0; i < 50; i++){
              system.debug(i+' ***** task CreatedDate '+taskList[tc].CreatedDate+' event CreatedDate '+eventList[ec].CreatedDate);
              IF(taskList[tc].CreatedDate  > eventList[ec].CreatedDate){
                activityList.add(new activityWrapper(taskList[tc]));
                tc++;
              }else{
                activityList.add(new activityWrapper(eventList[ec]));
                ec++;
              }
            }

    }
  }
//Wrapper Class
    public class activityWrapper{
Task t {get; set;}
Event e {get; set;}

      }


  
I am trying to write a wrapper class so I can create a combined lists of tasks and events, I have found several examples and documents that say to define a new public list, but whenever I try to add the list (below in bold).  I get the following error: Invalid type: accountWrapper.  Every example I see looks like they are doing the exact same thing so why do I get the error?

public with sharing class CTRL_MCContactActivities {
    private Contact theContact;
    public Map<String, String> params {get;set;}
    public Integer getRetailActivitesCount {get;set;}
    public String conId;
    public List<Activity_Contact__c> activities {set;get;}
    public List<accountWrapper> display_list {get; set;}
    Public List<Task> taskList {get; set;}
    Public List<Event> eventList {get; set;}
    Public integer tC = 0;
    Public integer eC = 0;
    public string activityId {get; set;}
    public string activityType {get; set;}
    public string createdDate {get; set;}
    public string meetingType {get; set;}
    public string subject {get; set;}
    public string activityDate {get; set;}
    public string description {get; set;}
    public string activityStatus {get; set;}
    public string ownerName {get; set;}

    public CTRL_MCContactActivities(ApexPages.StandardController controller) {
        theContact = (Contact) controller.getRecord();
        If (theContact != null) {
            activities = [SELECT Contact__c, Activity_Type__c, Activity_Subtype__c, Subject__c, Due_Date__c,
                                 Short_Description__c, Activity_Status__c, Assigned_To__c
                         FROM Activity_Contact__c
                         WHERE Contact__c = :theContact.Id
                         ORDER BY Due_Date__c DESC
                         LIMIT 50];
        } else {
            activities = new List<Activity_Contact__c>();
      }
    }
  //  remove this comment }

    public class activityWapper{
      
    }
    public Integer getRetailActivitesCount() {
           return  [SELECT count() FROM Task WHERE Id in (Select taskId from taskRelation where Relationid = :conId)  AND (RecordTypeId = '0126000000018NT' OR RecordTypeId = '0126000000018NU')];
    }






}
 
I am looking for a little help I am pretty much brand new to VF and other than training I have never actually done anything functional in it.  I am trying to create a form from a custom object but keep getting the error Coul not resolvve the entity from <apex:inputField> value binding '{!Initial_Investment_Costs__c}", <apex:inputField> can only be sused with SObjects, or objects that are Visualforce field component resolvable.  But I cannot figure out what is the problem.  My VF page is below.

<apex:page standardController="CapEx_OpEx_Initial_Investment_Costs__c">
    <apex:form>
        <apex:pageBlock title="Add Initial Investment Costs">
            <apex:inputField value="{! Initial_Investment_Costs__c}"/>
            <apex:inputField value="{! If_Other_Please_Specify__c}"/>
            <apex:inputField value="{! Year_0__c}"/>
            <apex:inputField value="{! Year_1__c}"/>
            <apex:inputField value="{! Year_2__c}"/>
            <apex:inputField value="{! Year_3__c}"/>
            <apex:inputField value="{! Additional_Notes__c}"/>
             
            <apex:pageBlockButtons>
                <apex:commandButton action="{! save }" value="Save" />  
                <apex:commandButton action="{! save&New }" value="Save & New" />   
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>