2010年1月31日日曜日
Select By parent-child relationships
for( Shopping__c s:[select id,Name,(Select Name From Goods__r limit 1) from Shopping__c where Name=:shop.Name])
{
Goods__c g=s.Goods__r;
goods.Name = g.Name;
}
{
Goods__c g=s.Goods__r;
goods.Name = g.Name;
}
Select By Foreign Key
shop.Name =
[Select Shopping__r.name From Goods__c where Name=:goods.Name]
.Shopping__r.name;
批処理更新
public void massUpdate() {
for (List <Contact> contacts:[Select FirstName, LastName From Contact]) {
for(Contact c : contacts) {
if (c.FirstName == 'Barbara' &&c.LastName == 'Gordon') {c.LastName = 'Wayne';}
}
update contacts;
}
}
SOQL Functions
●AVG()
SELECT CampaignId, AVG(Amount)
FROM Opportunity
GROUP BY CampaignId
●COUNT()
SELECT COUNT() FROM Account WHERE Name LIKE 'a%'
●COUNT_DISTINCT()
SELECT COUNT_DISTINCT(Company)
FROM Lead
●MIN()
SELECT MIN(CreatedDate), FirstName, LastName
FROM Contact
GROUP BY FirstName, LastName
●MAX()
SELECT Name, MAX(BudgetedCost)
FROM Campaign
GROUP BY Name
●SUM()
SELECT SUM(Amount)
FROM Opportunity
WHERE IsClosed = false AND Probability > 60
2010年1月30日土曜日
SOQL Select from 2 table
① select s.Name,(Select Name From Goods__r) from Shopping__c s
②Select g.Name, Shopping__r.name From Goods__c g
Create a Test Class
@isTest
private class HelloWorldTestClass {
static testMethod void validateHelloWorld() {
Account a = new Account(name='T1 Account');
insert a;
a = [SELECT hello__c FROM account WHERE Id =:a.id];
System.assertEquals('World', a.hello__c);
}
}
Create Trigger
trigger helloWorldAccountTrigger on Account (before insert) {
Account[] accs = Trigger.new;
MyHelloWorld.addHelloWorld(accs);
}
登録:
投稿 (Atom)