回答編集履歴

3

修正

2020/09/19 00:23

投稿

kuma_kuma_
kuma_kuma_

スコア2506

test CHANGED
@@ -50,7 +50,7 @@
50
50
 
51
51
  public static List<Contact> searchForContacts(String lastName, String postNum){
52
52
 
53
- List<Contact> Contacts = [Select Id, Name from Contact where LastName = :lastname AND MailingPostalCode = :postNum ];
53
+ List<Contact> Contacts = [Select Id, Name from Contact where LastName = :lastname AND MailingPostalCode = :postNum ORDER BY Id LIMIT 1];
54
54
 
55
55
  return Contacts;
56
56
 

2

再調整

2020/09/19 00:23

投稿

kuma_kuma_
kuma_kuma_

スコア2506

test CHANGED
@@ -48,9 +48,9 @@
48
48
 
49
49
  public class ContactSearch {
50
50
 
51
- public static List<Contact> searchForContact(String lastName, String postNum){
51
+ public static List<Contact> searchForContacts(String lastName, String postNum){
52
52
 
53
- List<Contact> Contacts = [Select ID,Name from Contact where LastName = :lastname AND MailingPostalCode = :postNum ];
53
+ List<Contact> Contacts = [Select Id, Name from Contact where LastName = :lastname AND MailingPostalCode = :postNum ];
54
54
 
55
55
  return Contacts;
56
56
 
@@ -60,6 +60,26 @@
60
60
 
61
61
  ```
62
62
 
63
- これで良いかと思うんだけどうかな?
63
+ テストクラス
64
64
 
65
+ ```APEX
66
+
67
+ @isTest
68
+
69
+ public class ContactSearchTest {
70
+
71
+ @isTest static void searchForContacts() {
72
+
73
+ Test.startTest();
74
+
75
+ List<Contact> Contacts = ContactSearch.searchForContacts('Rogers', '27215');
76
+
77
+ System.assertEquals(Contacts.size() != 1, true);
78
+
65
- テストクラスはよろしくね!
79
+ Test.stopTest();
80
+
81
+ }
82
+
83
+ }
84
+
85
+ ```

1

修正

2020/09/18 10:46

投稿

kuma_kuma_
kuma_kuma_

スコア2506

test CHANGED
@@ -50,9 +50,9 @@
50
50
 
51
51
  public static List<Contact> searchForContact(String lastName, String postNum){
52
52
 
53
- List<Contact> con = [SELECT id, name FROM Contact WHERE LastName=:lastName AND MailingPostalCode=:postNum];
53
+ List<Contact> Contacts = [Select ID,Name from Contact where LastName = :lastname AND MailingPostalCode = :postNum ];
54
54
 
55
- return con;
55
+ return Contacts;
56
56
 
57
57
  }
58
58