Skip to content

Instantly share code, notes, and snippets.

@isanuki
isanuki / TerraSkyTechBlog20130417_002
Last active December 15, 2015 23:59
SOQL 集計関数サンプル
AggregateResult[] results = [SELECT SUM(Amount) summary
FROM Opportunity WHERE IsWon = true];
System.debug('受注金額合計=' + results[0].get('summary'));
@isanuki
isanuki / TerraSkyTechBlog20130417_003
Last active December 15, 2015 23:59
SOQL GROUP BY サンプル
AggregateResult[] results = [SELECT StageName, SUM(Amount) summary
FROM Opportunity
WHERE IsClosed = false
GROUP BY StageName];
for(AggregateResult ar: results){
System.debug('フェーズ='+ ar.get('StageName')
+ ':金額='+ ar.get('summary'));
}
@isanuki
isanuki / TerraSkyTechBlog20130417_001
Last active December 15, 2015 23:59
SOQL サンプル
Account[] accounts = [SELECT Name, Phone
FROM Account WHERE Rating = '見込みあり'];
@isanuki
isanuki / TerraSkyTechBlog20130417_004
Last active December 15, 2015 23:59
SOQL HAVINGサンプル
AggregateResult[] results = [SELECT LeadSource, SUM(Amount) summary
FROM Opportunity
GROUP BY LeadSource
HAVING Count(LeadSource) > 20];
for(AggregateResult ar: results){
System.debug('リードソース='+ ar.get('LeadSource')
+ ':金額='+ ar.get('summary'));
}
@isanuki
isanuki / TerraSkyTechBlog20130417_005
Last active December 15, 2015 23:59
SOQL 日付関数サンプル
Account[] accounts = [SELECT Name
FROM Account
WHERE CALENDAR_YEAR(CreatedDate) = 2012];
@isanuki
isanuki / TerraSkyTechBlog20130417_006
Last active December 15, 2015 23:59
SOQL 日付関数サンプル
AggregateResult[] results = [SELECT FISCAL_YEAR(CloseDate) year,
SUM(Amount) summary
FROM Opportunity
WHERE IsWon = true
GROUP BY FISCAL_YEAR(CloseDate)];
for(AggregateResult ar: results){
System.debug('年度='+ ar.get('year')
+ ':金額='+ ar.get('summary'));
}
@isanuki
isanuki / TerraSkyTechBlog20130417_007
Last active December 15, 2015 23:59
SOQL 日付リテラル サンプル
Account[] accounts = [SELECT Name
FROM Account
WHERE LastModifiedDate = THIS_WEEK];
<?xml version="1.0" encoding="UTF-8"?>
<CustomObjectSharingRules xmlns="http://soap.sforce.com/2006/04/metadata">
<ownerRules>
<fullName>Acct1toAcc2</fullName>
<sharedTo>
<portalRoleAndSubordinates>CustomerUser1</portalRoleAndSubordinates>
</sharedTo>
<sharedFrom>
<portalRoleAndSubordinates>CustomerUser2</portalRoleAndSubordinates>
</sharedFrom>
@isanuki
isanuki / AnalyticsAPISample.page
Last active December 30, 2015 13:59
Visualforce Analytics API Highcharts Sample
<apex:page showHeader="false">
<!-- 必要なライブラリを読み込む -->
<apex:includeScript value="//code.jquery.com/jquery-1.10.1.min.js" />
<apex:includeScript value="{!$Resource.highcharts}" />
<apex:includeScript value="{!$Resource.forcetk}" />
<script type="text/javascript">
$j = jQuery.noConflict();
var repot = null;
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<fields>
<fullName>Code__c</fullName>
<externalId>false</externalId>
<label>コード値</label>
<length>255</length>
<required>false</required>
<type>Text</type>
<unique>false</unique>