Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@riunraku

テストクラス作成する時に、既存のデータが検索できなくて、 新しい作成データがInsert failed(DUPLICATE_VALUE)

More than 1 year has passed since last update.

テストクラス作成する時に、既存のデータが検索できなくて、 新しい作成データがInsert failed(DUPLICATE_VALUE)、その原因は@isTestの後が(SeeAllData=true)が追加してなかったです。
必ず注意ください。

@isTest
private class XXXXXTest_Class {

// 「ChatterグループID」 取得
String NEW_GROUP_NAME = System.Label.ANNOUNCE_VIEWER_GROUP;
// グループ名前のリスト生成
List nameList = new List();
nameList = NEW_GROUP_NAME.split(',',0);
Map grpMap = new Map();
for (CollaborationGroup cg : [SELECT Name FROM CollaborationGroup WHERE Name IN :nameList AND IsArchived = FALSE]) {
grpMap.put(cg.Name, cg);
}
//Create Public Chatter groups
List grps = new List();
for (String grpName:nameList) {
//Confirm group does not already exist
if (!grpMap.containsKey(grpName)) {
CollaborationGroup g = new CollaborationGroup(Name=grpName, CollaborationType='Public');
system.debug(g);
grps.add(g);
}
}
insert grps;
}

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
riunraku
このアカウントでの投稿は私個人の見解に基づくものです。 初心者向け_admin develper資格達成 https://trailhead.salesforce.com/ja/users/raku2016/trailmixes/harumi
harumisystems
ソフトウェア開発、不動産

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?