• Chris Moynihan
  • NEWBIE
  • 20 Points
  • Member since 2015
  • Senior Solutions Engineer
  • Birst, Inc.


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 7
    Replies
I have two icons on my replacement page for a custom tab. One is from the enhanced list, and the other from section header.

Can I remove the icon from the enhanced list or from the section header? I only want one.

User-added image
 
<apex:page showHeader="true" tabstyle="SEActivity__c">
    <apex:sectionHeader title="SE Activities" subtitle="Home" />
    <apex:enhancedList type="SEActivity__c" height="600" rowsPerPage="50" />
</apex:page>



 
I am trying to write a test case for my page/controller. I've written test code for triggers before without a lot of trouble, but it's been a long time and I am having trouble getting my tests written. Below is my code, as well as where I am with my test code so far.

The page/controller let's me add multiple entries for a custom object so I can enter a bunch at once and then save them.

Any help and direction is much appreciated.

Controller:
public class MultiAddSEActivities
{
    
    // Holds the SE Activity records to be saved
    public List<SE_Activities__c>recList  = new List<SE_Activities__c>();
    
    // List of the recClass
    public List<recClass> actRecords
    {get;set;}
    
    // Indicates the row to be deleted
    public String selectedRowIndex
    {get;set;}  
    
    // # of records in the recClass list
    public Integer count = 0;
    
    // Save the records by adding the elements in the record class list to recList, return to the same page
    public PageReference Save()
    {
        PageReference pr = new PageReference('/a00/o');
        
        for(Integer j = 0;j<actRecords.size();j++)
        {
            recList.add(actRecords[j].seact);
        } 
        insert recList;
        pr.setRedirect(True);
        return pr;
    }
        
    // Add a row
    public void Add()
    {   
        count = count+1;
 
        // Call to the recClass constructor
        recClass objRecClass = new recClass(count);
        
        // Add the record to the recClass list
        actRecords.add(objRecClass);
    }
    
    // Add duplicate of last row
    public void dupe()
    {
        if (count == 0){
            return;
        }else{
            
            // Create new Record Class record
            recClass dupeRecord = new recClass(count+1);
            
            // Get duplicate record from temp list
            dupeRecord.seact = actRecords[count-1].seact.clone(false,true,false,false);
            
            // Add the record to the record class list
            actRecords.add(dupeRecord);
            
            count = count + 1;
        }
    }
    
    // Delete row
    public void Del()
    {
        
        // Find the matching record in the list and remove it
        Integer j = 0;
        while (j < actRecords.size())
        {
          if(actRecords.get(j).recCount == selectedRowIndex)
          {
            actRecords.remove(j);
            count = count - 1;
          }
          else
          {
            j++;
          }
        }

        // Reset recCount for each record in the list
        Integer r = 0;
        while (r < actRecords.size())
        {
           actRecords[r].recCount = String.valueOf(r+1);
           r++;
        }     
    }
    
    
    // Constructor
    public MultiAddSEActivities()
    {
        //ApexPages.StandardController ctlr
        actRecords = new List<recClass>();
        Add();
        selectedRowIndex = '0';   
    }


    // Record Class
    public class recClass
    {       
        // recCount acts as a index for a row. This will be helpful to identify the row to be deleted
        public String recCount
        {get;set;}

        public SE_Activities__c seact 
        {get;set;}

        // Record Class Constructor
        public recClass(Integer intCount)
        {
            // Set the index
            recCount = String.valueOf(intCount);     
            
            // Create a new SE Activity
            seact = new SE_Activities__c();
            
        }
    }
}

Test Code:
@isTest
public class controllerTests {

    public static testMethod void testMultiAddSEActivitiesPage(){
    
        PageReference pg = Page.MultiAddSEActivities;
        Test.setCurrentPage(pg);
        
        MultiAddSEActivities controller = new MultiAddSEActivities();
        String nextPage = controller.Save().getUrl();

        // Instantiate a new controller with all params on the page
        controller = new MultiAddSEActivities();
        controller.Add();
        controller.dupe();
        controller.Del();
        
        public List<SE_Activities__c> testList  = new List<SE_Activities__c>();
        
        // ?????
        
        nextPage = controller.Save().getUrl();

    }
}

Page:
<apex:page controller="MultiAddSEActivities" id="thePage">
<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>
        <apex:commandbutton value="Duplicate Last" action="{!Dupe}" rerender="pb1"/>
        <apex:commandbutton value="Save" action="{!Save}"/>
    </apex:pageBlockButtons>
    
    <apex:pageblock id="pb1">
            
        <apex:repeat value="{!actRecords}" var="e1" id="therepeat">
             <apex:panelGrid columns="8">
                
                <apex:panelGrid headerClass="Name" width="15px">
                    <apex:facet name="header">Delete</apex:facet>
                    <apex:commandButton value="x" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                    </apex:commandButton>
                </apex:panelGrid>   

                <apex:panelGrid title="SPD">
                    <apex:facet name="header">Activity Date</apex:facet>
                    <apex:inputfield value="{!e1.seact.Activity_Date__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Opportunity</apex:facet>
                    <apex:inputfield style="width:250px" value="{!e1.seact.OpportunityLink__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Type</apex:facet>
                    <apex:inputfield value="{!e1.seact.Type__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Hours</apex:facet>
                    <apex:inputfield style="width:30px" value="{!e1.seact.Hours__c}"/>
                </apex:panelGrid>
                                
                <apex:panelGrid >
                    <apex:facet name="header">Comments</apex:facet>
                    <apex:inputfield style="width:250px; height:12px" value="{!e1.seact.Comments__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Onsite</apex:facet>
                    <apex:inputfield value="{!e1.seact.Onsite__c}"/>
                </apex:panelGrid>
                
            </apex:panelgrid>
        </apex:repeat>
        
    </apex:pageBlock>        
</apex:pageblock>
</apex:form>
</apex:page>


 
I am building a page to allow entry of multiple records of a custom object (job).

On that page I have a Duplicate button that will add another record by duplicating what is in the last record.

I have a custom class with two elements (record #, job), and I maintain a List of this class, one class for each record on the page.

To duplicate, I create a new instance of my custom class recClass called dupe, then grab the last element in my recClass List, make dupe equal to that element, then increment the record # of dupe to reflect the correct number in the recClass List.

My issue is that when I set the record # to the new value, it also affects the record # of the previous record in the recClass List.
 
count = count+1;

// Create new blank class
recClass dupeRecord = new recClass(count);         

// Hold onto the record # until after the dupe
String tempRecCount = dupeRecord.recCount;

// Get last record in list, and copy it to the new record
dupeRecord = recList[count-2];

system.debug('Duped (copied) record is: '+dupeRecord);
system.debug('Original record is: '+recList[count-2]);

// This changes the new record, and the original that was duped
dupeRecord.recCount = tempRecCount;

system.debug('Record to be added: '+dupeRecord);
system.debug('Original record is: '+recList[count-2]);
            
// Add duped record to the end of the record list
recList.add(dupeRecord);

I've read about deepclone, but that seems to apply to sObjects, of which my custom class is not.
 
public class recClass
    {       
        /* recCount acts as a index for a row. Helpful to identify the row to be deleted */
        public String recCount
        {get;set;}

        public SE_Activities__c seact 
        {get;set;}

        /* Record Class Constructor */
        public recClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);     
            
            /*create a new SE Activity*/
            seact = new SE_Activities__c();
            
        }
    }

Any ideas?
I have two icons on my replacement page for a custom tab. One is from the enhanced list, and the other from section header.

Can I remove the icon from the enhanced list or from the section header? I only want one.

User-added image
 
<apex:page showHeader="true" tabstyle="SEActivity__c">
    <apex:sectionHeader title="SE Activities" subtitle="Home" />
    <apex:enhancedList type="SEActivity__c" height="600" rowsPerPage="50" />
</apex:page>



 
I am trying to write a test case for my page/controller. I've written test code for triggers before without a lot of trouble, but it's been a long time and I am having trouble getting my tests written. Below is my code, as well as where I am with my test code so far.

The page/controller let's me add multiple entries for a custom object so I can enter a bunch at once and then save them.

Any help and direction is much appreciated.

Controller:
public class MultiAddSEActivities
{
    
    // Holds the SE Activity records to be saved
    public List<SE_Activities__c>recList  = new List<SE_Activities__c>();
    
    // List of the recClass
    public List<recClass> actRecords
    {get;set;}
    
    // Indicates the row to be deleted
    public String selectedRowIndex
    {get;set;}  
    
    // # of records in the recClass list
    public Integer count = 0;
    
    // Save the records by adding the elements in the record class list to recList, return to the same page
    public PageReference Save()
    {
        PageReference pr = new PageReference('/a00/o');
        
        for(Integer j = 0;j<actRecords.size();j++)
        {
            recList.add(actRecords[j].seact);
        } 
        insert recList;
        pr.setRedirect(True);
        return pr;
    }
        
    // Add a row
    public void Add()
    {   
        count = count+1;
 
        // Call to the recClass constructor
        recClass objRecClass = new recClass(count);
        
        // Add the record to the recClass list
        actRecords.add(objRecClass);
    }
    
    // Add duplicate of last row
    public void dupe()
    {
        if (count == 0){
            return;
        }else{
            
            // Create new Record Class record
            recClass dupeRecord = new recClass(count+1);
            
            // Get duplicate record from temp list
            dupeRecord.seact = actRecords[count-1].seact.clone(false,true,false,false);
            
            // Add the record to the record class list
            actRecords.add(dupeRecord);
            
            count = count + 1;
        }
    }
    
    // Delete row
    public void Del()
    {
        
        // Find the matching record in the list and remove it
        Integer j = 0;
        while (j < actRecords.size())
        {
          if(actRecords.get(j).recCount == selectedRowIndex)
          {
            actRecords.remove(j);
            count = count - 1;
          }
          else
          {
            j++;
          }
        }

        // Reset recCount for each record in the list
        Integer r = 0;
        while (r < actRecords.size())
        {
           actRecords[r].recCount = String.valueOf(r+1);
           r++;
        }     
    }
    
    
    // Constructor
    public MultiAddSEActivities()
    {
        //ApexPages.StandardController ctlr
        actRecords = new List<recClass>();
        Add();
        selectedRowIndex = '0';   
    }


    // Record Class
    public class recClass
    {       
        // recCount acts as a index for a row. This will be helpful to identify the row to be deleted
        public String recCount
        {get;set;}

        public SE_Activities__c seact 
        {get;set;}

        // Record Class Constructor
        public recClass(Integer intCount)
        {
            // Set the index
            recCount = String.valueOf(intCount);     
            
            // Create a new SE Activity
            seact = new SE_Activities__c();
            
        }
    }
}

Test Code:
@isTest
public class controllerTests {

    public static testMethod void testMultiAddSEActivitiesPage(){
    
        PageReference pg = Page.MultiAddSEActivities;
        Test.setCurrentPage(pg);
        
        MultiAddSEActivities controller = new MultiAddSEActivities();
        String nextPage = controller.Save().getUrl();

        // Instantiate a new controller with all params on the page
        controller = new MultiAddSEActivities();
        controller.Add();
        controller.dupe();
        controller.Del();
        
        public List<SE_Activities__c> testList  = new List<SE_Activities__c>();
        
        // ?????
        
        nextPage = controller.Save().getUrl();

    }
}

Page:
<apex:page controller="MultiAddSEActivities" id="thePage">
<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >
        <apex:commandbutton value="Add" action="{!Add}" rerender="pb1"/>
        <apex:commandbutton value="Duplicate Last" action="{!Dupe}" rerender="pb1"/>
        <apex:commandbutton value="Save" action="{!Save}"/>
    </apex:pageBlockButtons>
    
    <apex:pageblock id="pb1">
            
        <apex:repeat value="{!actRecords}" var="e1" id="therepeat">
             <apex:panelGrid columns="8">
                
                <apex:panelGrid headerClass="Name" width="15px">
                    <apex:facet name="header">Delete</apex:facet>
                    <apex:commandButton value="x" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                    </apex:commandButton>
                </apex:panelGrid>   

                <apex:panelGrid title="SPD">
                    <apex:facet name="header">Activity Date</apex:facet>
                    <apex:inputfield value="{!e1.seact.Activity_Date__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Opportunity</apex:facet>
                    <apex:inputfield style="width:250px" value="{!e1.seact.OpportunityLink__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Type</apex:facet>
                    <apex:inputfield value="{!e1.seact.Type__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Hours</apex:facet>
                    <apex:inputfield style="width:30px" value="{!e1.seact.Hours__c}"/>
                </apex:panelGrid>
                                
                <apex:panelGrid >
                    <apex:facet name="header">Comments</apex:facet>
                    <apex:inputfield style="width:250px; height:12px" value="{!e1.seact.Comments__c}"/>
                </apex:panelGrid>
                
                <apex:panelGrid >
                    <apex:facet name="header">Onsite</apex:facet>
                    <apex:inputfield value="{!e1.seact.Onsite__c}"/>
                </apex:panelGrid>
                
            </apex:panelgrid>
        </apex:repeat>
        
    </apex:pageBlock>        
</apex:pageblock>
</apex:form>
</apex:page>