• Eric Anderson 54
  • NEWBIE
  • 100 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 26
    Questions
  • 20
    Replies
Hi there,

I have a custom (parent) object that has two child objects related to it. I have also allowed (Notes &) 'Attachements' to be enabled for the (parent) custom object. One of the Child objects tracks 'Time' invovled in the particular entry in the (Parent) custom object. The other child object tracks 'Suspects' who are involved in a particular entry of the (Parent) custom object.The user has requested that when a 'Suspect' is entered into child object which are related to the parent object, that a entry be made into the 'Time' child object. Similarly, they have requested that whenever an 'Attachment' is added to the (Parent) custom object, that  another entry be made into the 'Time' child object.

I've tried both the 'Before Insert' and 'After Insert' type of trigger for the Attachments, and neither one seems to execute.
 
trigger Attachement_After_Add_Del on Attachment (before insert) {
    List<Request_Time_Entry__c> entryList = new List<Request_Time_Entry__c>();
    for(Attachment AttachmentObj : Trigger.new){
    system.debug('The Attachment Trigger fired.');
    Request_Time_Entry__c entry = new Request_Time_Entry__c();
      entry.Hours_Worked__c = '0';
      entry.Minutes_Worked__c = '15';
      string ParentID = AttachmentObj.parentId;
      entry.Work_Description__c = 'Added Suspect';
      entry.Name = ParentID.substring(0, 15);
      entry.Date_Worked__C = system.Today();
      entry.Related_Object__c = ParentID.substring(0, 15);
      entryList.add(entry);
     }
     if(entryList.size()>0){
      insert entryList;
     }
}


trigger Suspect_After_Add on Suspect__c (after insert) {
    List<Request_Time_Entry__c> entryList = new List<Request_Time_Entry__c>();
    for(Suspect__c SuspectObj : Trigger.new){
    system.debug('The Suspect Trigger fired.');
    Request_Time_Entry__c entry = new Request_Time_Entry__c();
      entry.Hours_Worked__c = '0';
      entry.Minutes_Worked__c = '15';
      string ParentID = SuspectObj.Investigation__c;
      entry.Work_Description__c = 'Added Suspect';
      entry.Name = ParentID.substring(0, 15);
      entry.Date_Worked__C = system.Today();
      entry.Related_Object__c = ParentID.substring(0, 15);
      entryList.add(entry);
     }
     if(entryList.size()>0){
      insert entryList;
     }
}



My 'Suspects' trigger works just fine. I have a 'System.debug' statement in it and it is showing up in my log just fine, including the entry being made in the 'Time' Child object.

My Attachment trigger does not work as best I can tell. There is no entry in the 'Time' Child object, and there is no entry in the Logs either. 

Does anyone have any insight for me on what the problem might be? Is there some obscure setting somewhere that I need to look for that will allow 'Attachments' of Custom objects to fire triggers?

I'd welcome any input I can get on this subject.

Thanks!

Eric Anderson
 
Hi there I have a custom parent object that has a child object. I also allow on the Parent object 'Notes and Attachments' (Notes & Upload files). We need to have a trigger on the 'Attachements' that will fire a trigger that will create an entry on the Child object of the parent. I don't know what needs to be done (if anything) to have the Child object know the id of the parent object. I presume I need to include the Parent ID when I create the entry in the Child object.

Below is the code I have been experimenting with, but I have not been able to get it to work.
 
trigger Attachement_After_Add_Del on Attachment (after insert) {
    List<Request_Time_Entry__c> entryList = new List<Request_Time_Entry__c>();
    for(Attachment AttachmentObj : Trigger.new){
    Request_Time_Entry__c entry = new Request_Time_Entry__c();
      entry.Hours_Worked__c = '00';
      entry.Minutes_Worked__c = '15';
      entry.NAME = 'Added Attachment';
      entry.Date_Worked__C = system.Today();
      // I don't know if what I need in the following line is correct. I Don't seem to get any
      // entries created on the child object when I run this code. Or, am I using the wrong 
     // form of 'Trigger' for an 'Attachement'. 
      entry.Related_Object__c = AttachmentObj.ParentId;
      entryList.add(entry);
     }
     if(entryList.size()>0){
      insert entryList;
     }
}
Any assistance would be greatly appreciated.

Thanks!

Eric Anderson
Hi there,

I have a parent custom object called 'Investigations' which is used for tracking criminal investigations. I have a child object for that parent called 'Time Entry Recap Report' which is used to record when time is put towards an investigation. As part of the 'Investigations' parent object, I have placed the 'Notes and Attachements' list object to the parent object. The user wants an automatic time entry made to the 'Time Entry Recap Report' child object, when ever an 'attachement' is added to the parent object. Basically, the user is trying to reduce rudimentary work that is done the same way every time.  I am trying to figure out how to develop a 'Trigger' that is based on the 'Attachement' process so that does not seem to be placing records in the 'Time reporting' object. Any suggestions on how to fix my code would be greatly appreciated.
 
trigger Attachement_After_Add_Del on Attachment (after insert) {
    List<Time_Entry_Recap_Report__c> entryList = new List<Time_Entry_Recap_Report__c>();
    for(Attachment AttachmentObj : Trigger.new){
    Time_Entry_Recap_Report__c entry = new Time_Entry_Recap_Report__c();
      entry.Hours_Worked__c = '00';
      entry.Minutes_Worked__c = '15';
      entry.NAME = 'Added Attachment';
      entry.Date_Worked__C = system.Today();
     //I've tried several incarnations at the following line of code, and I just can't figure out
     //what it will take to get it to work.       
      entry.Investigation_Time_Entry__c = AttachmentObj.ParentId;
      entryList.add(entry);
     }
     if(entryList.size()>0){
      insert entryList;
     }
}



Thank you very much for your time!

Respectfully,

Eric Anderson
Hi there,

I have two custom objects. The Investigation__c is the parent object, and the Time_Entry_Recap_Report__c is the child object. What I want to have happen is when the parent record (Investigation) is initially created, I want to create an initial entry in the 'Time_Entry_Recap_Report__c' with 15 minutes of time worked and a description of the task being 'Opened new investigation'. I'm trying to figure out how to relate the Child record to the parent record when I create the entry in the trigger. The object 'Time_Entry_Recap_Report__c' is already defined as a child to the parent, but trying to insert the record without a reference to the 'Investigation_Time_Entry__c' field within the 'Time_Entry_Recap_Report__c' object didn't work either. The Error I am getting is "Error: Compile Error: Illegal assignment from Schema.SObjectField to Id at line 8 column 7. Any assistance would be greatly appreicated. 
trigger CreateTimeEntry on Investigation__c (after insert) {
    List<Time_Entry_Recap_Report__c> entryList = new List<Time_Entry_Recap_Report__c>();
    for(Investigation__c InvestigationObj : Trigger.new){
    Time_Entry_Recap_Report__c entry = new Time_Entry_Recap_Report__c();
      entry.Hours_Worked__c = '00';
      entry.Minutes_Worked__c = '15';
      entry.Work_Performed__c = 'Opened new investigation';
      entry.Investigation_Time_Entry__c = Investigation__c.NAME;
      entryList.add(entry);
     }
     if(entryList.size()>0){
      upsert entryList;
     }
}

 
Hi there,

We have an App that is a 'Investigation' Custom object. Within that custom object, I have one or more witnesses as 'Child custom' objects. Because the 'Save' in the default entry form (Salesforce out of the box) for the child object does not take us back to the 'Parent custom object' the way the user wants it too, we used a 'URL Hack'. We got chastised for this and told we should use a VisualForce page. I'm fairly green when it comes to VisualForce development, so I could use all of the help that I can get. In a 'Master-Detail' related lists, I'm trying to create a data entry form using VisualForce. I've entered most of the mark up in the VF page and my code looks like the following:
 
<apex:page standardController="Witness__c">
<apex:form id="Witness_Entry_Form">
    <apex:pageBlock title="Create Witness">

    <apex:pageBlockSection columns="1">  
    <apex:inputField value="{!Witness__c.Name}"/>      
    <apex:inputField value="{!Witness__c.CDC_Number__c}"/>
    <apex:inputField value="{!Witness__c.CDC_Offender__c}"/>
    <apex:inputField value="{!Witness__c.Eye_Color__c}"/>
    <apex:inputField value="{!Witness__c.First_Name__c}"/>
    <apex:inputField value="{!Witness__c.Hair_Color__c}"/>
    <apex:inputField value="{!Witness__c.Last_Name__c}"/>
    <apex:inputField value="{!Witness__c.Request_Witness__c}"/>
    </apex:pageBlockSection>

    <apex:pageBlockButtons >
      <apex:commandButton action="{!save}" value="Save"/>
    </apex:pageBlockButtons>

</apex:pageBlock>
        
</apex:form>
</apex:page>

However, when I try to create a button within the Witness object with a display type of 'List button', and then select 'VisualForce' for the Content source, my VisualForce page is not listed in the 'Content' drop down box and as a result I get a 'You must enter a value' error.

I would sincerely appreicate any help I can get in regards to this.

Thanks!

Eric 
Hi there everyone,

We have a parent custom object related to a Child object. The default behavior on 'Save' or 'Cancel' out of Child entry object, doesn't take us to the parent object by default the way we think it should. So, we added a 'SaveURL' and 'CancelURL' values to take us back to the parent object. It is our understanding from 'Support' that this is concidered a 'URL Hack'. Their recommended solution is that we "... impliment a VisualForce button instead of a 'URL Hack' on a link button so that substitutional parameters can be passed correctly." We asked them for an example and they so far have not been able to provide us with an example. We aren't quite sure what we should do with a 'VisualForce' button. The natural 'Extension' of our logic based on this comment from support is that we should then process the 'Child object' using a 'VisualForce' page instead of the default Child object that is presented by default by the Salesforce UI. 

The challenge that caused us to contact Support originally was the fact that the object ID's change when you move an APP from Development to Testing and then to production. We had a typo in our 'URL Hack' that was causing it not to work. We eventually figured out the problem with our 'URL Hack', but we are trying to pursue 'Best Practices'. We don't want to use 'URL Hacks' if they are not going to be supported (and maybe removed completely from the product). However, we can't afford the resources to put a lot of extra effort into developing VisualForce and Apex code to get around an issue that frankly we feel is a short coming in the software. (We think 'Cancel' or 'Save' should take you back to the parent object by default).

We would appreciate any meaningful input anyone can provide to get to this best practice.

Thanks!

- Eric -  
Hi there everyone,

I'm new to Salesforce and Visualforce development. Though I have been doing C# for years in the Windows environment, my experience in web development is pretty limited. I am trying to build a solution where there are two picklists. The first pick list (OCS Units) is based on a 'Global pick list'. The second pick list should be loaded based on the value picked in the first pick list. When I run my code, it doesn't look like even the first pick list is being populated because when I click on the 'drop down' arrow, nothing is displayed.

Below is my Visualforce code:
 
<apex:page controller="OCSPicklistLoader">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection columns="2">
            	<apex:pageBlockSectionItem>
                    <apex:outputLabel value="OCS Unit"/>
                </apex:pageBlockSectionItem>
            	<apex:pageBlockSectionItem>
                    <apex:selectList size="1" value="{!OCS_Unit}">
                    	<apex:selectOptions value="{!OCS_Unit}"/>
                    	<apex:actionSupport event="onchange" reRender="Offices"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem>
                    <apex:outputLabel value="OCS Office"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem>
                    <apex:selectList size="1" value="{!OCS_Office}" id="Offices">
                    	<apex:selectOptions value="{!OCS_Office}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>    
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Below is my Controller code:
public class OCSPicklistLoader {
    public string OCS_Unit {get;set;}
    public string OCS_Office {get;set;}
    public List<OCS_Office__c> OCSOffices;
     
    public List<SelectOption> OCS_Unit()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('A','None'));
        options.add(new SelectOption('B','FAT'));
        options.add(new SelectOption('C','SSU'));
        options.add(new SelectOption('D','EOU'));
        options.add(new SelectOption('E','EPMU'));
        options.add(new SelectOption('F','CIAU'));
        options.add(new SelectOption('G','JGO'));
        return options;
    }
    public List<SelectOption> OCS_Office()
    {
        List<SelectOption> options = new List<SelectOption>();

        OCSOffices = [select Name from OCS_Office__c WHERE OCS_Unit_Code__c=:OCS_Unit]; 
        for(OCS_Office__c a : OCSOffices)
        {
            options.add(new SelectOption(a.Name,a.Name));
        } 
        return options;
		
    }
	
}
Any assistance would be greatly appreciated.

Thanks!

Eric
I have a user requirement that our current Salesforce object, developed in Visualforce be cleaned up. The 
user requirement is that evidentuary information be captured for a case. Currently, through visualforce, we 
have developed a screen that looks like the followig: (except when it is running, the files address is on the same line as the rest of the information.)

Witness name    Witness phone     Witness address        Witness city    Witness e-mail        Deposed    Deposition file 
Jane Doe    916-555-1212    123 Main Street        Sacramento    janedoe@anymail.com    Yes     C:/My Documents/Cases/JanedoeDeposition05042017.WMV
John Doe    916-555-1212    123 Main Street        Sacramento    johndoe@anymail.com    Yes     C:/My Documents/Cases/JohndoeDeposition05042017.WMV
Sue Smith    916-555-1111    133 Main Street        Sacramento    suesmith@anymail.com    Yes     C:/My Documents/Cases/SuesmithDeposition05042017.WMV
Tom Thumb    916-555-2222    113 Main Street        Sacramento    tomthumb@anymail.com    Yes     C:/My Documents/Cases/tomthumbDeposition05042017.WMV


The section of the code that I am currently using to accomplish the above is similar to this: 
 
<apex:pageBlockTable value="{!WitnessEntries}" var="entry" id="Entry_Table_List">
                <apex:column width="70" headerValue="Witness name">
                    <apex:inputField value="{!entry.Witness_name__c}"/>
                </apex:column>    
                <apex:column width="60" headerValue="Witness phone">
                    <apex:inputField value="{!entry.Witness_phone__c}"/>
                </apex:column>    
                <apex:column width="20" headerValue="Witness address">
                    <apex:inputField value="{!entry.Witness_address__c}"/>
                </apex:column>    
                <apex:column width="20" headerValue="Witness city">
                    <apex:inputField value="{!entry.Witness_city__c}"/>
                </apex:column>  
                <apex:column width="80" headerValue="Witness e-mail">
                    <apex:inputField value="{!entry.Witness_e-mail__c}"/><br/>
                </apex:column>  
                <apex:column width="80" headerValue="Deposed">
                    <apex:inputField value="{!entry.Deposed__c}"/><br/>
                </apex:column>  
                <apex:column width="80" headerValue="Deposition file">
                    <apex:inputField value="{!entry.Deposition_file__c}"/><br/>
                </apex:column>  
            </apex:pageBlockTable>

However, what the user wants to see is a form that looks like the following so that it is easier for them to 
digest the information at a glance. 

Witness Name:    Jane Doe       Witness Phone: 916-555-1212    Witness e-mail:  janedoe@anymail.com
Witness address: 123 Main Street   Witness City:  Sacramento     Witness deposed: Yes 
Witness Deposition File: C:/My Documents/Cases/JanedoeDeposition05042017.WMV

Witness Name:    John Doe       Witness Phone: 916-555-1212    Witness e-mail:  johndoe@anymail.com    
Witness address: 123 Main Street   Witness City:  Sacramento     Witness deposed: Yes 
Witness Deposition File: C:/My Documents/Cases/JohndoeDeposition05042017.WMV

Witness Name:    Sue Smith       Witness Phone: 916-555-1111    Witness e-mail:  suesmith@anymail.com    
Witness address: 133 Main Street   Witness City:  Sacramento     Witness deposed: Yes 
Witness Deposition File: C:/My Documents/Cases/SuesmithDeposition05042017.WMV

Witness Name:    Tom Thumb       Witness Phone: 916-555-2222    Witness e-mail:  tomthumb@anymail.com    
Witness address: 113 Main Street   Witness City:  Sacramento     Witness deposed: Yes 
Witness Deposition File: C:/My Documents/Cases/tomthumbDeposition05042017.WMV

Thank you in advance for how I might accomplish this. 

Respectfully, 

Eric Anderson
Is there a way to define a Layout in a table format other than doing it in a Visualforce page?

By default, Salesforce allows you to define a layout as something like

Name: Entry 1
Date: 05/01/2017
Description: This is a test entry.

Name: Entry 2
Date: 05/02/2017
Description: This is the second test entry

I would like to have it display as

Name             Date          Description
Entry 1          05/01/2017 This is a test entry
Entry 2          05/02/2017 This is the second test entry

It seems like we ought to be able to do that in Salesforce Layout manager, but I can't figure out any way to do it. Any assistance would be greatly appreciated.

Thanks! - Eric-
Hi there everyone,

I have a test class that I am trying to create that is giving me grief. I have a test class that has added an entry to a Master object (Requests) and a related object (Time Entry). However, in order to get better coverage, I need to have at least three 'Time Entry' objects created so that various conditions are tested. There is also some totalling going on, so i need to have multiple Time entry objects in the same master object. The creation of the master object works ok, as well as the insert of the initial related object. However, when I try to create the 2nd and 3rd objects (Test2 & Test3) into 'Time Entry' I get the error message: 'INVALID_FIELD_FOR_INSERT_UPDATE, can not specify Id in an insert call:[Id]'

Below is what I believe to be the relevant portion of the code.
 
//Instantiate a new instance of the Custom Request Object.
        Request__c ReqObj = new Request__c();
    //Populate the name of the new request object.
        ReqObj.Name = 'Test request';
    //Populate 'What is being requested.
        ReqObj.What_is_being_requested__c = 'Entry to test apex code.';
    //Insert the new request object into Salesforce.
		insert ReqObj;	
        
    //Obtain the object Id for the request object created.     
        string ReqeustId = ReqObj.id;
		
	//Instantiate a new instance of the Time_Entry object.
		Time_Entry__c te = new Time_Entry__c();
    //Populate the required fields of the Time Entry object.
		te.Name ='Test1';												 
        te.Date_Worked__c = System.today();
        te.Hours_Worked__c = '01';
        te.Minutes_Worked__c = '15';
        te.Work_Description__c = 'This is a test entry';
        te.Activity__c = 'Research';
        te.Related_Object__c = ReqeustId.substring(0, 15);
    //Insert the new Time_Entry object into Salesforce.
		insert te;														 
		
    //Populate the required fields of the Time Entry object.
		te.Name ='Test2';												 
        te.Date_Worked__c = System.today();
        te.Hours_Worked__c = '02';
        te.Minutes_Worked__c = '00';
        te.Work_Description__c = 'This is a test entry';
        te.Activity__c = 'Research';
        te.Related_Object__c = ReqeustId.substring(0, 15);
    //Insert the new Time_Entry object into Salesforce.
		insert te;	
        
    //Populate the required fields of the Time Entry object.
		te.Name ='Test3';												 
        te.Date_Worked__c = System.today();
        te.Hours_Worked__c = '01';
        te.Minutes_Worked__c = '15';
        te.Work_Description__c = 'This is a test entry';
        te.Activity__c = 'Development';
        te.Related_Object__c = ReqeustId.substring(0, 15);
    //Insert the new Time_Entry object into Salesforce.
		insert te;														 
        
	//Indicate the starting of the test process. 
        Test.StartTest();




Any assistance would be greatly appreciated.

Thanks! - Eric -
I have a Visualforce page that I need to display summary data of objects within a parent. As part of the Child object, there is an activity object. That Activity object might include:
Running
Sleeping
Eating
Studying
Recreating

I am required to create an output that shows how many TOTAL hours, each object did. I am required to show, each activity even if there were no hours related to that related list entry. So if the parent object had no hours related to 'Recreating' for instance, I need to show on the display '0' hours. I've tried doing this with a SOQL statement, but it keeps telling me that Activity__c is not valid. I'm trying a 'Select Name from Activity__c' to drive a second SOQL Statement that then goes against the parent oject which in this case is 'Requests' in the form of something like 'Select hours__c from Requests__c where Actvity__c=:Activity__c.id' or something like that. .

I understand why this may not be possible, but I want to know if I am missing something.

Thanks for your time in regards to this!

- Eric Anderson -

Thanks!
Hi there everyone,

I have a requirement to build a report that has sub totals and grand totals in it. Since I can't seem to figure out how to do this in the Salesforce reporting functionality, I'm doing it with a Visual force form. My thought was that I would process through a Object and group the entries by 'Activity'. When the activity changed, I would do a 'Sub total' for the activity. My thinking was that i would take the rows out of the 'SourceEntries' list, and add them to the 'TimeEntrires' list. When the Activity changes, then I would add an extra row to the list that serves as a 'Subtotal' like. Though I have some of the psuedo code in there and commented out, I'm finding that I can't even take information from one list to another.

Can anyone guide me on what I might be doing wrong. I am getting 'Attempt to de-reference a null object'.
The problem is with the statement 'TimeEntries.add(a);
The value of the debug statement is: DEBUG|Time_Entry__c:{Id=a04r0000002303wAAA, Activity__c=Research, Date_Worked__c=2017-04-14 00:00:00, Hours_Worked__c=1, Minutes_Worked__c=00, Work_Description__c=This is the first v1.2 time entry record for create time entry.}

The code involved is the following:
public class TERepController {

    //This is the list for handling the group of time entries related to the parent object. 
    public list<Time_Entry__c> SourceEntries {get;set;}
    //This is the list that will handle the detail with the totals added too it. 
    public List<Time_Entry__c> TimeEntries;

    //Used to get the parent request object ID from the Visual force page to the controller. 
    public string ReqID {get;set;}
    
    //Used to identify when there is an activity change for total generation. 
    public string strOldActivity = 'None';
    
    //Used to detect if a Row entered without selecting an action. 
    public TERepController(ApexPages.StandardController controller) 
    {
        //Obtain the parent object Id from the the visualforce form. 
        ReqId = Apexpages.currentPage().getparameters().get('Id');
        //Call the loaddata method to laod the time entries related to the parent object. 
        LoadData();
     }
    public void LoadData()
    {
        //Obtain the first 15 bytes of the Parent Object ID to use for record selection. 
        ReqId = 'a03r0000000rwC0';
        string RequestID = ReqId.substring(0, 15);
        //Load the related time entry records from the database. 
        SourceEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c from Time_Entry__c WHERE Related_Object__c=:RequestID order by Activity__c, ID]; 
        for(Time_Entry__c a : SourceEntries)
        {
//            if(a.Activity__c == strOldActivity)
//            {
//            	TimeEntries.add(new SourceEntries(a));
//            }
//            	else if(strOldActivity == 'None')
//                    {
                        System.debug(a);
             			TimeEntries.add(a);
//                        strOldActivity = a.Activity__c;
//                    }
//                    	else
//                        {
//                            Time_Entry__c b = new Time_Entry__c(Activity__c=strOldActivity, Work_Description__c='Activity Total', Hours_Worked__c='8', Minutes_Worked__c='30');
//                            TimeEntries.add(new SourceEntries(b));
//             				TimeEntries.add(new SourceEntries(a));
//                        	strOldActivity = a.Activity__c;
//                        }
        } 
        insert TimeEntries;
        return;
    }

}
I'd welcome any assistance anyone can provide me.

Thanks!

Eric Anderson

 
Hi there everyone,

I have a requirement from a user to launch a report from a Visual force page. I will define the report through the normal Reports and Dashboards, but the user requires that i be able to launch the report from the custom object. In our business case, the user will be looking at a 'Time Entry' Visualforce object that is related to our 'Cases' object. The user wants the button on the Visualforce object to pass a parameter of the 'Case object ID' to the report and have the report display all fo the time entries so that this can be printed on a document.

Thank you in advance for your assistance.

Eric Anderson
Hi there,

I have a need to create a trigger that will create a row for a 'Time_Entry' object based on the addition of a row to a 'Requst' object. The 'Request' object has 'Time entries' assigned to it and it is perceived that there is time associated with creating a new request, so the requirement is that the system create a 'Time Entry' for a 'Request' when the new request is opened. I've tried to create a trigger for this based on what i learned from the Trailhead training, but I'm missing something.
 
trigger New_Req_Time_Entry on Request__c (after insert) {
    //Get the ID number for the request just created. 
        string RequestID = Request__c.Id; 
    //Build the default values to the new time entry record. 
        Time_Entry__c entry = new Time_Entry__c(Activity__c='<Select Activity>', Date_Worked__c=System.today(), Hours_Worked__c=' 0', Minutes_Worked__c='15', Related_Object__c=RequestID);
    //Insert the new default time entry row into the Salesforce database. 
        Insert entry;

}

I've tried 3 or 4 approaches, and I keep thinking that I'm over thinking it!

Any help would be greatly appreciated.

Thanks!

Eric Anderson
HI there,

I am new to Salesforce and consiquently Visualforce. I have a business requirement to notify the user if they have not selected the correct entry i the drop down box. I've tried to apply information related in the following 'Article' with no success:

https://developer.salesforce.com/forums/ForumsMain#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F00000008x3BIAQ

The article was based on how to display a 'Message box' in Visualforce. I know the condition to display the message box is met, but the Message box is not being displayed, I am able to see that the value in 'results' is infact equal to true because of the information shown in the log. My related code is below:

RELEVANT VISUALFORCE CODE
 
<apex:page standardController="Request__c" extensions="TrController" >
    <!-- The following code will fix a problem with the calendar autospawning when the time entries are displayed. -->
    <script>
        function setFocusOnLoad(){ Coment.focus(); }
    </script>
    <script> 
       	function validateRecords()
       	{
           	if('{!results}' == true)
               {
                   alert('Please select a action type for the record entered and then click on "Save" again!');
			   }                    
 		}
    </script>



RELEVANT CONTROLLER CODE
 
public string results {get;set;}
    public TrController(ApexPages.StandardController controller) 
    {
        //Obtain the parent object Id from the the visualforce form. 
        ReqId = Apexpages.currentPage().getparameters().get('Id');
        //SelectedEntryId = Apexpages.currentPage().getparameters().get('deleteEntryId');
        //Call the loaddata method to laod the time entries related to the parent object. 
        results = LoadData();
     }
    public string LoadData()
    {
        //Establish results indicator
        results = 'False';
        //Obtain the first 15 bytes of the Parent Object ID to use for record selection. 
        string RequestID = ReqId.substring(0, 15);
        //Load the related time entry records from the database. 
        TimeEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c from Time_Entry__c WHERE Related_Object__c=:RequestID order by ID DESC]; 
        for(Time_Entry__c a : TimeEntries)
        {
        if (a.Activity__c == '<Select Activity>')
            {
                results = 'True';
            }
        } 
        System.debug(results);
        return results;
        //return;
    }

    public void add()
    {   
       //Obtain the first 15 bytes of the Parent Object ID to use for record identification. 
        string RequestID = ReqId.substring(0, 15);
        //Build the default values to the new time entry record. 
        Time_Entry__c entry = new Time_Entry__c(Activity__c='<Select Activity>', Date_Worked__c=System.today(), Hours_Worked__c=' 0', Minutes_Worked__c='00', Related_Object__c=RequestID);
        //Insert the new default time entry row into the Salesforce database. 
        Insert entry;
        //Call the method to reload the Visualforce list. 
        results = LoadData();
        //LoadData();
        //return;
    }

I would greatly appreciate any guidance on how best to proceed with my Visualforce code prompting the user to select an appropriate entry in the drop down box.

Thank you!

Eric Anderson
I don't know what I am doing wrong. I've been working on the Animal Locator exercise in trailhead having to do with REST API Callouts and just can not get the result I'm working on to pass the 'Challenge'. My code is 100% tested, and it seems to meet all the criteria, but I keep getting the following message: "Challenge Not yet complete... here's what's wrong:
Executing the 'getAnimalNameById' method on 'AnimalLocator' failed. Make sure the method exists with the name 'getAnimalNameById', is public and static, accepts an Integer and returns a String."

Below is my code:

AnimalLocator.apxc (Class)

public class AnimalLocator {
    public static string getAnimalNameById(integer numSubmitted) {
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + numSubmitted);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        string replyName = 'None returned';
        if (response.getStatusCode() == 200) {
         replyName = response.getBody();
        }
            return replyName;
    }
}

AnimalLocatorTest.apxc

@IsTest
private class AnimalLocatorTest {
    @isTest static  void  testGetCallout() {
    // Set mock callout class
    Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock());
    // This causes a fake response to be sent
    // from the class that implements HttpCalloutMock.
    String animalname = AnimalLocator.getAnimalNameById(2);
    // Verify that the response received contains fake values       
    String expectedValue = 'Charles H Bones Esquire';
    System.assertEquals(animalname, expectedValue);
    }
}

AnimalLocatorMock.apxc

@IsTest
global class AnimalLocatorMock implements HttpCalloutMock {
    //Implement this interface method
    global HTTPResponse respond(HTTPRequest request) {
        // Create a fake response
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setBody('Charles H Bones Esquire');
        response.setStatusCode(200);
        return response;
    }
}

My code is saved and closed out of and the challenge still fails. Any suggestions would be greatly appreciated. Thanks!
So, I'm new to Apex and Visualforce, and I have a unique problem that I am sure is indicative of the fact that I am a rookie at this envrionment. The code executes correctly when using 'Visualforce' but not with my Apex Test Class. Since I've only been working with Apex and Visualforce for two weeks now, I'm sure its because there is something that I am not clear about. Please find below my Visualforce code, my Controller code and my Test class. I'm only having a problem with testing the Delete code in the Apex class. I can't seem to get the correct 'ID' to pass through so that the row is subsiquently deleted from Salesforce. The 'Null' portion of the Delete in the Controller tests with the Test class, but the deletion of the row inserted does not. Any help would be greatly appreciated. Thanks!

VISUALFORCE CODE 
<apex:page standardController="Request__c" extensions="TrController" >
    <!-- The following code will fix a problem with the calendar autospawning when the time entries are displayed. -->
    <script>
        function setFocusOnLoad(){ Coment.focus(); }
    </script>
   
    <!--Because we will be defining 'Input' fields, we must wrap our code in a 'Form' block. -->
    <apex:form id="Time_Entry_Form">
        <apex:pageBlock title="CDCR - Salesforce Time Reporting for Requests" id="Time_Entry_List">
           
            <!-- The following pageBlockButtons segment defines the two buttons that appear at the top of the Time entry form. -->
            <apex:pageBlockButtons id="Button_area">
                <!-- The following Button is defined in a more complicated fashion so that a parameter can be passed. -->
                <apex:commandLink >
                    <a href="javascript: CurrRequest('{!Request__c.Id}');" class="btn">New</a>               
                </apex:commandLink>
               
                <apex:commandLink >
                    <a href="javascript: SaveEntry();" class="btn">Save</a>               
                </apex:commandLink>

            </apex:pageBlockButtons>
           
             <!-- The following pageBlockTable segment defines the time entry rows that will be displayed. -->
            <apex:pageBlockTable value="{!TimeEntries}" var="entry" id="Entry_Table_List">
                <apex:column width="45" headerValue="Action">
                    <a href="javascript:if (window.confirm('Are you sure?')) DeleteEntry('{!entry.Id}');" style="font-weight:bold">Del</a>               
                </apex:column>   
                <apex:column width="70" headerValue="Activity">
                    <apex:inputField value="{!entry.Activity__c}"/>
                </apex:column>   
                <apex:column width="70" headerValue="Date Worked">
                    <apex:inputField value="{!entry.Date_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Hours">
                    <apex:inputField value="{!entry.Hours_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Worked">
                    <apex:inputField value="{!entry.Minutes_Worked__c}"/>
                </apex:column>   
                <apex:column headerValue="Work Description">
                    <apex:inputField style="width:100%" value="{!entry.Work_Description__c}" id="comment"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <!-- This action block is executed based on the 'Delete' button being clicked on. -->
        <apex:actionFunction action="{!del}" name="DeleteEntry" reRender="Time_Entry_List">
            <apex:param name="deleteEntryID" value="" assignTo="{!SelectedEntryID}"/>
        </apex:actionFunction>
       
         <!-- This action block is executed based on the 'New' button being clicked on. -->
        <apex:actionFunction action="{!add}" name="CurrRequest" reRender="Time_Entry_List">
            <apex:param name="addEntryID" value="" assignTo="{!ReqID}"/>
        </apex:actionFunction>

         <!-- This action block is executed based on the 'Save' button being clicked on. -->
        <apex:actionFunction action="{!save}" name="SaveEntry" reRender="Time_Entry_List"/>
       
     </apex:form>
    <!-- The following script code is used in order to fix the problem with the calendar autospawning. -->
    <script>
        var Coment=document.getElementById('{!$Component.theForm.block.sec.item.comment}');
    </script>   
</apex:page>

APEX CONTROLLER CLASS

public with sharing class TrController
{
    //This is the list for handling the group of time entries related to the parent object.
    public List<Time_Entry__c> TimeEntries {get;set;}
    //Used to get a hold of the entry record that is selected for deletion.
    public string SelectedEntryID {get;set;}
    //Used to get the parent request object ID from the Visual force page to the controller.
    public string ReqID {get;set;}
    public TrController(ApexPages.StandardController controller)
    {
        //Obtain the parent object Id from the the visualforce form.
        ReqId = Apexpages.currentPage().getparameters().get('Id');
        //SelectedEntryId = Apexpages.currentPage().getparameters().get('deleteEntryId');
        //Call the loaddata method to laod the time entries related to the parent object.
        LoadData();
     }
    public void LoadData()
    {
        //Obtain the first 15 bytes of the Parent Object ID to use for record selection.
        string RequestID = ReqId.substring(0, 15);
        //Load the related time entry records from the database.
        TimeEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c from Time_Entry__c WHERE Related_Object__c=:RequestID order by ID DESC];

    }
    public void save()
    {
        //Update the Salesforce database with the data entred.
        update TimeEntries;
    }
    public void add()
    {  
       //Obtain the first 15 bytes of the Parent Object ID to use for record identification.
        string RequestID = ReqId.substring(0, 15);
        //Build the default values to the new time entry record.
        Time_Entry__c entry = new Time_Entry__c(Activity__c='Research', Date_Worked__c=System.today(), Hours_Worked__c=' 0', Minutes_Worked__c='00', Related_Object__c=RequestID);
        //Insert the new default time entry row into the Salesforce database.
        Insert entry;
        //Call the method to reload the Visualforce list.
        LoadData();
    }
    public void del()
    {
     ExecuteDelete(SelectedEntryId);
    }
    public void ExecuteDelete(string selectedEntry)
    {
        //if we are missing the reference, then do nothing except return.
        if (selectedEntry == null)
        {
            return;
        }
        
        //If the record is within the collection, then delete it.
        Time_Entry__c tobeDeleted = null;
        for(Time_Entry__c a : TimeEntries)
        {
            string EntID = a.Id;
            string SelId = EntId.substring(0, 15);
        if (EntID == selectedEntry)
            {
                tobeDeleted = a;
                break;
            }
        }   
        //If account record found then delete it.
        if (tobeDeleted != null)
            {
                Delete toBeDeleted;
            }
        //Refresh the list
        LoadData();

    }

}

APEX TEST CLASS

@isTest
public class TrControllerTest
{
 static testMethod void testMethod1()
 {
  
    //Instantiate a new instance of the Custom Request Object.
        Request__c ReqObj = new Request__c();
    //Populate the name of the new request object.
        ReqObj.Name = 'Test request';
    //Populate 'What is being requested.
        ReqObj.What_is_being_requested__c = 'Entry to test apex code.';
    //Insert the new request object into Salesforce.
  insert ReqObj;             
  
 //Instantiate a new instance of the Time_Entry object.
  Time_Entry__c te = new Time_Entry__c();
    //Populate the required fields of the Time Entry object.
  te.Name ='Test';            
        te.Date_Worked__c = System.today();
        te.Hours_Worked__c = '01';
        te.Minutes_Worked__c = '15';
        te.Work_Description__c = 'This is a test entry';
        te.Activity__c = 'Research';
    //Insert the new Time_Entry object into Salesforce.
  insert te;              
  
    //Indicate the starting of the test process.
        Test.StartTest();
 
    //Post the Request ID of the Request object created.
            Apexpages.currentPage().getparameters().put('id', String.valueOf(ReqObj.Id));
    //Instantiate a new instance of the Request object standard controller.
       ApexPages.StandardController sc = new ApexPages.StandardController(ReqObj);
    //Instantiate a new instance of the Time Entry Controller that is related to the Standard controller.
        TrController testAccPlan = new TrController(sc);
   
    //Test the code within the 'save' method.
            testAccPlan.save(); 
    //Test the code within the 'add' method.
         testAccPlan.add();           
         //System.AssertEquals(NewEntryId, ReqObj.Id);
            
 //Obtain the object Id's for the row inserted in the database initially.    
         List<Time_Entry__c> deleteEntry = [select id from Time_Entry__c WHERE Work_Description__c = 'This is a test entry'];

 //Loop through the objects returned from the 'Select' statement and pass the Object Id's to the 'ExecuteDelete' class.    
        for(Time_Entry__c a : deleteEntry)
            {
                testAccPlan.ExecuteDelete(a.Id);
                //Leave the loop after one itteration.
                break;
            }
    
    //Execute the ExecuteDelete class with a 'Null' variable so that the additionally related code is tested.
        testAccPlan.ExecuteDelete(null);
  
    //Indicate the end of the test code.
        Test.StopTest();
 }
}
So I have a Visualforce page that I have created that is related to a standard controller and also an extension to an 'Apex' controller. I've taken the 'Trailhead' training on testing an Apex class, but I can't seem to successfully apply what I learned in the Trailhead tutorial to my project and get there to not be syntax errors in my test code. I have only working on my first Visualforce/Apex project for a week now, so I'd sure welcome any suggestions anyone might have. The primary Methods that I am calling from the Visualforce Page are 'Save', 'Add' and 'Delete', so any help in any of those methods that I could then apply to the others would be greatly appreciated.

VISUALFORCE CODE:
<apex:page standardController="Request__c" extensions="TrController" >
    <!-- The following code will fix a problem with the calendar autospawning when the time entries are displayed. -->
    <script>
        function setFocusOnLoad(){ Coment.focus(); }
    </script>
   
    <!--Because we will be defining 'Input' fields, we must wrap our code in a 'Form' block. -->
    <apex:form id="Time_Entry_Form">
        <apex:pageBlock title="CDCR - Salesforce Time Reporting for Requests" id="Time_Entry_List">
           
            <!-- The following pageBlockButtons segment defines the two buttons that appear at the top of the Time entry form. -->
            <apex:pageBlockButtons id="Button_area">
                <!-- The following Button is defined in a more complicated fashion so that a parameter can be passed. -->
                <apex:commandLink >
                    <a href="javascript: CurrRequest('{!Request__c.Id}');" class="btn">New</a>               
                </apex:commandLink>
               
                <apex:commandLink >
                    <a href="javascript: SaveEntry();" class="btn">Save</a>               
                </apex:commandLink>

            </apex:pageBlockButtons>
           
             <!-- The following pageBlockTable segment defines the time entry rows that will be displayed. -->
            <apex:pageBlockTable value="{!TimeEntries}" var="entry" id="Entry_Table_List">
                <apex:column width="45" headerValue="Action">
                    <a href="javascript:if (window.confirm('Are you sure?')) DeleteEntry('{!entry.Id}');" style="font-weight:bold">Del</a>               
                </apex:column>   
                <apex:column width="70" headerValue="Activity">
                    <apex:inputField value="{!entry.Activity__c}"/>
                </apex:column>   
                <apex:column width="70" headerValue="Date Worked">
                    <apex:inputField value="{!entry.Date_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Hours">
                    <apex:inputField value="{!entry.Hours_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Worked">
                    <apex:inputField value="{!entry.Minutes_Worked__c}"/>
                </apex:column>   
                <apex:column headerValue="Work Description">
                    <apex:inputField style="width:100%" value="{!entry.Work_Description__c}" id="comment"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <!-- This action block is executed based on the 'Delete' button being clicked on. -->
        <apex:actionFunction action="{!del}" name="DeleteEntry" reRender="Time_Entry_List">
            <apex:param name="EntryID" value="" assignTo="{!SelectedEntryID}"/>
        </apex:actionFunction>
       
         <!-- This action block is executed based on the 'New' button being clicked on. -->
        <apex:actionFunction action="{!add}" name="CurrRequest" reRender="Time_Entry_List">
            <apex:param name="EntryID" value="" assignTo="{!ReqID}"/>
        </apex:actionFunction>

         <!-- This action block is executed based on the 'Save' button being clicked on. -->
        <apex:actionFunction action="{!save}" name="SaveEntry" reRender="Time_Entry_List"/>
       
     </apex:form>
    <!-- The following script code is used in order to fix the problem with the calendar autospawning. -->
    <script>
        var Coment=document.getElementById('{!$Component.theForm.block.sec.item.comment}');
    </script>   
</apex:page>

CONTROLLER APEX CODE

public with sharing class TrController
{
    //This is the list for handling the group of time entries related to the parent object.
    public List<Time_Entry__c> TimeEntries {get;set;}
    //Used to get a hold of the entry record that is selected for deletion.
    public string SelectedEntryID {get;set;}
    //Used to get the parent request object ID from the Visual force page to the controller.
    public string ReqID {get;set;}
    public TrController(ApexPages.StandardController controller)
    {
        //Obtain the parent object Id from the the visualforce form.
        ReqId = Apexpages.currentPage().getparameters().get('Id');
        //Call the loaddata method to laod the time entries related to the parent object.
        LoadData();
     }
    public void LoadData()
    {
        //Obtain the first 15 bytes of the Parent Object ID to use for record selection.
        string RequestID = ReqId.substring(0, 15);
        //Load the related time entry records from the database.
        TimeEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c from Time_Entry__c WHERE Related_Object__c=:RequestID order by ID DESC];

    }
    public void save()
    {
        //Update the Salesforce database with the data entred.
        update TimeEntries;
    }
    public void add()
    {  
       //Obtain the first 15 bytes of the Parent Object ID to use for record identification.
        string RequestID = ReqId.substring(0, 15);
        //Build the default values to the new time entry record.
        Time_Entry__c entry = new Time_Entry__c(Activity__c='Research', Date_Worked__c=System.today(), Hours_Worked__c=' 0', Minutes_Worked__c='00', Related_Object__c=RequestID);
        //Insert the new default time entry row into the Salesforce database.
        Insert entry;
        //Call the method to reload the Visualforce list.
        LoadData();
    }
    public void del()
    {   
        //if we are missing the reference, then do nothing except return.
        if (SelectedEntryId == null)
        {
            return;
        }
        
        //If the record is within the collection, then delete it.
        Time_Entry__c tobeDeleted = null;
        for(Time_Entry__c a : TimeEntries)
        if (a.Id == SelectedEntryId)
            {
                tobeDeleted = a;
                break;
            }
        //If account record found then delete it.
        if (tobeDeleted != null)
            {
                Delete toBeDeleted;
            }
        //Refresh the list
        LoadData();

    }

}

Thank you in advance for your time.

Eric Anderson 
Hi there,

I have a Visualforce page that allows for editing of rows in a table. My problem is, I can't figure out what is causing the 'forcus' to be initially placed on the calendar of the first row of my visualforce object, and consiquently causing the calendar to display. I don't want the calednar to display unless someone clicks on it. My visualforce code is below, and a screenshot is attached.

Thank you in advance for your assistance.

<apex:page standardController="Request__c" extensions="TrController" >
    <!--Because we will be defining 'Input' fields, we must wrap our code in a 'Form' block. -->
    <apex:form id="Time_Entry_Form">
        <apex:pageBlock title="CDCR - Salesforce Time Reporting for Requests" id="Time_Entry_List">
           
            <!-- The following pageBlockButtons segment defines the two buttons that appear at the top of the Time entry form. -->
            <apex:pageBlockButtons id="Button_area">
                <!-- The following Button is defined in a more complicated fashion so that a parameter can be passed. -->
                <apex:commandLink >
                    <a href="javascript: CurrRequest('{!Request__c.Id}');" class="btn">New</a>               
                </apex:commandLink>
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
           
             <!-- The following pageBlockTable segment defines the time entry rows that will be displayed. -->
            <apex:pageBlockTable value="{!TimeEntries}" var="entry" id="Entry_Table_List">
                <apex:column width="45" headerValue="Action">
                    <a href="javascript:if (window.confirm('Are you sure?')) DeleteEntry('{!entry.Id}');" style="font-weight:bold">Del</a>               
                </apex:column>   
                <apex:column width="70" headerValue="Activity">
                    <apex:inputField value="{!entry.Activity__c}"/>
                </apex:column>   
                <apex:column headerValue="Date Worked">
                    <apex:inputField value="{!entry.Date_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Hours">
                    <apex:inputField value="{!entry.Hours_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Worked">
                    <apex:inputField value="{!entry.Minutes_Worked__c}"/>
                </apex:column>   
                <apex:column headerValue="Work Description">
                    <apex:inputField style="width:100%" value="{!entry.Work_Description__c}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <!-- This action block is executed based on the 'Delete' button being clicked on. -->
        <apex:actionFunction action="{!del}" name="DeleteEntry" reRender="Time_Entry_List">
            <apex:param name="EntryID" value="" assignTo="{!SelectedEntryID}"/>
        </apex:actionFunction>
       
         <!-- This action block is executed based on the 'New' button being clicked on. -->
        <apex:actionFunction action="{!add}" name="CurrRequest" reRender="Time_Entry_List">
            <apex:param name="EntryID" value="" assignTo="{!ReqID}"/>
        </apex:actionFunction>

    </apex:form>
</apex:page>

User-added image
Hi there,

I have two custom objects. The Investigation__c is the parent object, and the Time_Entry_Recap_Report__c is the child object. What I want to have happen is when the parent record (Investigation) is initially created, I want to create an initial entry in the 'Time_Entry_Recap_Report__c' with 15 minutes of time worked and a description of the task being 'Opened new investigation'. I'm trying to figure out how to relate the Child record to the parent record when I create the entry in the trigger. The object 'Time_Entry_Recap_Report__c' is already defined as a child to the parent, but trying to insert the record without a reference to the 'Investigation_Time_Entry__c' field within the 'Time_Entry_Recap_Report__c' object didn't work either. The Error I am getting is "Error: Compile Error: Illegal assignment from Schema.SObjectField to Id at line 8 column 7. Any assistance would be greatly appreicated. 
trigger CreateTimeEntry on Investigation__c (after insert) {
    List<Time_Entry_Recap_Report__c> entryList = new List<Time_Entry_Recap_Report__c>();
    for(Investigation__c InvestigationObj : Trigger.new){
    Time_Entry_Recap_Report__c entry = new Time_Entry_Recap_Report__c();
      entry.Hours_Worked__c = '00';
      entry.Minutes_Worked__c = '15';
      entry.Work_Performed__c = 'Opened new investigation';
      entry.Investigation_Time_Entry__c = Investigation__c.NAME;
      entryList.add(entry);
     }
     if(entryList.size()>0){
      upsert entryList;
     }
}

 
Hi there,

I have a custom (parent) object that has two child objects related to it. I have also allowed (Notes &) 'Attachements' to be enabled for the (parent) custom object. One of the Child objects tracks 'Time' invovled in the particular entry in the (Parent) custom object. The other child object tracks 'Suspects' who are involved in a particular entry of the (Parent) custom object.The user has requested that when a 'Suspect' is entered into child object which are related to the parent object, that a entry be made into the 'Time' child object. Similarly, they have requested that whenever an 'Attachment' is added to the (Parent) custom object, that  another entry be made into the 'Time' child object.

I've tried both the 'Before Insert' and 'After Insert' type of trigger for the Attachments, and neither one seems to execute.
 
trigger Attachement_After_Add_Del on Attachment (before insert) {
    List<Request_Time_Entry__c> entryList = new List<Request_Time_Entry__c>();
    for(Attachment AttachmentObj : Trigger.new){
    system.debug('The Attachment Trigger fired.');
    Request_Time_Entry__c entry = new Request_Time_Entry__c();
      entry.Hours_Worked__c = '0';
      entry.Minutes_Worked__c = '15';
      string ParentID = AttachmentObj.parentId;
      entry.Work_Description__c = 'Added Suspect';
      entry.Name = ParentID.substring(0, 15);
      entry.Date_Worked__C = system.Today();
      entry.Related_Object__c = ParentID.substring(0, 15);
      entryList.add(entry);
     }
     if(entryList.size()>0){
      insert entryList;
     }
}


trigger Suspect_After_Add on Suspect__c (after insert) {
    List<Request_Time_Entry__c> entryList = new List<Request_Time_Entry__c>();
    for(Suspect__c SuspectObj : Trigger.new){
    system.debug('The Suspect Trigger fired.');
    Request_Time_Entry__c entry = new Request_Time_Entry__c();
      entry.Hours_Worked__c = '0';
      entry.Minutes_Worked__c = '15';
      string ParentID = SuspectObj.Investigation__c;
      entry.Work_Description__c = 'Added Suspect';
      entry.Name = ParentID.substring(0, 15);
      entry.Date_Worked__C = system.Today();
      entry.Related_Object__c = ParentID.substring(0, 15);
      entryList.add(entry);
     }
     if(entryList.size()>0){
      insert entryList;
     }
}



My 'Suspects' trigger works just fine. I have a 'System.debug' statement in it and it is showing up in my log just fine, including the entry being made in the 'Time' Child object.

My Attachment trigger does not work as best I can tell. There is no entry in the 'Time' Child object, and there is no entry in the Logs either. 

Does anyone have any insight for me on what the problem might be? Is there some obscure setting somewhere that I need to look for that will allow 'Attachments' of Custom objects to fire triggers?

I'd welcome any input I can get on this subject.

Thanks!

Eric Anderson
 
Hi there I have a custom parent object that has a child object. I also allow on the Parent object 'Notes and Attachments' (Notes & Upload files). We need to have a trigger on the 'Attachements' that will fire a trigger that will create an entry on the Child object of the parent. I don't know what needs to be done (if anything) to have the Child object know the id of the parent object. I presume I need to include the Parent ID when I create the entry in the Child object.

Below is the code I have been experimenting with, but I have not been able to get it to work.
 
trigger Attachement_After_Add_Del on Attachment (after insert) {
    List<Request_Time_Entry__c> entryList = new List<Request_Time_Entry__c>();
    for(Attachment AttachmentObj : Trigger.new){
    Request_Time_Entry__c entry = new Request_Time_Entry__c();
      entry.Hours_Worked__c = '00';
      entry.Minutes_Worked__c = '15';
      entry.NAME = 'Added Attachment';
      entry.Date_Worked__C = system.Today();
      // I don't know if what I need in the following line is correct. I Don't seem to get any
      // entries created on the child object when I run this code. Or, am I using the wrong 
     // form of 'Trigger' for an 'Attachement'. 
      entry.Related_Object__c = AttachmentObj.ParentId;
      entryList.add(entry);
     }
     if(entryList.size()>0){
      insert entryList;
     }
}
Any assistance would be greatly appreciated.

Thanks!

Eric Anderson
Hi there,

We have an App that is a 'Investigation' Custom object. Within that custom object, I have one or more witnesses as 'Child custom' objects. Because the 'Save' in the default entry form (Salesforce out of the box) for the child object does not take us back to the 'Parent custom object' the way the user wants it too, we used a 'URL Hack'. We got chastised for this and told we should use a VisualForce page. I'm fairly green when it comes to VisualForce development, so I could use all of the help that I can get. In a 'Master-Detail' related lists, I'm trying to create a data entry form using VisualForce. I've entered most of the mark up in the VF page and my code looks like the following:
 
<apex:page standardController="Witness__c">
<apex:form id="Witness_Entry_Form">
    <apex:pageBlock title="Create Witness">

    <apex:pageBlockSection columns="1">  
    <apex:inputField value="{!Witness__c.Name}"/>      
    <apex:inputField value="{!Witness__c.CDC_Number__c}"/>
    <apex:inputField value="{!Witness__c.CDC_Offender__c}"/>
    <apex:inputField value="{!Witness__c.Eye_Color__c}"/>
    <apex:inputField value="{!Witness__c.First_Name__c}"/>
    <apex:inputField value="{!Witness__c.Hair_Color__c}"/>
    <apex:inputField value="{!Witness__c.Last_Name__c}"/>
    <apex:inputField value="{!Witness__c.Request_Witness__c}"/>
    </apex:pageBlockSection>

    <apex:pageBlockButtons >
      <apex:commandButton action="{!save}" value="Save"/>
    </apex:pageBlockButtons>

</apex:pageBlock>
        
</apex:form>
</apex:page>

However, when I try to create a button within the Witness object with a display type of 'List button', and then select 'VisualForce' for the Content source, my VisualForce page is not listed in the 'Content' drop down box and as a result I get a 'You must enter a value' error.

I would sincerely appreicate any help I can get in regards to this.

Thanks!

Eric 
Hi there everyone,

I'm new to Salesforce and Visualforce development. Though I have been doing C# for years in the Windows environment, my experience in web development is pretty limited. I am trying to build a solution where there are two picklists. The first pick list (OCS Units) is based on a 'Global pick list'. The second pick list should be loaded based on the value picked in the first pick list. When I run my code, it doesn't look like even the first pick list is being populated because when I click on the 'drop down' arrow, nothing is displayed.

Below is my Visualforce code:
 
<apex:page controller="OCSPicklistLoader">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection columns="2">
            	<apex:pageBlockSectionItem>
                    <apex:outputLabel value="OCS Unit"/>
                </apex:pageBlockSectionItem>
            	<apex:pageBlockSectionItem>
                    <apex:selectList size="1" value="{!OCS_Unit}">
                    	<apex:selectOptions value="{!OCS_Unit}"/>
                    	<apex:actionSupport event="onchange" reRender="Offices"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem>
                    <apex:outputLabel value="OCS Office"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem>
                    <apex:selectList size="1" value="{!OCS_Office}" id="Offices">
                    	<apex:selectOptions value="{!OCS_Office}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>    
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Below is my Controller code:
public class OCSPicklistLoader {
    public string OCS_Unit {get;set;}
    public string OCS_Office {get;set;}
    public List<OCS_Office__c> OCSOffices;
     
    public List<SelectOption> OCS_Unit()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('A','None'));
        options.add(new SelectOption('B','FAT'));
        options.add(new SelectOption('C','SSU'));
        options.add(new SelectOption('D','EOU'));
        options.add(new SelectOption('E','EPMU'));
        options.add(new SelectOption('F','CIAU'));
        options.add(new SelectOption('G','JGO'));
        return options;
    }
    public List<SelectOption> OCS_Office()
    {
        List<SelectOption> options = new List<SelectOption>();

        OCSOffices = [select Name from OCS_Office__c WHERE OCS_Unit_Code__c=:OCS_Unit]; 
        for(OCS_Office__c a : OCSOffices)
        {
            options.add(new SelectOption(a.Name,a.Name));
        } 
        return options;
		
    }
	
}
Any assistance would be greatly appreciated.

Thanks!

Eric
I have a user requirement that our current Salesforce object, developed in Visualforce be cleaned up. The 
user requirement is that evidentuary information be captured for a case. Currently, through visualforce, we 
have developed a screen that looks like the followig: (except when it is running, the files address is on the same line as the rest of the information.)

Witness name    Witness phone     Witness address        Witness city    Witness e-mail        Deposed    Deposition file 
Jane Doe    916-555-1212    123 Main Street        Sacramento    janedoe@anymail.com    Yes     C:/My Documents/Cases/JanedoeDeposition05042017.WMV
John Doe    916-555-1212    123 Main Street        Sacramento    johndoe@anymail.com    Yes     C:/My Documents/Cases/JohndoeDeposition05042017.WMV
Sue Smith    916-555-1111    133 Main Street        Sacramento    suesmith@anymail.com    Yes     C:/My Documents/Cases/SuesmithDeposition05042017.WMV
Tom Thumb    916-555-2222    113 Main Street        Sacramento    tomthumb@anymail.com    Yes     C:/My Documents/Cases/tomthumbDeposition05042017.WMV


The section of the code that I am currently using to accomplish the above is similar to this: 
 
<apex:pageBlockTable value="{!WitnessEntries}" var="entry" id="Entry_Table_List">
                <apex:column width="70" headerValue="Witness name">
                    <apex:inputField value="{!entry.Witness_name__c}"/>
                </apex:column>    
                <apex:column width="60" headerValue="Witness phone">
                    <apex:inputField value="{!entry.Witness_phone__c}"/>
                </apex:column>    
                <apex:column width="20" headerValue="Witness address">
                    <apex:inputField value="{!entry.Witness_address__c}"/>
                </apex:column>    
                <apex:column width="20" headerValue="Witness city">
                    <apex:inputField value="{!entry.Witness_city__c}"/>
                </apex:column>  
                <apex:column width="80" headerValue="Witness e-mail">
                    <apex:inputField value="{!entry.Witness_e-mail__c}"/><br/>
                </apex:column>  
                <apex:column width="80" headerValue="Deposed">
                    <apex:inputField value="{!entry.Deposed__c}"/><br/>
                </apex:column>  
                <apex:column width="80" headerValue="Deposition file">
                    <apex:inputField value="{!entry.Deposition_file__c}"/><br/>
                </apex:column>  
            </apex:pageBlockTable>

However, what the user wants to see is a form that looks like the following so that it is easier for them to 
digest the information at a glance. 

Witness Name:    Jane Doe       Witness Phone: 916-555-1212    Witness e-mail:  janedoe@anymail.com
Witness address: 123 Main Street   Witness City:  Sacramento     Witness deposed: Yes 
Witness Deposition File: C:/My Documents/Cases/JanedoeDeposition05042017.WMV

Witness Name:    John Doe       Witness Phone: 916-555-1212    Witness e-mail:  johndoe@anymail.com    
Witness address: 123 Main Street   Witness City:  Sacramento     Witness deposed: Yes 
Witness Deposition File: C:/My Documents/Cases/JohndoeDeposition05042017.WMV

Witness Name:    Sue Smith       Witness Phone: 916-555-1111    Witness e-mail:  suesmith@anymail.com    
Witness address: 133 Main Street   Witness City:  Sacramento     Witness deposed: Yes 
Witness Deposition File: C:/My Documents/Cases/SuesmithDeposition05042017.WMV

Witness Name:    Tom Thumb       Witness Phone: 916-555-2222    Witness e-mail:  tomthumb@anymail.com    
Witness address: 113 Main Street   Witness City:  Sacramento     Witness deposed: Yes 
Witness Deposition File: C:/My Documents/Cases/tomthumbDeposition05042017.WMV

Thank you in advance for how I might accomplish this. 

Respectfully, 

Eric Anderson
Hi there everyone,

I have a test class that I am trying to create that is giving me grief. I have a test class that has added an entry to a Master object (Requests) and a related object (Time Entry). However, in order to get better coverage, I need to have at least three 'Time Entry' objects created so that various conditions are tested. There is also some totalling going on, so i need to have multiple Time entry objects in the same master object. The creation of the master object works ok, as well as the insert of the initial related object. However, when I try to create the 2nd and 3rd objects (Test2 & Test3) into 'Time Entry' I get the error message: 'INVALID_FIELD_FOR_INSERT_UPDATE, can not specify Id in an insert call:[Id]'

Below is what I believe to be the relevant portion of the code.
 
//Instantiate a new instance of the Custom Request Object.
        Request__c ReqObj = new Request__c();
    //Populate the name of the new request object.
        ReqObj.Name = 'Test request';
    //Populate 'What is being requested.
        ReqObj.What_is_being_requested__c = 'Entry to test apex code.';
    //Insert the new request object into Salesforce.
		insert ReqObj;	
        
    //Obtain the object Id for the request object created.     
        string ReqeustId = ReqObj.id;
		
	//Instantiate a new instance of the Time_Entry object.
		Time_Entry__c te = new Time_Entry__c();
    //Populate the required fields of the Time Entry object.
		te.Name ='Test1';												 
        te.Date_Worked__c = System.today();
        te.Hours_Worked__c = '01';
        te.Minutes_Worked__c = '15';
        te.Work_Description__c = 'This is a test entry';
        te.Activity__c = 'Research';
        te.Related_Object__c = ReqeustId.substring(0, 15);
    //Insert the new Time_Entry object into Salesforce.
		insert te;														 
		
    //Populate the required fields of the Time Entry object.
		te.Name ='Test2';												 
        te.Date_Worked__c = System.today();
        te.Hours_Worked__c = '02';
        te.Minutes_Worked__c = '00';
        te.Work_Description__c = 'This is a test entry';
        te.Activity__c = 'Research';
        te.Related_Object__c = ReqeustId.substring(0, 15);
    //Insert the new Time_Entry object into Salesforce.
		insert te;	
        
    //Populate the required fields of the Time Entry object.
		te.Name ='Test3';												 
        te.Date_Worked__c = System.today();
        te.Hours_Worked__c = '01';
        te.Minutes_Worked__c = '15';
        te.Work_Description__c = 'This is a test entry';
        te.Activity__c = 'Development';
        te.Related_Object__c = ReqeustId.substring(0, 15);
    //Insert the new Time_Entry object into Salesforce.
		insert te;														 
        
	//Indicate the starting of the test process. 
        Test.StartTest();




Any assistance would be greatly appreciated.

Thanks! - Eric -
Hi there everyone,

I have a requirement to build a report that has sub totals and grand totals in it. Since I can't seem to figure out how to do this in the Salesforce reporting functionality, I'm doing it with a Visual force form. My thought was that I would process through a Object and group the entries by 'Activity'. When the activity changed, I would do a 'Sub total' for the activity. My thinking was that i would take the rows out of the 'SourceEntries' list, and add them to the 'TimeEntrires' list. When the Activity changes, then I would add an extra row to the list that serves as a 'Subtotal' like. Though I have some of the psuedo code in there and commented out, I'm finding that I can't even take information from one list to another.

Can anyone guide me on what I might be doing wrong. I am getting 'Attempt to de-reference a null object'.
The problem is with the statement 'TimeEntries.add(a);
The value of the debug statement is: DEBUG|Time_Entry__c:{Id=a04r0000002303wAAA, Activity__c=Research, Date_Worked__c=2017-04-14 00:00:00, Hours_Worked__c=1, Minutes_Worked__c=00, Work_Description__c=This is the first v1.2 time entry record for create time entry.}

The code involved is the following:
public class TERepController {

    //This is the list for handling the group of time entries related to the parent object. 
    public list<Time_Entry__c> SourceEntries {get;set;}
    //This is the list that will handle the detail with the totals added too it. 
    public List<Time_Entry__c> TimeEntries;

    //Used to get the parent request object ID from the Visual force page to the controller. 
    public string ReqID {get;set;}
    
    //Used to identify when there is an activity change for total generation. 
    public string strOldActivity = 'None';
    
    //Used to detect if a Row entered without selecting an action. 
    public TERepController(ApexPages.StandardController controller) 
    {
        //Obtain the parent object Id from the the visualforce form. 
        ReqId = Apexpages.currentPage().getparameters().get('Id');
        //Call the loaddata method to laod the time entries related to the parent object. 
        LoadData();
     }
    public void LoadData()
    {
        //Obtain the first 15 bytes of the Parent Object ID to use for record selection. 
        ReqId = 'a03r0000000rwC0';
        string RequestID = ReqId.substring(0, 15);
        //Load the related time entry records from the database. 
        SourceEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c from Time_Entry__c WHERE Related_Object__c=:RequestID order by Activity__c, ID]; 
        for(Time_Entry__c a : SourceEntries)
        {
//            if(a.Activity__c == strOldActivity)
//            {
//            	TimeEntries.add(new SourceEntries(a));
//            }
//            	else if(strOldActivity == 'None')
//                    {
                        System.debug(a);
             			TimeEntries.add(a);
//                        strOldActivity = a.Activity__c;
//                    }
//                    	else
//                        {
//                            Time_Entry__c b = new Time_Entry__c(Activity__c=strOldActivity, Work_Description__c='Activity Total', Hours_Worked__c='8', Minutes_Worked__c='30');
//                            TimeEntries.add(new SourceEntries(b));
//             				TimeEntries.add(new SourceEntries(a));
//                        	strOldActivity = a.Activity__c;
//                        }
        } 
        insert TimeEntries;
        return;
    }

}
I'd welcome any assistance anyone can provide me.

Thanks!

Eric Anderson

 
Hi there,

I have a need to create a trigger that will create a row for a 'Time_Entry' object based on the addition of a row to a 'Requst' object. The 'Request' object has 'Time entries' assigned to it and it is perceived that there is time associated with creating a new request, so the requirement is that the system create a 'Time Entry' for a 'Request' when the new request is opened. I've tried to create a trigger for this based on what i learned from the Trailhead training, but I'm missing something.
 
trigger New_Req_Time_Entry on Request__c (after insert) {
    //Get the ID number for the request just created. 
        string RequestID = Request__c.Id; 
    //Build the default values to the new time entry record. 
        Time_Entry__c entry = new Time_Entry__c(Activity__c='<Select Activity>', Date_Worked__c=System.today(), Hours_Worked__c=' 0', Minutes_Worked__c='15', Related_Object__c=RequestID);
    //Insert the new default time entry row into the Salesforce database. 
        Insert entry;

}

I've tried 3 or 4 approaches, and I keep thinking that I'm over thinking it!

Any help would be greatly appreciated.

Thanks!

Eric Anderson
HI there,

I am new to Salesforce and consiquently Visualforce. I have a business requirement to notify the user if they have not selected the correct entry i the drop down box. I've tried to apply information related in the following 'Article' with no success:

https://developer.salesforce.com/forums/ForumsMain#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F00000008x3BIAQ

The article was based on how to display a 'Message box' in Visualforce. I know the condition to display the message box is met, but the Message box is not being displayed, I am able to see that the value in 'results' is infact equal to true because of the information shown in the log. My related code is below:

RELEVANT VISUALFORCE CODE
 
<apex:page standardController="Request__c" extensions="TrController" >
    <!-- The following code will fix a problem with the calendar autospawning when the time entries are displayed. -->
    <script>
        function setFocusOnLoad(){ Coment.focus(); }
    </script>
    <script> 
       	function validateRecords()
       	{
           	if('{!results}' == true)
               {
                   alert('Please select a action type for the record entered and then click on "Save" again!');
			   }                    
 		}
    </script>



RELEVANT CONTROLLER CODE
 
public string results {get;set;}
    public TrController(ApexPages.StandardController controller) 
    {
        //Obtain the parent object Id from the the visualforce form. 
        ReqId = Apexpages.currentPage().getparameters().get('Id');
        //SelectedEntryId = Apexpages.currentPage().getparameters().get('deleteEntryId');
        //Call the loaddata method to laod the time entries related to the parent object. 
        results = LoadData();
     }
    public string LoadData()
    {
        //Establish results indicator
        results = 'False';
        //Obtain the first 15 bytes of the Parent Object ID to use for record selection. 
        string RequestID = ReqId.substring(0, 15);
        //Load the related time entry records from the database. 
        TimeEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c from Time_Entry__c WHERE Related_Object__c=:RequestID order by ID DESC]; 
        for(Time_Entry__c a : TimeEntries)
        {
        if (a.Activity__c == '<Select Activity>')
            {
                results = 'True';
            }
        } 
        System.debug(results);
        return results;
        //return;
    }

    public void add()
    {   
       //Obtain the first 15 bytes of the Parent Object ID to use for record identification. 
        string RequestID = ReqId.substring(0, 15);
        //Build the default values to the new time entry record. 
        Time_Entry__c entry = new Time_Entry__c(Activity__c='<Select Activity>', Date_Worked__c=System.today(), Hours_Worked__c=' 0', Minutes_Worked__c='00', Related_Object__c=RequestID);
        //Insert the new default time entry row into the Salesforce database. 
        Insert entry;
        //Call the method to reload the Visualforce list. 
        results = LoadData();
        //LoadData();
        //return;
    }

I would greatly appreciate any guidance on how best to proceed with my Visualforce code prompting the user to select an appropriate entry in the drop down box.

Thank you!

Eric Anderson
I don't know what I am doing wrong. I've been working on the Animal Locator exercise in trailhead having to do with REST API Callouts and just can not get the result I'm working on to pass the 'Challenge'. My code is 100% tested, and it seems to meet all the criteria, but I keep getting the following message: "Challenge Not yet complete... here's what's wrong:
Executing the 'getAnimalNameById' method on 'AnimalLocator' failed. Make sure the method exists with the name 'getAnimalNameById', is public and static, accepts an Integer and returns a String."

Below is my code:

AnimalLocator.apxc (Class)

public class AnimalLocator {
    public static string getAnimalNameById(integer numSubmitted) {
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + numSubmitted);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        string replyName = 'None returned';
        if (response.getStatusCode() == 200) {
         replyName = response.getBody();
        }
            return replyName;
    }
}

AnimalLocatorTest.apxc

@IsTest
private class AnimalLocatorTest {
    @isTest static  void  testGetCallout() {
    // Set mock callout class
    Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock());
    // This causes a fake response to be sent
    // from the class that implements HttpCalloutMock.
    String animalname = AnimalLocator.getAnimalNameById(2);
    // Verify that the response received contains fake values       
    String expectedValue = 'Charles H Bones Esquire';
    System.assertEquals(animalname, expectedValue);
    }
}

AnimalLocatorMock.apxc

@IsTest
global class AnimalLocatorMock implements HttpCalloutMock {
    //Implement this interface method
    global HTTPResponse respond(HTTPRequest request) {
        // Create a fake response
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setBody('Charles H Bones Esquire');
        response.setStatusCode(200);
        return response;
    }
}

My code is saved and closed out of and the challenge still fails. Any suggestions would be greatly appreciated. Thanks!
So, I'm new to Apex and Visualforce, and I have a unique problem that I am sure is indicative of the fact that I am a rookie at this envrionment. The code executes correctly when using 'Visualforce' but not with my Apex Test Class. Since I've only been working with Apex and Visualforce for two weeks now, I'm sure its because there is something that I am not clear about. Please find below my Visualforce code, my Controller code and my Test class. I'm only having a problem with testing the Delete code in the Apex class. I can't seem to get the correct 'ID' to pass through so that the row is subsiquently deleted from Salesforce. The 'Null' portion of the Delete in the Controller tests with the Test class, but the deletion of the row inserted does not. Any help would be greatly appreciated. Thanks!

VISUALFORCE CODE 
<apex:page standardController="Request__c" extensions="TrController" >
    <!-- The following code will fix a problem with the calendar autospawning when the time entries are displayed. -->
    <script>
        function setFocusOnLoad(){ Coment.focus(); }
    </script>
   
    <!--Because we will be defining 'Input' fields, we must wrap our code in a 'Form' block. -->
    <apex:form id="Time_Entry_Form">
        <apex:pageBlock title="CDCR - Salesforce Time Reporting for Requests" id="Time_Entry_List">
           
            <!-- The following pageBlockButtons segment defines the two buttons that appear at the top of the Time entry form. -->
            <apex:pageBlockButtons id="Button_area">
                <!-- The following Button is defined in a more complicated fashion so that a parameter can be passed. -->
                <apex:commandLink >
                    <a href="javascript: CurrRequest('{!Request__c.Id}');" class="btn">New</a>               
                </apex:commandLink>
               
                <apex:commandLink >
                    <a href="javascript: SaveEntry();" class="btn">Save</a>               
                </apex:commandLink>

            </apex:pageBlockButtons>
           
             <!-- The following pageBlockTable segment defines the time entry rows that will be displayed. -->
            <apex:pageBlockTable value="{!TimeEntries}" var="entry" id="Entry_Table_List">
                <apex:column width="45" headerValue="Action">
                    <a href="javascript:if (window.confirm('Are you sure?')) DeleteEntry('{!entry.Id}');" style="font-weight:bold">Del</a>               
                </apex:column>   
                <apex:column width="70" headerValue="Activity">
                    <apex:inputField value="{!entry.Activity__c}"/>
                </apex:column>   
                <apex:column width="70" headerValue="Date Worked">
                    <apex:inputField value="{!entry.Date_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Hours">
                    <apex:inputField value="{!entry.Hours_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Worked">
                    <apex:inputField value="{!entry.Minutes_Worked__c}"/>
                </apex:column>   
                <apex:column headerValue="Work Description">
                    <apex:inputField style="width:100%" value="{!entry.Work_Description__c}" id="comment"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <!-- This action block is executed based on the 'Delete' button being clicked on. -->
        <apex:actionFunction action="{!del}" name="DeleteEntry" reRender="Time_Entry_List">
            <apex:param name="deleteEntryID" value="" assignTo="{!SelectedEntryID}"/>
        </apex:actionFunction>
       
         <!-- This action block is executed based on the 'New' button being clicked on. -->
        <apex:actionFunction action="{!add}" name="CurrRequest" reRender="Time_Entry_List">
            <apex:param name="addEntryID" value="" assignTo="{!ReqID}"/>
        </apex:actionFunction>

         <!-- This action block is executed based on the 'Save' button being clicked on. -->
        <apex:actionFunction action="{!save}" name="SaveEntry" reRender="Time_Entry_List"/>
       
     </apex:form>
    <!-- The following script code is used in order to fix the problem with the calendar autospawning. -->
    <script>
        var Coment=document.getElementById('{!$Component.theForm.block.sec.item.comment}');
    </script>   
</apex:page>

APEX CONTROLLER CLASS

public with sharing class TrController
{
    //This is the list for handling the group of time entries related to the parent object.
    public List<Time_Entry__c> TimeEntries {get;set;}
    //Used to get a hold of the entry record that is selected for deletion.
    public string SelectedEntryID {get;set;}
    //Used to get the parent request object ID from the Visual force page to the controller.
    public string ReqID {get;set;}
    public TrController(ApexPages.StandardController controller)
    {
        //Obtain the parent object Id from the the visualforce form.
        ReqId = Apexpages.currentPage().getparameters().get('Id');
        //SelectedEntryId = Apexpages.currentPage().getparameters().get('deleteEntryId');
        //Call the loaddata method to laod the time entries related to the parent object.
        LoadData();
     }
    public void LoadData()
    {
        //Obtain the first 15 bytes of the Parent Object ID to use for record selection.
        string RequestID = ReqId.substring(0, 15);
        //Load the related time entry records from the database.
        TimeEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c from Time_Entry__c WHERE Related_Object__c=:RequestID order by ID DESC];

    }
    public void save()
    {
        //Update the Salesforce database with the data entred.
        update TimeEntries;
    }
    public void add()
    {  
       //Obtain the first 15 bytes of the Parent Object ID to use for record identification.
        string RequestID = ReqId.substring(0, 15);
        //Build the default values to the new time entry record.
        Time_Entry__c entry = new Time_Entry__c(Activity__c='Research', Date_Worked__c=System.today(), Hours_Worked__c=' 0', Minutes_Worked__c='00', Related_Object__c=RequestID);
        //Insert the new default time entry row into the Salesforce database.
        Insert entry;
        //Call the method to reload the Visualforce list.
        LoadData();
    }
    public void del()
    {
     ExecuteDelete(SelectedEntryId);
    }
    public void ExecuteDelete(string selectedEntry)
    {
        //if we are missing the reference, then do nothing except return.
        if (selectedEntry == null)
        {
            return;
        }
        
        //If the record is within the collection, then delete it.
        Time_Entry__c tobeDeleted = null;
        for(Time_Entry__c a : TimeEntries)
        {
            string EntID = a.Id;
            string SelId = EntId.substring(0, 15);
        if (EntID == selectedEntry)
            {
                tobeDeleted = a;
                break;
            }
        }   
        //If account record found then delete it.
        if (tobeDeleted != null)
            {
                Delete toBeDeleted;
            }
        //Refresh the list
        LoadData();

    }

}

APEX TEST CLASS

@isTest
public class TrControllerTest
{
 static testMethod void testMethod1()
 {
  
    //Instantiate a new instance of the Custom Request Object.
        Request__c ReqObj = new Request__c();
    //Populate the name of the new request object.
        ReqObj.Name = 'Test request';
    //Populate 'What is being requested.
        ReqObj.What_is_being_requested__c = 'Entry to test apex code.';
    //Insert the new request object into Salesforce.
  insert ReqObj;             
  
 //Instantiate a new instance of the Time_Entry object.
  Time_Entry__c te = new Time_Entry__c();
    //Populate the required fields of the Time Entry object.
  te.Name ='Test';            
        te.Date_Worked__c = System.today();
        te.Hours_Worked__c = '01';
        te.Minutes_Worked__c = '15';
        te.Work_Description__c = 'This is a test entry';
        te.Activity__c = 'Research';
    //Insert the new Time_Entry object into Salesforce.
  insert te;              
  
    //Indicate the starting of the test process.
        Test.StartTest();
 
    //Post the Request ID of the Request object created.
            Apexpages.currentPage().getparameters().put('id', String.valueOf(ReqObj.Id));
    //Instantiate a new instance of the Request object standard controller.
       ApexPages.StandardController sc = new ApexPages.StandardController(ReqObj);
    //Instantiate a new instance of the Time Entry Controller that is related to the Standard controller.
        TrController testAccPlan = new TrController(sc);
   
    //Test the code within the 'save' method.
            testAccPlan.save(); 
    //Test the code within the 'add' method.
         testAccPlan.add();           
         //System.AssertEquals(NewEntryId, ReqObj.Id);
            
 //Obtain the object Id's for the row inserted in the database initially.    
         List<Time_Entry__c> deleteEntry = [select id from Time_Entry__c WHERE Work_Description__c = 'This is a test entry'];

 //Loop through the objects returned from the 'Select' statement and pass the Object Id's to the 'ExecuteDelete' class.    
        for(Time_Entry__c a : deleteEntry)
            {
                testAccPlan.ExecuteDelete(a.Id);
                //Leave the loop after one itteration.
                break;
            }
    
    //Execute the ExecuteDelete class with a 'Null' variable so that the additionally related code is tested.
        testAccPlan.ExecuteDelete(null);
  
    //Indicate the end of the test code.
        Test.StopTest();
 }
}
So I have a Visualforce page that I have created that is related to a standard controller and also an extension to an 'Apex' controller. I've taken the 'Trailhead' training on testing an Apex class, but I can't seem to successfully apply what I learned in the Trailhead tutorial to my project and get there to not be syntax errors in my test code. I have only working on my first Visualforce/Apex project for a week now, so I'd sure welcome any suggestions anyone might have. The primary Methods that I am calling from the Visualforce Page are 'Save', 'Add' and 'Delete', so any help in any of those methods that I could then apply to the others would be greatly appreciated.

VISUALFORCE CODE:
<apex:page standardController="Request__c" extensions="TrController" >
    <!-- The following code will fix a problem with the calendar autospawning when the time entries are displayed. -->
    <script>
        function setFocusOnLoad(){ Coment.focus(); }
    </script>
   
    <!--Because we will be defining 'Input' fields, we must wrap our code in a 'Form' block. -->
    <apex:form id="Time_Entry_Form">
        <apex:pageBlock title="CDCR - Salesforce Time Reporting for Requests" id="Time_Entry_List">
           
            <!-- The following pageBlockButtons segment defines the two buttons that appear at the top of the Time entry form. -->
            <apex:pageBlockButtons id="Button_area">
                <!-- The following Button is defined in a more complicated fashion so that a parameter can be passed. -->
                <apex:commandLink >
                    <a href="javascript: CurrRequest('{!Request__c.Id}');" class="btn">New</a>               
                </apex:commandLink>
               
                <apex:commandLink >
                    <a href="javascript: SaveEntry();" class="btn">Save</a>               
                </apex:commandLink>

            </apex:pageBlockButtons>
           
             <!-- The following pageBlockTable segment defines the time entry rows that will be displayed. -->
            <apex:pageBlockTable value="{!TimeEntries}" var="entry" id="Entry_Table_List">
                <apex:column width="45" headerValue="Action">
                    <a href="javascript:if (window.confirm('Are you sure?')) DeleteEntry('{!entry.Id}');" style="font-weight:bold">Del</a>               
                </apex:column>   
                <apex:column width="70" headerValue="Activity">
                    <apex:inputField value="{!entry.Activity__c}"/>
                </apex:column>   
                <apex:column width="70" headerValue="Date Worked">
                    <apex:inputField value="{!entry.Date_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Hours">
                    <apex:inputField value="{!entry.Hours_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Worked">
                    <apex:inputField value="{!entry.Minutes_Worked__c}"/>
                </apex:column>   
                <apex:column headerValue="Work Description">
                    <apex:inputField style="width:100%" value="{!entry.Work_Description__c}" id="comment"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <!-- This action block is executed based on the 'Delete' button being clicked on. -->
        <apex:actionFunction action="{!del}" name="DeleteEntry" reRender="Time_Entry_List">
            <apex:param name="EntryID" value="" assignTo="{!SelectedEntryID}"/>
        </apex:actionFunction>
       
         <!-- This action block is executed based on the 'New' button being clicked on. -->
        <apex:actionFunction action="{!add}" name="CurrRequest" reRender="Time_Entry_List">
            <apex:param name="EntryID" value="" assignTo="{!ReqID}"/>
        </apex:actionFunction>

         <!-- This action block is executed based on the 'Save' button being clicked on. -->
        <apex:actionFunction action="{!save}" name="SaveEntry" reRender="Time_Entry_List"/>
       
     </apex:form>
    <!-- The following script code is used in order to fix the problem with the calendar autospawning. -->
    <script>
        var Coment=document.getElementById('{!$Component.theForm.block.sec.item.comment}');
    </script>   
</apex:page>

CONTROLLER APEX CODE

public with sharing class TrController
{
    //This is the list for handling the group of time entries related to the parent object.
    public List<Time_Entry__c> TimeEntries {get;set;}
    //Used to get a hold of the entry record that is selected for deletion.
    public string SelectedEntryID {get;set;}
    //Used to get the parent request object ID from the Visual force page to the controller.
    public string ReqID {get;set;}
    public TrController(ApexPages.StandardController controller)
    {
        //Obtain the parent object Id from the the visualforce form.
        ReqId = Apexpages.currentPage().getparameters().get('Id');
        //Call the loaddata method to laod the time entries related to the parent object.
        LoadData();
     }
    public void LoadData()
    {
        //Obtain the first 15 bytes of the Parent Object ID to use for record selection.
        string RequestID = ReqId.substring(0, 15);
        //Load the related time entry records from the database.
        TimeEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c from Time_Entry__c WHERE Related_Object__c=:RequestID order by ID DESC];

    }
    public void save()
    {
        //Update the Salesforce database with the data entred.
        update TimeEntries;
    }
    public void add()
    {  
       //Obtain the first 15 bytes of the Parent Object ID to use for record identification.
        string RequestID = ReqId.substring(0, 15);
        //Build the default values to the new time entry record.
        Time_Entry__c entry = new Time_Entry__c(Activity__c='Research', Date_Worked__c=System.today(), Hours_Worked__c=' 0', Minutes_Worked__c='00', Related_Object__c=RequestID);
        //Insert the new default time entry row into the Salesforce database.
        Insert entry;
        //Call the method to reload the Visualforce list.
        LoadData();
    }
    public void del()
    {   
        //if we are missing the reference, then do nothing except return.
        if (SelectedEntryId == null)
        {
            return;
        }
        
        //If the record is within the collection, then delete it.
        Time_Entry__c tobeDeleted = null;
        for(Time_Entry__c a : TimeEntries)
        if (a.Id == SelectedEntryId)
            {
                tobeDeleted = a;
                break;
            }
        //If account record found then delete it.
        if (tobeDeleted != null)
            {
                Delete toBeDeleted;
            }
        //Refresh the list
        LoadData();

    }

}

Thank you in advance for your time.

Eric Anderson 
Hi there everyone,

I've looked through previous entries and couldn't find an entry that matched exactly what I was trying to do, so forgive me for yet another post.

I'm finding that my Visualforce page is not loading the rows correctly on the initial load. I've figured out that it is because there are no entries that match the 'null' parameter that is probably being used in my where clause. How do I pass a paremeter to my load routine on the initial load of the visual force page? I find that if I do an 'Insert' the desired table rows show up.  The code for my VF page and Controller are below:

VISUALFORCE PAGE

<apex:page standardController="Request__c" extensions="TrController" >
    <!--Because we will be defining 'Input' fields, we must wrap our code in a 'Form' block. -->
    <apex:form id="Time_Entry_Form">
        <apex:pageBlock title="CDCR - Salesforce Time Reporting for Requests" id="Time_Entry_List">
            <apex:pageBlockButtons id="Button_area">
                <!-- The following Button is defined in a more complicated fashion so that a parameter can be passed. -->
                <apex:commandButton >
                    <a href="javascript: CurrRequest('{!Request__c.Id}');" type="submit">New</a>               
                </apex:commandButton>
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            <div class="displayPeek">
                <label>Result of Peek:</label>
                <apex:outputText value="{!Request__c.Id}"/>
            </div>
            <apex:pageBlockTable value="{!TimeEntries}" var="entry" id="Entry_Table_List">
                <apex:column width="45" headerValue="Action">
                    <a href="javascript:if (window.confirm('Are you sure?')) DeleteEntry('{!entry.Id}');" style="font-weight:bold">Del</a>               
                </apex:column>   
                <apex:column headerValue="Related Object">
                    <apex:inputField style="width:100%" value="{!entry.Related_Object__c}"/>
                </apex:column>  
                <apex:column width="70" headerValue="Activity">
                    <apex:inputField value="{!entry.Activity__c}"/>
                </apex:column>   
                <apex:column width="30" headerValue="Date Worked">
                    <apex:inputField value="{!entry.Date_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Hours">
                    <apex:inputField value="{!entry.Hours_Worked__c}"/>
                </apex:column>   
                <apex:column width="20" headerValue="Worked">
                    <apex:inputField value="{!entry.Minutes_Worked__c}"/>
                </apex:column>   
                <apex:column headerValue="Work Description">
                    <apex:inputField style="width:100%" value="{!entry.Work_Description__c}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:actionFunction action="{!del}" name="DeleteEntry" reRender="Time_Entry_List">
            <apex:param name="EntryID" value="" assignTo="{!SelectedEntryID}"/>
        </apex:actionFunction>
        <apex:actionFunction action="{!add}" name="CurrRequest" reRender="Time_Entry_Form">
            <apex:param name="EntryID" value="" assignTo="{!ReqID}"/>
        </apex:actionFunction>

    </apex:form>
</apex:page>




CONTROLLER

public with sharing class TrController
{
    public List<Time_Entry__c> TimeEntries {get;set;}
    public string reqRslt {get;set;}
    public string showMessage {get;set;}
    //Used to get a hold of the entry record that is selected for deletion.
    public string SelectedEntryID {get;set;}
    public string ReqID {get;set;}
    public TrController(ApexPages.StandardController controller)
    {
        LoadData();
     }
    private void LoadData()
    {
        //Load the related time entry records from the database.
        TimeEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c from Time_Entry__c WHERE Related_Object__c=:ReqId order by ID DESC];

    }
    public void save()
    {
        //Update the Salesforce database with the data entred.
        update TimeEntries;
    }
    public void add()
    {  
        //The following line will obetain the request id (ReqId) that is passed from the VisualForce page
        string RequestID = ReqId;
        //Build the default values to the new time entry record.
        Time_Entry__c entry = new Time_Entry__c(Activity__c='Research', Date_Worked__c=System.today(), Hours_Worked__c=' 0', Minutes_Worked__c='00', Related_Object__c=RequestID);
        //Insert the new default time entry row into the Salesforce database.
        Insert entry;
        //Call the method to reload the Visualforce list.
        LoadData();
    }
    public void del()
    {   
        //if we are missing the reference, then do nothing except return.
        if (SelectedEntryId == null)
        {
            return;
        }
        
        //If the record is within the collection, then delete it.
        Time_Entry__c tobeDeleted = null;
        for(Time_Entry__c a : TimeEntries)
        if (a.Id == SelectedEntryId)
            {
                tobeDeleted = a;
                break;
            }
        //If account record found then delete it.
        if (tobeDeleted != null)
            {
                Delete toBeDeleted;
            }
        //Refresh the list
        LoadData();

    }

}  
I have only been working in Visualforce for a week, so forgive me if this is a stupid question.

I have a 'Custom Object' called 'Request__c'. I also have a custom object called 'Time_Entry__c' that is managed through a Visualforce page and is functionally a child of 'Request__c' and is displayed on the 'Request__c' form in Salesforce. I have some code where I am trying to pass the object id of the 'Request__c' object to the Apex method so that its value is included when I create a new instance (row) of the 'Time_Entry__c' object. However, the code that I have developed is not working. Please see the relevent code below. I would appreciate any help that I can get. Thank you so much.

VISUALFORCE code

<apex:page standardController="Request__c" extensions="TrController">
    <!--Because we will be defining 'Input' fields, we must wrap our code in a 'Form' block. -->
    <apex:form >
        <apex:pageBlock title="CDCR - Salesforce Time Reporting for Requests">
            <apex:pageBlockButtons >
                <!-- The following Button is defined in a more complicated fashion so that a parameter can be passed. -->
                <apex:commandButton >
                    <a href="javascript: CurrRequest('{!Request__c.Id}');" >New</a>               
                </apex:commandButton>
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>

...

       <apex:actionFunction action="{!add}" name="CurrRequest" reRender="">
            <apex:param name="EntryID" value="" assignTo="{!ReqID}"/>
        </apex:actionFunction>

    </apex:form>
</apex:page>

APEX Controller

public with sharing class TrController
{
    public List<Time_Entry__c> TimeEntries {get;set;}
    public string reqRslt {get;set;}
    public string showMessage {get;set;}
    //Used to get a hold of the entry record that is selected for deletion.
    public string SelectedEntryID {get;set;}
    public string ReqID {get;set;}
    public TrController(ApexPages.StandardController controller)
    {
        LoadData();
     }

...

    private void LoadData()
    {
        //Load the related time entry records from the database.
        //TimeEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c from Time_Entry__c WHERE name=:profileName order by ID DESC];

        TimeEntries = [select id, Activity__c, Date_Worked__c, Hours_Worked__c, Minutes_Worked__c, Work_Description__c, Related_Object__c from Time_Entry__c order by ID DESC];
    }
...

    public void add()
    {  
        //The following line will obetain the request id (ReqId) that is passed from the VisualForce page
        string RequestID = ReqId;
        //Build the default values to the new time entry record.
        Time_Entry__c entry = new Time_Entry__c(Activity__c='Research', Date_Worked__c=System.today(), Hours_Worked__c=' 0', Minutes_Worked__c='00', Related_Object__c=RequestID);
        //Insert the new default time entry row into the Salesforce database.
        Insert entry;
        //Call the method to reload the Visualforce list.
        LoadData();
    }


   
It has been requested of me that I create a 'Related list' that can be shared to multiple objects that can be used for our time entry. Much like 'Files', 'Groups', 'Notes'  and 'Open Activities' show up in all 'Standard' and 'Custom' objects, my management wants me to create a 'Related list' format that will show up as being available for 'Planting' in any of the objects that we desire such as 'Accounts', 'Contacts' and so on as well as any 'Custom objects' that we may define.

Please let me know how I can do this.

Thanks! - Eric-