• anna425912
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 7
    Replies
I have a search page that returns a list in a PageBlockTable using a wrapper class.  It has an inputCheckbox and a number input.  Once selected the user clicks a commandButton to decide what to do with the checked rows.  However, not all of the checked rows are being returned and the changed quantities are also not being returned for all the rows. If I select rows without selecting the top one, then it doesn't register that any have been chosen.  The odd thing is that it is working perfectly in one of my sandboxes, but once I moved it to another (same exact code, I swear), it's no longer working. So I decided to try another sandbox and it seems to behave differently there as well.  I've been banging my head against a wall about this for a few days so I appreciate any help!! Thanks!

Here are portiosn of the code which are causing me issues: 

part of the visualforce with pageblocktable:
<apex:pageBlock mode="detail" id="results">
    <div style="width: 100%; overflow:hidden;">
        <div style="align:center;">
            <table>
                <tr>
                    <td>
                        <apex:commandButton action="{!additemSelections}" value="Add Selected items" style="width:150px" status="loading"/>
                        <div class="divider"/>
                        <apex:commandButton action="{!goToOpp}" value="Return to Opportunity" style="width:150px"/>
                    </td>
                </tr>
            </table>
        </div>
    </div>                                        
    <div style="width: 100%; overflow:hidden;">                                       
        <p style="font-size:20px; color:#585858">
        <apex:actionStatus id="loading" startText="Loading..." />
        </p>
    </div>
    <apex:pageBlockTable value="{!finalzlist}" var="z" id="itemtable">
        <apex:column width="55px" id="column2">
            <apex:facet name="header">
                <apex:commandLink value="{!selectTitle}" rerender="results,debug" id="selectAll" action="{!selectAll}" status="loading"/>
            </apex:facet>
        <!-- Input checkbox that is not always working -->
            <apex:inputCheckbox id="cbid" value="{!z.cb}" disabled="{!z.disabled}" onchange="checkValidation({!z.idx},{!z.Inventory_Available1},{!z.name1})"/>
        </apex:column>                                                     
        <apex:column >
            <apex:facet name="header">
                Quantity
            </apex:facet>
            <div id="{!z.name1}div" style="color:red; font-weight:bold"></div>
        <!-- Input number that is not always working -->
            <apex:input type="number" value="{!z.quantity}" id="quanId" onchange="validation({!z.idx},{!z.Inventory_Available1},{!z.name1});" disabled="{!z.disabled}" />
        </apex:column>                                           
    </apex:pageBlockTable>
</apex:pageBlock>
Javascript that runs onchange:
<script type="text/javascript">
        function validation(index,avail,item) {
            var divid = item + 'div';
            var newid = 'j_id0:f:results:itemtable:'+index+':quanId';
            var quan = document.getElementById(newid).value;
            if(quan > avail) {
                var errormessage = 'Quantity must be '+avail+' or less. item will not be added to cart.';
                document.getElementById(divid).innerHTML = errormessage;
                document.getElementById(newid).style.color = "red";
            } else {
                document.getElementById(divid).innerHTML = "";
                document.getElementById(newid).style.color = "black";
            }
        }
        function checkValidation(index,avail,item) {
            var checkboxId = 'j_id0:f:results:itemtable:'+index+':cbid';
            var checked = document.getElementById(checkboxId).checked;
            if(checked) {
                var quanId = 'j_id0:f:results:itemtable:'+index+':quanId';
                quan = document.getElementById(quanId).value;
                var divid = item + 'div';
                if(quan == 0) {
                    var errormessage = 'Please enter a quantity greater than 0. item will not be added to cart.';
                    document.getElementById(divid).innerHTML = errormessage;
                    document.getElementById(quanId).style.color = "red";
                } 
            } else {
                validation(index,avail,item);
            }
        }
    </script>

Controller: 
 
public with sharing class itemSearchController{

    public String oppId{
        get { return System.currentPageReference().getParameters().get('oppId'); }
        set;
    }
    public List<Inventory_Object__c> newitems {get;set;}
    public List<Inventory_Object__c> itemCodes {get;set;}
    public String soql {get;set;}
    public Integer removeitemIDX {get; set;}
    public Decimal totalInventory {get; set;}
    public Decimal totalInventoryActive {get; set;}
    public Decimal totalSelectedQuantity {get; set;}
    public Map<String,Id> zMap { get; set; }
    public String selectTitle {get; set;}
    public List<item_Code_Selection__c> newZCSList {get; set;}
    public Boolean isSubmitting {get; set;}
    public List<itemCodeClass> finalzlist {get; set;}
    public List<itemToAdd> itemsToAdd {get; set;}
    public Decimal totalConfirmPrice {get; set;}
    public Integer totalConfirmQuantity {get; set;}

    public class itemCodeClass {
        public String name1 {get; set;}
        public String msa1 {get; set;}
        public String city1 {get; set;}
        public String state1 {get; set;}
        public String id1 {get; set;}
        public Decimal Inventory_Available1 {get; set;}
        public Boolean cb {get; set;}
        public Boolean disabled {get; set;}
        public Integer quantity {get; set;}
        public Decimal Inventory_Active1 {get; set;}
        public Decimal List_Price1 {get; set;}
        public Integer idx {get; set;}
        public itemCodeClass(String name1, String msa1, String city1, String state1, String id1, Decimal Inventory_Available1, Boolean cb, Boolean disabled, Integer quantity, Decimal Inventory_Active1, Decimal List_Price1, Integer idx) {
            this.name1 = name1;
            this.msa1 = msa1;
            this.city1 = city1;
            this.state1 = state1;
            this.id1 = id1;
            this.Inventory_Available1 = Inventory_Available1;
            this.cb = cb;
            this.disabled = disabled;
            this.quantity = quantity;
            this.Inventory_Active1 = Inventory_Active1;
            this.List_Price1 = List_Price1;
            this.idx = idx;
        }
    }
    public itemSearchController() {
        selectTitle = 'Select All';
        totalSelectedQuantity = 0;
        isSubmitting = false;
        if(oppId == null) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'In order to add items, please access this page through the Opportunity.'));
        }
    }

    public PageReference additemSelections() {
        Map<Id,itemCodeClass> itemM2 = new Map<Id,itemCodeClass>();
        if(finalzlist != null ) {
            for(itemCodeClass z :finalzlist) {
                if(z.cb == true && z.quantity > 0 && z.quantity <= z.Inventory_Available1) {
                    itemM2.put(z.Id1,z);
                } else if (z.cb == true && z.quantity == 0) {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please make sure all selected items have a quantity greater than 0.'));
                    return null;
                }
            }
            List<item_Code_Selection__c> zcslist = new List<item_Code_Selection__c>();
            List<itemToAdd> zs = new List<itemToAdd>();
            if(itemM2.size() == 0 ) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least 1 item code with a quantity less than or equal to the availability.'));
                return null;
            } else {
                isSubmitting = true;
                Inventory_Object__c[] zca = [SELECT Id FROM Inventory_Object__c WHERE Id in :itemM2.keyset()];
                RecordType rna = [SELECT Id, Name FROM RecordType WHERE sObjectType = 'item_Code_Selection__c' and Name = 'New - Inventory'];
                Decimal tcp = 0.0;
                Integer tcq = 0;
                for(Inventory_Object__c za :zca ) {
                    itemCodeClass zcc = itemM2.get(za.Id);
                    item_Code_Selection__c z = new item_Code_Selection__c(Opportunity__c=oppId,Inventory_Object__c=za.Id,RecordTypeId=rna.Id,Discount__c=0.0,Quantity__c=zcc.quantity);
                    Decimal tp = zcc.quantity*zcc.List_Price1;
                    tcp = tcp + tp;
                    tcq = tcq + zcc.quantity;
                    zs.add(new itemToAdd(zcc.name1,zcc.quantity,zcc.List_Price1,tp)); 
                    zcslist.add(z);                
                }
                itemsToAdd = zs;
                totalConfirmQuantity = tcq;
                totalConfirmPrice = tcp;
            }
            if(zcslist.size() > 0 ) {
                newZCSList = zcslist;            
            } 
            return null; 
        } else {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please search for and select at least 1 item code.'));
            return null;
        }

    }

}




 
I'm trying to increase our code coverage percentage and finding many issues with actually determining what a class or trigger's coverage is. My current frustration is with a specific class and test.  In our full copy sandbox, I'm getting 96% coverage, 24/25 lines. In production, I'm getting 57% coverage, 16/28 lines.  I know that one of those lines (the one showing up in fullcopy) is actually uncovered; however the other lines that are showing as uncovered in production are close brackets and blank lines.  I tried clearing all test history as that was a suggestion, but it did not fix the problem.  Additionally, when I run the test to cover that class, and click on the specific methods to see all the classes and triggers that it covers, it says 80% coverage, 20/25 lines.  On the class page, it shows the 57% number.  
I have an old scheduled class that I need to delete and some related classes to edit.  They currently get this error because there are over 1 million cron jobs with status = "deleted". Unfortunately I haven't found a way to delete all those classes without taking a long time.  In the past, Salesforce support will just "run the scrutiny" on the sandboxes or production environment to fix this. The customer support rep directed me here because they won't address it.  I plan to delete delete these old classes since our new scheduled classes are written to be editable.  Is there someone from Salesforce that can "run the scrutiny" so that I can delete these classes? 
We are currently unable to deploy any change sets because our current code coverage is at 72%.  I have tested deploying just a single field on an almost untouched object and get the 72%. I'm wondering how can production get below 75% if all classes and test classes have to be deployed and they won't be deployed if it causes code coverage to go below 75%.  Is it possible that Flows or Process Builder, which can just be created in production, count towards code coverage? 
I would like my visualforce pages on the page layout to not slow down the loading of the entire page.  Is there some way I can make the entire VF page just load asynchronously.  It seems to work if I create another VF that puts these VF pages into an iFrame, but that seems like a silly workaround since it is basically creating 2 visualforce pages for every 1. 
I have a many to many relationship between my account records, and I am trying to show information from related objects on the same account record.  So if you're looking at an account, you can see the related accounts (related through the junction object) and their related opportunities.  I'm exploring consoles and visualforce pages, and looking for the easiest way to do this because it's a very rushed project.  Are there any visualforce tags that already do this without a ton of customized markup? 
I have a class that has a future call that first has a try which has a callout in it, a catch that sends an email notification, and a finally which updates a custom setting.  However, I am getting cases where the try seems like it should have worked because I'm not getting an email notification from the catch statement, but the finally portion fails to update the custom setting. Then when I go to check if the try portion succeeded, the records haven't been updated.  
I have a before insert, before update trigger on the contact that is causing issues when a lead is converted.  I don't need the triggers to run on lead conversion though so how can I write this into my trigger or class?
I have a search page that returns a list in a PageBlockTable using a wrapper class.  It has an inputCheckbox and a number input.  Once selected the user clicks a commandButton to decide what to do with the checked rows.  However, not all of the checked rows are being returned and the changed quantities are also not being returned for all the rows. If I select rows without selecting the top one, then it doesn't register that any have been chosen.  The odd thing is that it is working perfectly in one of my sandboxes, but once I moved it to another (same exact code, I swear), it's no longer working. So I decided to try another sandbox and it seems to behave differently there as well.  I've been banging my head against a wall about this for a few days so I appreciate any help!! Thanks!

Here are portiosn of the code which are causing me issues: 

part of the visualforce with pageblocktable:
<apex:pageBlock mode="detail" id="results">
    <div style="width: 100%; overflow:hidden;">
        <div style="align:center;">
            <table>
                <tr>
                    <td>
                        <apex:commandButton action="{!additemSelections}" value="Add Selected items" style="width:150px" status="loading"/>
                        <div class="divider"/>
                        <apex:commandButton action="{!goToOpp}" value="Return to Opportunity" style="width:150px"/>
                    </td>
                </tr>
            </table>
        </div>
    </div>                                        
    <div style="width: 100%; overflow:hidden;">                                       
        <p style="font-size:20px; color:#585858">
        <apex:actionStatus id="loading" startText="Loading..." />
        </p>
    </div>
    <apex:pageBlockTable value="{!finalzlist}" var="z" id="itemtable">
        <apex:column width="55px" id="column2">
            <apex:facet name="header">
                <apex:commandLink value="{!selectTitle}" rerender="results,debug" id="selectAll" action="{!selectAll}" status="loading"/>
            </apex:facet>
        <!-- Input checkbox that is not always working -->
            <apex:inputCheckbox id="cbid" value="{!z.cb}" disabled="{!z.disabled}" onchange="checkValidation({!z.idx},{!z.Inventory_Available1},{!z.name1})"/>
        </apex:column>                                                     
        <apex:column >
            <apex:facet name="header">
                Quantity
            </apex:facet>
            <div id="{!z.name1}div" style="color:red; font-weight:bold"></div>
        <!-- Input number that is not always working -->
            <apex:input type="number" value="{!z.quantity}" id="quanId" onchange="validation({!z.idx},{!z.Inventory_Available1},{!z.name1});" disabled="{!z.disabled}" />
        </apex:column>                                           
    </apex:pageBlockTable>
</apex:pageBlock>
Javascript that runs onchange:
<script type="text/javascript">
        function validation(index,avail,item) {
            var divid = item + 'div';
            var newid = 'j_id0:f:results:itemtable:'+index+':quanId';
            var quan = document.getElementById(newid).value;
            if(quan > avail) {
                var errormessage = 'Quantity must be '+avail+' or less. item will not be added to cart.';
                document.getElementById(divid).innerHTML = errormessage;
                document.getElementById(newid).style.color = "red";
            } else {
                document.getElementById(divid).innerHTML = "";
                document.getElementById(newid).style.color = "black";
            }
        }
        function checkValidation(index,avail,item) {
            var checkboxId = 'j_id0:f:results:itemtable:'+index+':cbid';
            var checked = document.getElementById(checkboxId).checked;
            if(checked) {
                var quanId = 'j_id0:f:results:itemtable:'+index+':quanId';
                quan = document.getElementById(quanId).value;
                var divid = item + 'div';
                if(quan == 0) {
                    var errormessage = 'Please enter a quantity greater than 0. item will not be added to cart.';
                    document.getElementById(divid).innerHTML = errormessage;
                    document.getElementById(quanId).style.color = "red";
                } 
            } else {
                validation(index,avail,item);
            }
        }
    </script>

Controller: 
 
public with sharing class itemSearchController{

    public String oppId{
        get { return System.currentPageReference().getParameters().get('oppId'); }
        set;
    }
    public List<Inventory_Object__c> newitems {get;set;}
    public List<Inventory_Object__c> itemCodes {get;set;}
    public String soql {get;set;}
    public Integer removeitemIDX {get; set;}
    public Decimal totalInventory {get; set;}
    public Decimal totalInventoryActive {get; set;}
    public Decimal totalSelectedQuantity {get; set;}
    public Map<String,Id> zMap { get; set; }
    public String selectTitle {get; set;}
    public List<item_Code_Selection__c> newZCSList {get; set;}
    public Boolean isSubmitting {get; set;}
    public List<itemCodeClass> finalzlist {get; set;}
    public List<itemToAdd> itemsToAdd {get; set;}
    public Decimal totalConfirmPrice {get; set;}
    public Integer totalConfirmQuantity {get; set;}

    public class itemCodeClass {
        public String name1 {get; set;}
        public String msa1 {get; set;}
        public String city1 {get; set;}
        public String state1 {get; set;}
        public String id1 {get; set;}
        public Decimal Inventory_Available1 {get; set;}
        public Boolean cb {get; set;}
        public Boolean disabled {get; set;}
        public Integer quantity {get; set;}
        public Decimal Inventory_Active1 {get; set;}
        public Decimal List_Price1 {get; set;}
        public Integer idx {get; set;}
        public itemCodeClass(String name1, String msa1, String city1, String state1, String id1, Decimal Inventory_Available1, Boolean cb, Boolean disabled, Integer quantity, Decimal Inventory_Active1, Decimal List_Price1, Integer idx) {
            this.name1 = name1;
            this.msa1 = msa1;
            this.city1 = city1;
            this.state1 = state1;
            this.id1 = id1;
            this.Inventory_Available1 = Inventory_Available1;
            this.cb = cb;
            this.disabled = disabled;
            this.quantity = quantity;
            this.Inventory_Active1 = Inventory_Active1;
            this.List_Price1 = List_Price1;
            this.idx = idx;
        }
    }
    public itemSearchController() {
        selectTitle = 'Select All';
        totalSelectedQuantity = 0;
        isSubmitting = false;
        if(oppId == null) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'In order to add items, please access this page through the Opportunity.'));
        }
    }

    public PageReference additemSelections() {
        Map<Id,itemCodeClass> itemM2 = new Map<Id,itemCodeClass>();
        if(finalzlist != null ) {
            for(itemCodeClass z :finalzlist) {
                if(z.cb == true && z.quantity > 0 && z.quantity <= z.Inventory_Available1) {
                    itemM2.put(z.Id1,z);
                } else if (z.cb == true && z.quantity == 0) {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please make sure all selected items have a quantity greater than 0.'));
                    return null;
                }
            }
            List<item_Code_Selection__c> zcslist = new List<item_Code_Selection__c>();
            List<itemToAdd> zs = new List<itemToAdd>();
            if(itemM2.size() == 0 ) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least 1 item code with a quantity less than or equal to the availability.'));
                return null;
            } else {
                isSubmitting = true;
                Inventory_Object__c[] zca = [SELECT Id FROM Inventory_Object__c WHERE Id in :itemM2.keyset()];
                RecordType rna = [SELECT Id, Name FROM RecordType WHERE sObjectType = 'item_Code_Selection__c' and Name = 'New - Inventory'];
                Decimal tcp = 0.0;
                Integer tcq = 0;
                for(Inventory_Object__c za :zca ) {
                    itemCodeClass zcc = itemM2.get(za.Id);
                    item_Code_Selection__c z = new item_Code_Selection__c(Opportunity__c=oppId,Inventory_Object__c=za.Id,RecordTypeId=rna.Id,Discount__c=0.0,Quantity__c=zcc.quantity);
                    Decimal tp = zcc.quantity*zcc.List_Price1;
                    tcp = tcp + tp;
                    tcq = tcq + zcc.quantity;
                    zs.add(new itemToAdd(zcc.name1,zcc.quantity,zcc.List_Price1,tp)); 
                    zcslist.add(z);                
                }
                itemsToAdd = zs;
                totalConfirmQuantity = tcq;
                totalConfirmPrice = tcp;
            }
            if(zcslist.size() > 0 ) {
                newZCSList = zcslist;            
            } 
            return null; 
        } else {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please search for and select at least 1 item code.'));
            return null;
        }

    }

}




 
I'm trying to increase our code coverage percentage and finding many issues with actually determining what a class or trigger's coverage is. My current frustration is with a specific class and test.  In our full copy sandbox, I'm getting 96% coverage, 24/25 lines. In production, I'm getting 57% coverage, 16/28 lines.  I know that one of those lines (the one showing up in fullcopy) is actually uncovered; however the other lines that are showing as uncovered in production are close brackets and blank lines.  I tried clearing all test history as that was a suggestion, but it did not fix the problem.  Additionally, when I run the test to cover that class, and click on the specific methods to see all the classes and triggers that it covers, it says 80% coverage, 20/25 lines.  On the class page, it shows the 57% number.  
I have an old scheduled class that I need to delete and some related classes to edit.  They currently get this error because there are over 1 million cron jobs with status = "deleted". Unfortunately I haven't found a way to delete all those classes without taking a long time.  In the past, Salesforce support will just "run the scrutiny" on the sandboxes or production environment to fix this. The customer support rep directed me here because they won't address it.  I plan to delete delete these old classes since our new scheduled classes are written to be editable.  Is there someone from Salesforce that can "run the scrutiny" so that I can delete these classes? 
We are currently unable to deploy any change sets because our current code coverage is at 72%.  I have tested deploying just a single field on an almost untouched object and get the 72%. I'm wondering how can production get below 75% if all classes and test classes have to be deployed and they won't be deployed if it causes code coverage to go below 75%.  Is it possible that Flows or Process Builder, which can just be created in production, count towards code coverage? 
I have a many to many relationship between my account records, and I am trying to show information from related objects on the same account record.  So if you're looking at an account, you can see the related accounts (related through the junction object) and their related opportunities.  I'm exploring consoles and visualforce pages, and looking for the easiest way to do this because it's a very rushed project.  Are there any visualforce tags that already do this without a ton of customized markup? 
I have a class that has a future call that first has a try which has a callout in it, a catch that sends an email notification, and a finally which updates a custom setting.  However, I am getting cases where the try seems like it should have worked because I'm not getting an email notification from the catch statement, but the finally portion fails to update the custom setting. Then when I go to check if the try portion succeeded, the records haven't been updated.  
I have a before insert, before update trigger on the contact that is causing issues when a lead is converted.  I don't need the triggers to run on lead conversion though so how can I write this into my trigger or class?