Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. public class AccountRelatedContacts {
  2. public id tobeEdited{get; set;}
  3. public String selectedcouId{get;set;}
  4. public String selectedAccId{get;set;}
  5. public string conid{get;set;}
  6. public boolean showPopup{ get; set; }
  7. public boolean isDownload {get;set;}
  8.  
  9. public list<contact> lstcontact{get;set;}
  10.  
  11.  
  12. public List<SelectOption> getCountryNames() {
  13.  
  14. List<SelectOption> couOptions= new List<SelectOption>();
  15. couOptions.add( new SelectOption('','--Select--'));
  16. list<Country__c> cut = [select Id,name from Country__c];
  17. for( Country__c cou : cut ) {
  18. couOptions.add( new SelectOption(cou.Id,cou.name));
  19. }
  20. return couOptions;
  21. }
  22.  
  23. public List<SelectOption> getAccountNames() {
  24. system.debug('country ID'+selectedcouid);
  25. List<SelectOption> accOptions= new List<SelectOption>();
  26. List<SelectOption> options = new List<SelectOption>();
  27. if(selectedcouId != null){
  28.  
  29. list<account> act = [select Id,name,Country__c from account where Country__c=:selectedcouId order by name ASC ];
  30.  
  31. for( Account acc : act ) {
  32. accOptions.add( new SelectOption(acc.Id,acc.name));
  33. }
  34. }
  35. else
  36. {
  37. accOptions.add( new SelectOption('--None--','--None--'));
  38. }
  39. return accOptions;
  40. }
  41.  
  42. public pagereference Submit(){
  43.  
  44. lstcontact= new List<contact>();
  45. lstcontact= [SELECT ID,name, Firstname,lastname,email,phone,account.name from contact WHERE accountId=:selectedaccid order by name ASC];
  46. return null;
  47. }
  48. }
  49.  
  50. public class testCountryAccountRelatedContacts {
  51.  
  52. private static testmethod void testgetCountryNames() {
  53. country__C c = new country__c();
  54. insert c;
  55. CountryAccountRelatedContacts controller = new CountryAccountRelatedContacts();
  56. controller.selectedcouId = c . id;
  57. List<SelectOption> sp = controller.getCountryNames();
  58. system.assertEquals(sp.size(),2);
  59. }
  60. private static testMethod void testgetaccountNames()
  61. {
  62. country__C c = new country__c();
  63. insert c;
  64. account acc = new account(Country__c=c.id,name = 'test');
  65. insert acc;
  66. CountryAccountRelatedContacts controllers = new CountryAccountRelatedContacts();
  67. List<SelectOption> sp1 = controllers.getaccountNames();
  68. controllers.selectedcouId = c.id;
  69. controllers.selectedAccId = acc.id;
  70. string getselectedcouId = controllers.selectedcouId;
  71. string getsselectedAccId = controllers.selectedAccId;
  72. List<SelectOption> sp2 = controllers.getaccountNames();
  73. system.assertEquals(sp2.size(),2);
  74. }
  75. }
  76.  
  77. USER_DEBUG [33]|DEBUG|country IDnull
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement