1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Salesforce開発者コンソールでSQL文実行

Last updated at Posted at 2019-08-20

■SOQLステートメントを実行する
開発者コンソールで、[Query Editor (クエリエディタ)] をクリックします。
SELECT Id, Name, Session_Date__c, Level__c FROM Session__c WHERE Level__c = 'Advanced' LIMIT 1

■DMLステートメントを実行する
開発者コンソールで、[Debug (デバッグ)] > [Open Execute Anonymous Window (実行匿名ウィンドウを開く)] をクリックし、次のステートメントを実行してセッションを更新します
List taskList = [SELECT Id, Status__c FROM Task__c WHERE Company__c = 'PS'];
List updTaskList = new List();
for (Task__c item : taskList) {
item.Status__c = 30;
updTaskList.add(item);
}
update updTaskList;

■参照URL
SOQL と DML を使用したデータへのアクセス
https://trailhead.salesforce.com/ja/content/learn/projects/salesforce_developer_workshop/accessing_data_with_soql_and_dml

【SOQL】Salesforce開発者コンソール(Query)の使い方
https://qiita.com/szaizen/items/be99e97f74b45bdf3d0a

Apex DML Statements
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_section.htm#!

Write SOSL Queries Unit | Salesforce Trailhead
https://trailhead.salesforce.com/en/content/learn/modules/apex_database/apex_database_sosl


Child-to-parent:子 (Contact) から親 (Account) を参照
SELECT Id, Name, Account.Id, Account.Name FROM Contact

Parent-to-child:親 (Account) から子 (Contact) を参照
SELECT Id, Name, (SELECT Id FROM Contacts) FROM Account

Child-to-parent:子(ChildObj__c)から親(ParentObj__c)を参照
SELECT Id, Name, ParentObj__c, ParentObj__r.name FROM ChildObj__c

Parent-to-child:親(ParentObj__c)から子(ChildObj__c)を参照
SELECT Id, Name, (SELECT Id, Name FROM [子リレーション名]__r) FROM ParentObj__c

Apexコードでの利用例
子(ChildObj__c)から親(ParentObj__c)を参照

List children = [SELECT Id, Name, ParentObj__c, ParentObj__r.name FROM ChildObj__c];
// 親オブジェクトのnameフィールドの値を表示
System.debug(children.parentObj__r.name);

親(ParentObj__c)から子(ChildObj__c)を参照
List parents = [SELECT Id, Name, (SELECT Id, Name FROM ChildObjs__r) FROM ParentObj__c];
// 子オブジェクトのnameフィールドの値を表示
for (ChildObj__c child : parents.childObjs__r) {
System.debug(child.name);
}

https://dackdive.hateblo.jp/entry/2014/06/10/112629
[Salesforce]参照関係にあるオブジェクトをSOQLで取得する

参照関係にある複数のオブジェクトのデータ取得
[子→親オブジェクトへのデータ参照]
SELECT Id, Name, parent.Id, parent.Name FROM Child;

[親→子オブジェクトへのデータ参照]

SELECT Id, Name, (SELECT Id, Name FROM Child)FROM Parent;

[参照関係にある2つのオブジェクトから1つのオブジェクトの項目のみ取得]
SELECT Id, NameFROM tableAWHERE Id IN (SELECT Id from tableB);

SELECT StageName, SUM(Amount) OppAmount, COUNT(id) Total
FROM Opportunity
WHERE isClosed=False
GROUP BY StageName
HAVING count(ID) >1

AggregateResult [] opps = [ SELECT StageName, SUM(Amount) OppAmount, COUNT(id) Total FROM Opportunity where isClosed=False GROUP BY StageName HAVING count(ID) >1 ];
System.debug(opps[0].OppAmount);

Sorting Data using ORDER BY:
Select Id, Name From Opportunity ORDER BY Name ASC

LIMIT the Rows using OFFSET and LIMIT:
SELECT Name FROM Opportunity LIMIT 50 OFFSET 100

Dynamic SOQL
String myString = 'John Smith';
List sobjList = Database.query('SELECT Id, Name FROM Account WHERE Name = :myString');

https://apexcoder.com/2016/01/02/how-to-use-soql-query-with-nested-soql-aggregate-functions-order-by-group-by-having-offset-and-limit/
Select Id, Name From Account LIMIT 10
Select Contact.Account.Name From Contact (1 level up )
Select Id, ( Select Id from Contacts ) From Account
Select Id, Name, (Select Id From Contacts), (Select Id From Cases) from Account LIMIT 10

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?