Skip to content

Instantly share code, notes, and snippets.

@101dvlp
Last active July 13, 2017 11:39
Show Gist options
  • Save 101dvlp/ffa2987d573f6baf1bf00ae142b6694f to your computer and use it in GitHub Desktop.
Save 101dvlp/ffa2987d573f6baf1bf00ae142b6694f to your computer and use it in GitHub Desktop.
// 検索元のContact
Contact c = new Contact();
c.LastName = 'con';
c.Phone = '0311111111';
// SOSLを実行
List<List<SObject>> searchList = [FIND :c.Phone IN Phone FIELDS RETURNING Account(Name, Phone), Contact(Name, Phone)];
Account[] acList = ((List<Account>)searchList[0]);
Contact[] cList = ((List<Contact>)searchList[1]);
// 検索結果の件数
System.debug('Accountの件数 >>> ' + acList.size());
System.debug('Contactの件数 >>> ' + cList.size());
// 検索元と取引先2件の電話を比較
System.debug('検索元の電話 >>> ' + c.Phone);
for(Account a : acList){
if(c.Phone == a.Phone){
System.debug(a.Phone + ' >>> 一致しました');
} else {
System.debug(a.Phone + ' >>> 一致しませんでした…');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment