發表文章

Apex Solution for Splitting Orders Based on Order Line Items in Salesforce

圖片
When managing orders in Salesforce, we sometimes face the need to split orders based on their order line items. Recently, I encountered such a challenge: under a specific contract, there were 18 orders, each containing three order line items. The task was to split these orders so that each new order would contain only one order line item. The first step in this task was to query all the orders under a specific contract. Then, for each order, we needed to query its associated order line items. Initially, I considered directly modifying the OrderId field of the OrderItem records, but this is not allowed in Salesforce, as once an OrderItem is created, its OrderId cannot be changed. Therefore, I took a different approach: create a new order and a new order item record for each order line item. In this way, each new order would have only one associated order line item. This required associating the new order items with the new orders after inserting the new orders. Here is an example of

在 Salesforce 中根據訂單項目拆分訂單的 Apex 解決方案

圖片
在處理 Salesforce 的訂單管理時,我們可能會遇到需要根據訂單項目(Order Line Items)拆分訂單的情況。最近,我遇到了這樣一個挑戰:在特定合同下有18張訂單,每個訂單包含三個訂單項目。任務是將這些訂單拆分,使每張新訂單只包含一個訂單項目。 這個任務的第一步是查詢特定合同下的所有訂單。然後,對於每個訂單,我們需要查詢其相關的訂單項目。最初,我考慮直接修改 OrderItem 記錄的 OrderId 字段,但是這在 Salesforce 中是不允許的,因為一旦 OrderItem 被創建,其 OrderId 就不能更改。 因此,我採取了不同的方法:為每個訂單項目創建一個新的訂單和一個新的訂單項目記錄。這樣,每個新的訂單都將只有一個與之關聯的訂單項目。這需要插入新訂單後,再將新訂單項目與新訂單關聯。 以下是實現此功能的 Apex 代碼示例:   public class SplitOrders {     public static void splitOrdersByLineItems(String contractId) {         // 查詢特定合同下的所有訂單         List<Order> originalOrders = [SELECT Id FROM Order WHERE ContractId = :contractId];         List<Order> newOrders = new List<Order>();         List<OrderItem> newOrderItems = new List<OrderItem>();         for (Order originalOrder : originalOrders) {             List<OrderItem> orderItems = [SELECT Id, Product2Id, Quantity, UnitPrice FROM OrderItem WHERE OrderId = :originalOrder.Id];             for (OrderItem originalItem : orderItems) {      

[mongodb] 多條件搜尋 / query with multi criteria

以下是 ChatGPT 的回答供參考,尚未驗證。 要查询 MongoDB 中 status 字段等于 'Signing' 且 contract_sign_method 字段等于 'Manual' 的记录,你可以使用 MongoDB 的查询操作符 $and 或者简单地将条件组合在一起。以下是两种方法的示例: 使用 $and 操作符: javascript Copy code db. your_collection_name . find ({ $and : [ { status : 'Signing' }, { contract_sign_method : 'Manual' } ] }) 在上面的示例中,我们使用 $and 操作符将两个条件组合在一起,以确保同时满足 status 为 'Signing' 和 contract_sign_method 为 'Manual' 的记录被查询。 直接组合条件: javascript Copy code db. your_collection_name . find ({ status : 'Signing' , contract_sign_method : 'Manual' }) 在这个示例中,我们没有使用 $and 操作符,而是将两个条件直接放在同一个查询对象中。MongoDB 默认会将多个条件视为逻辑 AND 运算,因此这个查询也将返回 status 为 'Signing' 且 contract_sign_method 为 'Manual' 的记录。 无论使用哪种方法,都会返回满足指定条件的记录。确保将 your_collection_name 替换为你实际使用的集合名称。

[mongodb] How to export mongodb data as CSV

How to export mongodb data as CSV Prerequisite install mongoexport Sample code: export data that invoice_date in July, 2023: mongoexport --host "{host}" --type=csv --authenticationDatabase admin -u admin -p {pwd} -d dashboard -c 'paymentRecords2' --query='{  "$or": [{"invoice_date": { "$gte": 1688169600, "$lt": 1690848000 } },{ "actual_payment_date": { "$gte": 1688169600, "$lt": 1690848000 } }  ]}' -o "mongodb_export_paymentRecords2.csv" --fields _id,field1,field2,field3 Note: --fields should not contain space

mongodb 如何清理某個欄位中的 null

 如何清理某個欄位中的 null sample code: db.ios.updateOne(   { _id: "(io_id)" },   { $pull: { history: null } } )

個人 Mac 常用快捷鍵

切換 chrome profile  command + shift + M 切換輸入法 control + option + space

Visual Studio Code 常忘功能 VSC FAQ

進入多 cursor 編輯 需要統一修改特定的字串時,可以先選取其中一個,再透過 Command + Shift + L 一次選取所有同樣的字串 按住 Command + Option,再按上/下,可以延伸 cursor 至相鄰行 選取一段文字後,按 Shift + Option + i

[待解之謎] update Opportunity.AccountId 時觸發了不應觸發的 email alert

圖片
 已進行實驗: 原地 edit and save oppotutniy,未更新任何欄位。 沒有觸發 workflow/email alert edit oppotutniy,隨便填個不重要的欄位(eg. lost reason) ,and save。 沒有觸發 workflow/email alert update opportunity.AccountId,改掛到另一個 account 意外觸發了 workflow/email alert Workflow criteria:  created, and any time it's edited to subsequently meet criteria rule 僅用到 stage and record type 兩個欄位

ISC2 CC (Certified in Cybersecurity Certification) 考試心得

前言 我大概花兩個下午把 ISC2 的官方課程看一看就去考了。 官方課程的單元共有五章,我只來得及看完前三章。而後來實際應考的時候,差不多就是每五題裡面我也就只會三題😆 屬於有看就會,沒看就猜的簡單考試。 基本上我覺得這個考試題目並不難,唸書方式也沒什麼特異,所以這篇文會講一些其它的考試注意事項。 這個證照是給誰考的? 我感覺這些內容是設計給大學生或是剛出社會的初階新手的。讓你對於「什麼是資安」有一個基本的感覺。 考試流程 我的考試地點就在台北市政府捷運站旁,台北市信義區基隆路一段163號12樓-3 聯合世紀大樓。交通非常方便。 上到12樓直接推門進入來到櫃台。 注意,進此門之後就不能再看書或其它應考的材料了。 我原本報名時是選下午三點的時段,不過我兩點出頭提早到了,也是可以直接隨到隨考。感覺是只要有空位就可以讓你考。 驗證身份時要提出雙證件。 我當天有準備了護照,但是後來只拿出了身份證和健保卡而已。據說有簽名的信用卡也可以當作證件之一。 驗證身份的同時要採集掌紋,左右手都要。然後會給你一個置物櫃鑰匙。 手機要關機收好、手錶要除下,口袋內不能有東西,如果有水的話要放到專門的置水區。但身份證要拿著,待會進考場之前還要再驗一次。 放好背包、鎖上置物櫃後,此時可以先上個廁所。 轉進內室就會看到考場了。 有別於我之前考 Salesforce 證照時一人被關在一小間房間的經驗,這裡的考場是多人在同一大間,電腦座位之間用隔板隔開。 現場有提供耳塞和耳罩,以免考生互相干擾。 進場前會口頭詢問身份,並再驗一次身份證,再掃一次掌紋。監考員就會給你一面手寫板以及一支筆,引你入場坐下。 考題 共 100 題,四選一單選題。 我選的是中文版的考題,不過每一題都還是可以查看英文原文。這個蠻有幫助的。 考題的中文翻譯看起來還是有比較嚴謹的,我沒看出任何不適當的翻譯。不像線上課程教材的翻譯都亂翻。 線上課程 ISC2 提供的 CC 線上課程也有簡體中文和英文可以選。我不客氣地老實說一句,中文版教材的翻譯超爛。 完全看得出是機器翻譯自動亂翻,而且未經人工校對。我在看課程的時候,多次都有衝動想要寄信給 ISC2 請他雇用我來協助翻釋。 課程翻譯翻得好,可以增進學習效率,節省千千萬萬個學生的寶貴時間。 課程翻譯不用心,真的就是在誤人子弟了。 而且品質這麼差的翻譯,也讓人對 ISC2 這個組織的形象大