teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

修正

2020/09/19 00:23

投稿

kuma_kuma_
kuma_kuma_

スコア2506

answer CHANGED
@@ -24,7 +24,7 @@
24
24
  ```APEX
25
25
  public class ContactSearch {
26
26
  public static List<Contact> searchForContacts(String lastName, String postNum){
27
- List<Contact> Contacts = [Select Id, Name from Contact where LastName = :lastname AND MailingPostalCode = :postNum ];
27
+ List<Contact> Contacts = [Select Id, Name from Contact where LastName = :lastname AND MailingPostalCode = :postNum ORDER BY Id LIMIT 1];
28
28
  return Contacts;
29
29
  }
30
30
  }

2

再調整

2020/09/19 00:23

投稿

kuma_kuma_
kuma_kuma_

スコア2506

answer CHANGED
@@ -23,11 +23,21 @@
23
23
 
24
24
  ```APEX
25
25
  public class ContactSearch {
26
- public static List<Contact> searchForContact(String lastName, String postNum){
26
+ public static List<Contact> searchForContacts(String lastName, String postNum){
27
- List<Contact> Contacts = [Select ID,Name from Contact where LastName = :lastname AND MailingPostalCode = :postNum ];
27
+ List<Contact> Contacts = [Select Id, Name from Contact where LastName = :lastname AND MailingPostalCode = :postNum ];
28
28
  return Contacts;
29
29
  }
30
30
  }
31
31
  ```
32
- これで良いかと思うんだけどうかな?
33
- テストクラスはよろしくね!
32
+ テストクラス
33
+ ```APEX
34
+ @isTest
35
+ public class ContactSearchTest {
36
+ @isTest static void searchForContacts() {
37
+ Test.startTest();
38
+ List<Contact> Contacts = ContactSearch.searchForContacts('Rogers', '27215');
39
+ System.assertEquals(Contacts.size() != 1, true);
40
+ Test.stopTest();
41
+ }
42
+ }
43
+ ```

1

修正

2020/09/18 10:46

投稿

kuma_kuma_
kuma_kuma_

スコア2506

answer CHANGED
@@ -24,8 +24,8 @@
24
24
  ```APEX
25
25
  public class ContactSearch {
26
26
  public static List<Contact> searchForContact(String lastName, String postNum){
27
- List<Contact> con = [SELECT id, name FROM Contact WHERE LastName=:lastName AND MailingPostalCode=:postNum];
27
+ List<Contact> Contacts = [Select ID,Name from Contact where LastName = :lastname AND MailingPostalCode = :postNum ];
28
- return con;
28
+ return Contacts;
29
29
  }
30
30
  }
31
31
  ```