• Brookesy
  • 0 Points
  • Member since 2009

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 1

Iv been having some issues getting complete coverage on the piece of code below. Its a simple search feature so people can search for limited information across regions (to assist in sales ops in other countries) You can do a basic search or a loose search.


public class CustomerSearchController { String acctName =''; Boolean looseSearch; List <Account> accountsList = new List <Account>(); public Void setacctName(String input) { acctName = input; } public Void setlooseSearch(Boolean input) { looseSearch = input; } public List <Account> getaccountsList() { return accountsList; } public String getacctName() { return null; } public Boolean getlooseSearch() { return null; } public PageReference Search() { accountsList =new List<account>(); if (looseSearch) { for( List <Account> temp : ([select id, name, Owner.Name, Sales_Stage__c, Branch__c from Account where name like: '%'+acctName+'%'])) { accountsList.addAll(temp); } }

else { for( List <Account> temp : ([select id, name, Owner.Name, Sales_Stage__c, Branch__c from Account where name like: acctName+'%'])) { accountsList.addAll(temp); } } return null; } }


My test class cant manage to get inside the public PageReference Sarch() method. And i was wondering how i do this? The test class is pretty simple as you can see, but only covers 61% of the code. Everything below the pageref method isnt tested
My question is how can i replicate the pagereference information and  fix my test class so that it will cover this code?
Any help would be great! 



@isTest private class CustomerSearchControllerTestMethod { static testMethod void searchControllerTest() { String input = 'Account'; String acctName = input; Boolean looseSearch = True; CustomerSearchController controller = new CustomerSearchController(); controller = new CustomerSearchController(); controller.setacctName('Account'); controller.setlooseSearch(true); controller.getaccountsList(); controller.getacctName(); controller.getlooseSearch(); List <Account> accountsList = new List <Account>(); accountsList = new List<account>(); } }


Message Edited by Brookesy on 08-17-2009 06:59 AM



Im quite an amateur coder so this is probably something easily solved. But im hoping after seeing it once i can reuse it across many objects :)


Basically i have a custom object (Currencies__c) that holds currency pairs say USD and CAD. These are held in 2 fields Settlement and Currency respectively.


I managed to piece together some code that would pull out all the Currency's from the custom object and display them on a visualforce page (along with some help from dev support on the delimiting and display bit, just couldn't get that working!) 


What im wondering now is how i can use the code i wrote in the class as a trigger on Accounts that is run after update and after insert. So that any time someone touches the account it will query all the related Currencies from the custom object and write them to a long text area (Currency_List__c) (as there could be 10 to 50+) 


Below is the code i used to pull the currencies in a delimited fashion (USD;CAD;GBP etc)


Any idea how i can convert this to a trigger? I assume i can reuse a lot of this code to pull the data but i assume il hit govenor limits if there is over 20 records? (i forget exact limits!)


Any help would be great!



public class currencyListTest {public String getSettlementCurrencies2() {    String strCur;    strCur = '';    for (List<Currencies__c> currencyList : [select CurrencySettlement__c from currencies__c where Account__c = :ApexPages.currentPage().getParameters().get('id')]) {        for (Currencies__c currencyItem : currencyList) {            if (strCur != '') {                strCur += ';';            }            strCur += currencyItem.CurrencySettlement__c;        }    }    return strCur;}public List<Currencies__c> getSettlementCurrencies() {    List<Currencies__c> currencyList;    currencyList = [select CurrencySettlement__c from currencies__c where Account__c = :ApexPages.currentPage().getParameters().get('id')];    return currencyList;} 


I've got to think this is a common request, but I didn't find an answer in my searching...


We are using Email-To-Case.  After a case is created, the support person will send an email to the customer from the support mailbox.  When the customer replies to that email, it is routed to Salesforce using email-to-case and the reply is automaticaly attached to the case because of the ID number in the email.


What I need to do is figure out how to make it so that an email alert is sent to the case owner to notify them that a customer's reply has been attached to their case.


Does anyone already have some code that does this?