You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Salesforce:如何将Account对象值填充至自定义对象字段

Hey there! Let's break down how to pull values from your Accounts/Organizations object into your Regrant Request custom object records. Based on what you've shared, here are a few practical approaches tailored to different needs:

1. Formula Fields (Quickest for Real-Time Display)

If you just need to display the Account values in Regrant Request records (no need to store them permanently), formula fields are your best bet—they sync automatically with the source Account:

  • Navigate to your Regrant Request object's field settings
  • Create a new Formula Field, pick the same data type as your target (text, since Project Name and Account Balance are text fields)
  • Use this formula structure (swap in your actual API field names):
    Related_Project__r.Project_Name__c
    
  • Repeat for Account Balance, and save. The field will now show the latest value from the linked Account without any extra work.

2. Salesforce Flow (No-Code Automation for Stored Values)

If you need to store the Account values in Regrant Request fields (for editing, offline access, or reporting), a Record-Triggered Flow is perfect:

  • Go to Setup → Flows → Create a Record-Triggered Flow
  • Set the trigger to fire when a Regrant Request record is created or updated, and filter for when the linked Accounts/Organizations field (you’ll need this lookup/master-detail field first!) has a value
  • Add a Get Records element to fetch the matching Account record, using the filter: Id = {!$Record.Related_Project__c}
  • Add an Update Records element to populate your Regrant Request fields with the values from the fetched Account (e.g., assign Get_Records_Name.Project_Name__c to your Regrant Request's Project Name field)
  • Activate the Flow, and all new/updated Regrant Request records will auto-sync the Account values.

3. Apex Trigger (Code for Complex Logic)

If you have advanced rules (like batch updating old records, or multi-condition matching), an Apex trigger can handle it:

trigger SyncAccountToRegrantRequest on Regrant_Request__c (before insert, before update) {
    // Collect all linked Account IDs from incoming records
    Set<Id> accountIds = new Set<Id>();
    for (Regrant_Request__c req : Trigger.new) {
        if (req.Related_Project__c != null) {
            accountIds.add(req.Related_Project__c);
        }
    }

    // Fetch the corresponding Account records
    Map<Id, Account> accountMap = new Map<Id, Account>([
        SELECT Id, Project_Name__c, Account_Balance__c 
        FROM Account 
        WHERE Id IN :accountIds
    ]);

    // Populate Regrant Request fields with Account values
    for (Regrant_Request__c req : Trigger.new) {
        Account linkedAccount = accountMap.get(req.Related_Project__c);
        if (linkedAccount != null) {
            req.Synced_Project_Name__c = linkedAccount.Project_Name__c; // Replace with your target field API name
            req.Synced_Account_Balance__c = linkedAccount.Account_Balance__c;
        }
    }
}
  • Remember to replace the placeholder API names with your actual field names
  • Test thoroughly to cover create, update, and bulk operation scenarios.

Bonus: Matching by Project Name (No Linking Field)

If you don’t have a lookup field and need to match via the Project Name text field:

  • In Flow: Set your Get Records filter to Project_Name__c = {!$Record.Project_Name__c} (ensure Project Names are unique to avoid multiple matches)
  • In Apex: Collect all Project Names from Regrant Requests, query Accounts where Project_Name__c IN :projectNames, then match by name to assign values.

内容的提问来源于stack exchange,提问作者Benjamin Russell

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:33:37