├── force-app └── main │ └── default │ └── classes │ ├── PriceRecordSeriesNumberDao.cls-meta.xml │ ├── PriceRecordSeriesNumberRestResource.cls-meta.xml │ ├── PriceRecordSeriesNumberRestResource.cls │ └── PriceRecordSeriesNumberDao.cls ├── config └── project-scratch-def.json ├── LICENSE ├── Makefile └── README.md /force-app/main/default/classes/PriceRecordSeriesNumberDao.cls-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 51.0 4 | Active 5 | 6 | -------------------------------------------------------------------------------- /force-app/main/default/classes/PriceRecordSeriesNumberRestResource.cls-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 51.0 4 | Active 5 | 6 | -------------------------------------------------------------------------------- /config/project-scratch-def.json: -------------------------------------------------------------------------------- 1 | { 2 | "orgName": "xxxx", 3 | "edition": "Developer", 4 | "features": [], 5 | "settings": { 6 | "lightningExperienceSettings": { 7 | "enableS1DesktopEnabled": true 8 | }, 9 | "securitySettings": { 10 | "passwordPolicies": { 11 | "enableSetPasswordInApi": true 12 | } 13 | }, 14 | "mobileSettings": { 15 | "enableS1EncryptedStoragePref2": false 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /force-app/main/default/classes/PriceRecordSeriesNumberRestResource.cls: -------------------------------------------------------------------------------- 1 | /** 2 | * 価格レコードオブジェクトのREST 3 | * 4 | */ 5 | @RestResource(urlMapping='/PriceRecordSeriesNumber/*') 6 | global with sharing class PriceRecordSeriesNumberRestResource { 7 | 8 | /** 9 | * 価格レコード連続番号を取得します。 10 | * 11 | * @return priceMaster 12 | */ 13 | @HttpGet 14 | global static List doGetPriceRecordSeriesNumber() { 15 | RestRequest req = RestContext.request; 16 | 17 | //クエリパラメータがnullでない場合 18 | String prId = req.params.get('price_record_id'); 19 | String d = req.params.get('date'); 20 | PriceRecordSeriesNumberDao dao = PriceRecordSeriesNumberDao.getInstance(); 21 | List ps = new List(); 22 | 23 | if (prId != null && d != null) { 24 | Date target = Date.valueOf(d); 25 | ps = dao.getPriceRecordSeriesNumberByPriceRecordAndEndDate(prId, target); 26 | return ps; 27 | } 28 | 29 | ps = dao.getPriceRecordSeriesNumber(); 30 | return ps; 31 | } 32 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Latona, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL := help 2 | 3 | .PHONY: sf-login 4 | sf-login: ## sandbox 環境にログインします。 5 | sfdx force:auth:web:login -r https://test.salesforce.com -a sand1 6 | sfdx config:set defaultusername=xxxx 7 | 8 | .PHONY: sf-all-retrieve 9 | sf-all-retrieve: ## 全ての Apex code を取得します。 10 | sfdx force:source:retrieve -x manifest/package.xml 11 | 12 | .PHONY: sf-class-retrieve 13 | sf-class-retrieve: ## クラス単位で Apex code を取得します。 14 | ifdef class 15 | sfdx force:source:retrieve -m "ApexClass:${class}" 16 | else 17 | @bash -c "echo -e '\033[36mUsage: make sf-class-retrieve class=TargetClassName\033[0m'" 18 | endif 19 | 20 | .PHONY: sf-all-deploy 21 | sf-all-deploy: ## 全ての Apex code をデプロイします。 22 | sfdx force:source:deploy -x manifest/package.xml 23 | 24 | .PHONY: sf-class-deploy 25 | sf-class-deploy: ## クラス単位で Apex code をデプロイします。 26 | ifdef class 27 | sfdx force:source:deploy -m "ApexClass:${class}" 28 | else 29 | @bash -c "echo -e '\033[36mUsage: make sf-class-deploy class=TargetClassName\033[0m'" 30 | endif 31 | 32 | # See "Self-Documented Makefile" article 33 | # https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html 34 | .PHONY: help 35 | help: 36 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # salesforce-apex-price-recordnumber 2 | salesforce-apex-price-recordnumber は、salesforce sand box 環境で動作する Apex コードを管理します。 3 | 4 | ## 使用方法 5 | salesforce の CLI の sfdx を使用します。[こちらから](https://developer.salesforce.com/docs/atlas.ja-jp.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli.htm) を参考にインストールしてください。 6 | また、下記コマンドを実行する事で既存の make コマンドの一覧と説明を出力します。 7 | ``` 8 | $ make 9 | sf-login sandbox 環境にログインします。 10 | sf-all-retrieve 全ての Apex code を取得します。 11 | sf-class-retrieve クラス単位で Apex code を取得します。 12 | sf-all-deploy 全ての Apex code をデプロイします。 13 | sf-class-deploy クラス単位で Apex code をデプロイします。 14 | ``` 15 | 引数のある make コマンドは、引数なしで叩く事で使用例が出力されます。 16 | ``` 17 | $ make sf-class-retrieve 18 | Usage: make sf-class-retrieve class=TargetClassName 19 | ``` 20 | 21 | ### login 22 | sfdx を使用するに当たって sandbox 環境にログインする必要があります。下記コマンドを実行してログインしてください。 23 | ``` 24 | $ make sf-login 25 | ``` 26 | 27 | ### retrieve 28 | #### 全ての Apex code を取得 29 | 下記コマンドを使用する事で sandbox 環境にある Apex コードを取得できます。(コードは `force-app/main/default` に、上書きされます。) 30 | 取得範囲は `manifest/package.xml` に記載されています。 31 | ``` 32 | $ make sf-all-retrieve 33 | ``` 34 | 35 | #### クラス単位での取得 36 | 下記コマンドを使用する事で sandbox 環境に ローカルの Apex コードをクラス単位で取得できます。 37 | ※ ローカル環境にコードが上書きされるので、注意して使用してください。 38 | 取得範囲は `manifest/package.xml` に記載されています。 39 | ``` 40 | $ make sf-class-deploy class=TargetClassName 41 | ``` 42 | 43 | #### フォルダー単位での取得 44 | ``` 45 | $ sfdx force:source:deploy -p {folder path} 46 | ``` 47 | 48 | ### deploy 49 | #### 全ての Apex code をデプロイ 50 | 下記コマンドを使用する事で sandbox 環境に ローカルの Apex コードを deploy できます。 51 | ※ ローカル環境のコードがそのまま反映されるので、注意して使用してください。 52 | 取得範囲は `manifest/package.xml` に記載されています。 53 | ``` 54 | $ make sf-all-deploy 55 | ``` 56 | 57 | #### クラス単位でのデプロイ 58 | 下記コマンドを使用する事で sandbox 環境に ローカルの Apex コードをクラス単位で deploy できます。 59 | ※ ローカル環境のコードがそのまま反映されるので、注意して使用してください。 60 | 取得範囲は `manifest/package.xml` に記載されています。 61 | ``` 62 | $ make sf-class-deploy class=TargetClassName 63 | ``` 64 | 65 | #### フォルダー単位でのデプロイ 66 | ``` 67 | $ sfdx force:source:deploy -p {folder path} 68 | ``` 69 | 70 | その他 Apex Class 単位でのデプロイなどは、[こちら](https://developer.salesforce.com/docs/atlas.ja-jp.sfdx_dev.meta/sfdx_dev/sfdx_dev_develop_any_org.htm) を参考にしてください 71 | -------------------------------------------------------------------------------- /force-app/main/default/classes/PriceRecordSeriesNumberDao.cls: -------------------------------------------------------------------------------- 1 | public with sharing class PriceRecordSeriesNumberDao { 2 | 3 | //Singleton 4 | private static PriceRecordSeriesNumberDao dao; 5 | 6 | public static PriceRecordSeriesNumberDao getInstance() { 7 | if (dao == null) { 8 | dao = new PriceRecordSeriesNumberDao(); 9 | } 10 | return dao; 11 | } 12 | 13 | /** 14 | * 価格レコード連続番号オブジェクトを取得します。 15 | * 16 | * @return List 17 | */ 18 | 19 | public List getPriceRecordSeriesNumber() { 20 | List price = [ 21 | SELECT 22 | price_type_id__c, 23 | price_type_name__c, 24 | price_record_no__c, 25 | price_record_id__c, 26 | OwnerId, 27 | LastModifiedById, 28 | end_date__c, 29 | start_date__c, 30 | create_date__c, 31 | series_number__c, 32 | price__c 33 | FROM PriceRecordSeriesNumber__c]; 34 | 35 | if (price == null || price.IsEmpty()) { 36 | return null; 37 | } 38 | 39 | return price; 40 | 41 | } 42 | 43 | public List getPriceRecordSeriesNumberByPriceRecordAndEndDate(String priceRecordId, Date targetDate) { 44 | List price = [ 45 | SELECT 46 | price_type_id__c, 47 | price_type_name__c, 48 | price_record_no__c, 49 | price_record_id__c, 50 | OwnerId, 51 | LastModifiedById, 52 | end_date__c, 53 | start_date__c, 54 | create_date__c, 55 | series_number__c, 56 | price__c 57 | FROM PriceRecordSeriesNumber__c 58 | WHERE price_record_id__c =: priceRecordId AND ( end_date__c >: targetDate AND start_date__c <: targetDate)]; 59 | 60 | if (price == null || price.IsEmpty()) { 61 | return null; 62 | } 63 | 64 | return price; 65 | 66 | } 67 | } --------------------------------------------------------------------------------