• Mishael Legaspi
  • NEWBIE
  • 25 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
Upon checking the code coverage of our APEX Classes, we've noticed that a few of our actual Test Classes are evaluated as well. We found out that this is because of the non-test methods with parameters in our Test Classes. These methods are really just helper functions for the Test Classes, but it's frustating that they are the ones that cause the Test Classes to be evaluated in the overall code coverage numbers. (as described in https://help.salesforce.com/apex/HTViewSolution?urlname=Why-is-a-Test-class-evaluated-as-part-of-the-Organization-s-Code-Coverage&language=en_US (https://help.salesforce.com/apex/HTViewSolution?urlname=Why-is-a-Test-class-evaluated-as-part-of-the-Organization-s-Code-Coverage&language=en_US))

Is there any work around here? We also found out that the same pattern is actually used in the examples from the Force.com Apex Code Developer's Guide and the APEX Workbook. See https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_testing_1.htm and https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_utility_classes.htm. Does this mean that we also have to create test classes for those test helper methods?

Thanks in advance,
Mishael

 
Hi all,

I'm using pageBlockTable to display rows of an inner class in my controller. Now, I also want every row to have an option to be deleted. I found solutions online similar to http://sfdcsrini.blogspot.com/2014/12/adding-and-deleting-rows-dynamically-in.html . But I would like to avoid using apex:variable because I think it's not that straightforward. So I tried to use a Map instead of a List of Row objects where the keys are the rowId of the Row objects. 

Here's my controller code:
public class TestInputController {
    
    public Map<Integer, Row> rows { get; set; }
    
    public TestInputController() {
        rows = new Map<Integer, Row>();
    }
    
    public void addRow() {
        Integer rowId = rows.size();
        rows.put(rowId , new Row(rowId));
    }
    
    public void removeRow() {
        rows.remove(Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIdToRemove')));
    }
    
    public class Row {
        public Integer rowId { get; set; }
        public Row(Integer rowId) {
            this.rowId = rowId;
        }
    }

}

And here's my visualforce code:
<apex:page controller="TestInputController" docType="html-5.0">
    <apex:form >        
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!rows}" var="rid" id="tablet">
                    <apex:column headerValue="ID">
                        <apex:input type="number" value="{!rows[rid].rowId}" />
                    </apex:column>
                    <apex:column headerValue="Action">
                        <apex:commandButton action="{!removeRow}" value="x" rerender="tablet">
                            <apex:param value="{!rows[rid].rowId}" name="rowIdToRemove" />
                        </apex:commandButton>
                    </apex:column>
                </apex:pageBlockTable>
                <apex:pageBlockSectionItem >
                    <apex:commandButton value="Add Row" action="{!addRow}" rerender="tablet"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Unfortunately, when I try to save the VisualForce page, I get the error:
Error: Expected input type 'text', got 'number' for Id data type

I figured that this is the line that caused the error:
<apex:input type="number" value="{!rows[rid].rowId}" />

I know that I can go back to the solution I found online regarding deleting rows, but I just don't get it why I'm getting this error. When I was using Lists before, the line
<apex:input type="number" value="{!row.rowId}" />
works (where row is the var name i used in the pageBlockTable). Am I missing something here? Or is this a bug?

Thanks,
Mishael
Upon checking the code coverage of our APEX Classes, we've noticed that a few of our actual Test Classes are evaluated as well. We found out that this is because of the non-test methods with parameters in our Test Classes. These methods are really just helper functions for the Test Classes, but it's frustating that they are the ones that cause the Test Classes to be evaluated in the overall code coverage numbers. (as described in https://help.salesforce.com/apex/HTViewSolution?urlname=Why-is-a-Test-class-evaluated-as-part-of-the-Organization-s-Code-Coverage&language=en_US (https://help.salesforce.com/apex/HTViewSolution?urlname=Why-is-a-Test-class-evaluated-as-part-of-the-Organization-s-Code-Coverage&language=en_US))

Is there any work around here? We also found out that the same pattern is actually used in the examples from the Force.com Apex Code Developer's Guide and the APEX Workbook. See https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_testing_1.htm and https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_utility_classes.htm. Does this mean that we also have to create test classes for those test helper methods?

Thanks in advance,
Mishael

 
Hi all,

I'm using pageBlockTable to display rows of an inner class in my controller. Now, I also want every row to have an option to be deleted. I found solutions online similar to http://sfdcsrini.blogspot.com/2014/12/adding-and-deleting-rows-dynamically-in.html . But I would like to avoid using apex:variable because I think it's not that straightforward. So I tried to use a Map instead of a List of Row objects where the keys are the rowId of the Row objects. 

Here's my controller code:
public class TestInputController {
    
    public Map<Integer, Row> rows { get; set; }
    
    public TestInputController() {
        rows = new Map<Integer, Row>();
    }
    
    public void addRow() {
        Integer rowId = rows.size();
        rows.put(rowId , new Row(rowId));
    }
    
    public void removeRow() {
        rows.remove(Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIdToRemove')));
    }
    
    public class Row {
        public Integer rowId { get; set; }
        public Row(Integer rowId) {
            this.rowId = rowId;
        }
    }

}

And here's my visualforce code:
<apex:page controller="TestInputController" docType="html-5.0">
    <apex:form >        
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!rows}" var="rid" id="tablet">
                    <apex:column headerValue="ID">
                        <apex:input type="number" value="{!rows[rid].rowId}" />
                    </apex:column>
                    <apex:column headerValue="Action">
                        <apex:commandButton action="{!removeRow}" value="x" rerender="tablet">
                            <apex:param value="{!rows[rid].rowId}" name="rowIdToRemove" />
                        </apex:commandButton>
                    </apex:column>
                </apex:pageBlockTable>
                <apex:pageBlockSectionItem >
                    <apex:commandButton value="Add Row" action="{!addRow}" rerender="tablet"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Unfortunately, when I try to save the VisualForce page, I get the error:
Error: Expected input type 'text', got 'number' for Id data type

I figured that this is the line that caused the error:
<apex:input type="number" value="{!rows[rid].rowId}" />

I know that I can go back to the solution I found online regarding deleting rows, but I just don't get it why I'm getting this error. When I was using Lists before, the line
<apex:input type="number" value="{!row.rowId}" />
works (where row is the var name i used in the pageBlockTable). Am I missing something here? Or is this a bug?

Thanks,
Mishael

I'm having trouble using the new html5 compliant apex:input field.  I'm working with maps and trying to set a number in the value part of the map, related to a corresponding Id key.  The map is called "prodQty" and an entry in the map might look like {XXXXXXXXXXXXXXXXXX,10} so the Key is an Id and the value is a number.

 

Here is a sample of what works using a normal input:text field:

 

<apex:inputText value="{!prodQty[p.Id]}" />

 All this does on the VF page is simply create an inputText field and display the corresponding number from the map.  I can change that number and it updates the map no problem.

 

I wanted to use the HTML5 number type and so set it up with this code:

 

<apex:input type="number" value="{!prodQty[p.Id]}" />

 Looks pretty standard to me, but I get this error:

 

Expected input type 'text', got 'number' for Id data type

 

It seems to be pulling through the key of the map rather than the value which is odd, because with a standard inputText component the value syntax works perfectly so why does the new component not recognise that I'm pulling through a number instead of an Id?  Is it impossible to use this new component with a map value?  It'll be an unfortunate limitation if that's the case!

 

Thanks for any advice.