發表文章

Chrome DevTools 的 Source 一片空白該怎麼辦?

有時候想要 debug JavaScript 的部份,但是 Chrome DevTools 的 Source 一片空白,此時我偏好的方法是在 Console 處執行: parent.location.reload(true) 即可。 也有一些其它的方法,請參見:https://stackoverflow.com/questions/20196795/chrome-developer-tool-html-script-is-blank-in-source-debugging-tutorial

.zshrc sample / m2 macbook /20230511

 export PATH="/opt/homebrew/Cellar/mongodb-community/6.0.1/bin:${PATH}" export HISTSIZE=1000000000 export SAVEHIST=$HISTSIZE setopt EXTENDED_HISTORY export PYENV_ROOT="$HOME/.pyenv" command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)" # rosetta terminal setup if [ $(arch) = "i386" ]; then     alias brew86="/usr/local/bin/brew"     alias pyenv86="arch -x86_64 pyenv" fi export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/shims:$PATH" if command -v pyenv 1>/dev/null 2>&1; then  eval "$(pyenv init -)" fi # The next line updates PATH for the Google Cloud SDK. if [ -f '/Users/henry.yang/Downloads/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/firstname.lastname/Downloads/google-cloud-sdk/path.zsh.inc'; fi # The next line enables shell command completion for gcloud. if [ -f '/Users/firstname.lastname/Downloads/google-...

show command history

history  behaves differently in  bash  than it does in  zsh : In short: zsh : history  lists only the  15 most recent  history entries history 1  lists  all  - see below. bash : history  lists  all  history entries. Sadly, passing a  numerical operand  to  history  behaves differently, too: zsh : history <n>  shows all entries  starting with   <n>  - therefore,  history 1  shows  all  entries. ( history -<n>  - note the  -  - shows the  <n>   most recent  entries, so the default behavior is effectively  history -15 ) bash : history <n>  shows the  <n>   most recent  entries. (bash's  history  doesn't support listing  from  an entry number; you can use  fc -l <n> , but a  specific entry  <n>  must exist , otherwise the comma...

How to use brew install for M1/M2 macbook. (Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)! )

Example arch -x86_64 brew install hashicorp/tap/vault Reference https://stackoverflow.com/questions/64963370/error-cannot-install-in-homebrew-on-arm-processor-in-intel-default-prefix-usr

Kafka 壞了? 談 Salesforce CDC (Change Data Capture) 壞掉的原因、預防與補救

我們有一個下游系統透過 kafka 的機制在即時 sync Salesforce 的 oportunity。 某一天,運作地好好的 integration 突然壞了,下游突然收不到資料了。 sync 失敗可能原因 以我們 Salesforce Enterprise Edition 的方案為例, 每 24 小時的 event 上限為 25,000。以日常正常用量來說大致夠用。 但若有人一次更新大批資料,則有超量風險。一但超量,subscriber 將收到 error: 403::Organization total events daily limit exceeded ,event 將無法送至 kafka。   Event Usage 可 由此查看 : SELECT EndDate,Name,StartDate,Value FROM PlatformEventUsageMetric WHERE EndDate = last_n_days:60 ORDER BY EndDate DESC NULLS FIRST 查詢過去一天有多少 opportunity 遭到 update/create: workbench query : SELECT Id,LastModifiedById,LastModifiedDate,Name,OwnerId FROM Opportunity WHERE LastModifiedDate = last_n_days:2 ORDER BY LastModifiedDate DESC NULLS FIRST 如何減少失敗的影響 事前預防 提醒系統管理員,不得突發性大規模更新 opportunity。 若需大規模更新,建議 分成小批量,在不同時間點更新。 排定在週末非工作日更新 更新後密切監控 kafka 運行狀況 Grafana Kafka Overview k8s / k9s 事中監測 建立自動監控機制,一旦發生超量風險,立刻發通知給 Salesforce 系統管理員 事後修補 手動執行 produce event job。 且需反覆手動執行,直至過去 24 小時內之 usage 回穩。     參考資料 Platform Event Allocations Change Data Capture (CDC...

如何在 list view 一次刪除多筆 record / How to mass delete records from list view

圖片
要如何在 list view 選擇多筆 record 後一鍵刪除呢? 這個功能在 Salesforce 目前沒有內建。 你可以選擇下列幾種方式 安裝 APP 用 flow 來做 用 apex class 來做 安裝 App 有一個由 Salesforce Labs 釋出的 app ,名字很直白就叫做 Mass Delete 官方說明文字 A set of custom list buttons that you can add to your standard list views or related lists. Users can select any number of records and delete all of them with a single click. 優點 快速簡單,即裝即用。 缺點 僅支援下列幾個現成的 standard object,如果需要用在 custom object,需要進行一點客製修改。 支援 object:  Product Solution Contact Contract Lead Opportunity Account Asset Campaign Case 使用在 custom object 的修改教學參考: https://blog.cloudanalogy.com/salesforce-lightning-how-to-mass-delete-records-from-list-view/ 概念上來說就只要 clone 它的 Visualforce Page 然後改第一行的 controller 即可。 用 Flow 來做 教學影片: https://youtu.be/3cdj8QCtYvI 用 Apex Class 來做 https://muskanagarwal1499.blogspot.com/2022/06/mass-delete-records-using-list-button.html

你在 Validation Rule 裡面對 RecordTypeId 做判斷卻常常失靈嗎?

你在 Validation Rule 裡面對 RecordTypeId 做判斷卻常常失靈嗎? 是不是明明想把某個 RecordTypeId 擋下來,但是設置的 Validation Rule 卻形同虛設呢? 這可能是因為你填入了太過正確的 RecordTypeId 了。

Salesforce 的 Id 為什麼分為 15 碼和 18 碼兩種?

概念上來說,15 碼 Id 是區分大小寫的,18 碼 Id 是不用考慮大小寫的。 技術上來說,直接把18 碼 Id 的後三碼截掉,就可以得到 Id 的 15 碼版本。 但若是想 15 碼 Id 出發想得到 18 碼 Id ,需要稍微計算一下。 這是用 JavaScript 來計算 15-digit to 18-digit 的方式: javascript :( function (){ var input = prompt ( 'Enter 15-character ID' ); var output ; if ( input . length == 15 ){ var addon = "" ; for ( var block = 0 ; block < 3 ; block ++) { var loop = 0 ; for ( var position = 0 ; position < 5 ; position ++){ var current = input . charAt ( block * 5 + position ); if ( current >= "A" && current <= "Z" ) loop += 1 << position ; } addon += "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345" . charAt ( loop ); } output =( input + addon ); } else { alert ( "Error : " + input + " i...

[似乎沒什麼用的小知識] 為什麼在 Deployment Status 的頁面,Deploy Components 的分子總是大於等於分母呢?

分子與分母的定義分別應為 Deployed 與 Total。 Deploy Components 的分子(Deployed)大於分母(Total)的原因可能是因為在進行部署時,某些組件可能已經存在於目標組織中,這些已經存在的組件並不會被覆蓋,因此在 Deploy Components 的計算中,它們被算作已經部署成功的組件(Deployed),但並未算在 Total 中。 舉例來說,如果在進行部署時,有 10 個組件需要被部署,但目標組織中已經有 2 個相同名稱的組件存在,那麼在 Deploy Components 的計算中,已經存在的這 2 個組件就會被算作 Deployed,而剩下的 8 個組件會被算作 Total,因此 Deployed 的值就大於 Total 的值了。 總之,在 Salesforce Deployment Status 頁面中,Deploy Components 的分子大於分母並不一定代表部署出現了問題,可能只是因為某些組件已經存在於目標組織中。 如果您確定部署出現了問題,可以查看相應的部署錯誤信息,並嘗試解決問題。 (來自 ChatGPT 的回答)

[Apex] List all non-editable fields

When we want to customize a FieldHistory object, such as the Opportunity Field History , we would write a small program to check the modification status of all fields when the Opprotunity record is updated. However, some fields are unnecessary, or even should not be checked. For example, some system fields like CreateDate and IsDeleted. In concept, if a field is not Updateable, there is no need to check it. So how do we confirm if a field is Updateable or not? Here is a ready-made method: (Using Opportunity as an example): Opportunity . sObjectType . getDescribe (). fields . getMap (). get ( fieldName ). getDescribe (). isUpdateable () The plain translation of the above line is roughly as follows: Retrieve the field map of the Opportunity object, and then extract the properties of the specified field from the field map. One of the properties that can be checked is isUpdateable. 

[Apex] 列出所有不可編輯的欄位

當我們想要自己客製化一個 FieldHistory object,例如 Opporutunity Field History,我們就會寫一支小程式,在 Opprotunity reocrd 被更新的時候檢查 所有欄位 的異動狀態。 但其實有些欄位是不必要、甚至是不應該檢查的。 例如某些系統欄位:CreateDate、IsDeleted 之類的。 概念上來說,如果某個 field 不是 Updateable,就毋須檢查。 那如何確認某個 field 是不是 Updateable呢? 這裡有一個現成的方法可用: 以 Opportunity 為例: Opportunity . sObjectType . getDescribe (). fields . getMap (). get ( fieldName ). getDescribe (). isUpdateable () 上面這行的白話翻譯大致是∶把 Opportunity 這個 object 的 field map 抓出來之後,再從 field map 裡面提取指定 field 的屬性,其中一個可以檢查屬性就是 isUpdateable。

實用的 SOQL 相對日期 Relative Range of Time

常用重點摘要 YESTERDAY Range: Starts 00:00:00 UTC the day before and continues for 24 hours.  Example: SELECT Id FROM Account WHERE CreatedDate = YESTERDAY TODAY Range: Starts 00:00:00 UTC of the current day and continues for 24 hours. Example: SELECT Id FROM Account WHERE CreatedDate > TODAY TOMORROW Range: Starts 00:00:00 UTC after the current day and continues for 24 hours. Example: SELECT Id FROM Opportunity WHERE CloseDate = TOMORROW LAST_N_DAYS:n For the number n provided, starts with the current day and continues for the past n days. This range includes the current day, not just previous days. For example, LAST_N_DAYS:1 includes yesterday and today. Example: SELECT Id FROM Account WHERE CreatedDate = LAST_N_DAYS:365 LAST_N_YEARS:n Starts 00:00:00 UTC on January 1 of the previous year and continues through the end of December 31 of the previous nth year. Example: SELECT Id FROM Opportunity WHERE CloseDate > LAST_N_YEARS:5 參考資料 Date Formats and Date Literals in WHERE

如何用 formula 計算出「下一季度的最後一天」

圖片
問: 請幫我生成一個 Salesforce formula, 需求是:根據 createddate 產生一個新的日期,新的日期為「下一季度的最後一天」 ChatGPT 答: 以下是 Salesforce 公式,可以根據 createddate 產生下一季度的最後一天日期: DATE ( YEAR (CreatedDate) + CASE ( MOD ( MONTH (CreatedDate) - 1 , 3 ), 0 , 0 , 0 , 1 , 1 , 1 ), CASE ( MOD ( MONTH (CreatedDate) - 1 , 3 ), 0 , 4 , 0 , 7 , 0 , 10 ), 1 ) - 1 這個公式中,我們使用了 YEAR 函数、MONTH 函数和 MOD 函数來計算出 createddate 所在的年份和月份,然後使用 CASE 函数來判斷 createddate 所在的季度,進而計算出下一季度的最後一個月份。最後,我們使用 DATE 函数來組合出下一季度的最後一天日期。 請注意,由於 Salesforce 中的日期格式是 ISO 8601 格式(yyyy-MM-dd),所以公式中最後的 -1 表示減去一天,以獲得下一季度的最後一天日期。