How do I copy custom fields from one object to another?
Here's how you can copy custom fields from one object to another. In this example, we'll create a custom field in the Account object and copy it to the Subscription object.
Note: Access to a sandbox and Application Composer are required in
this procedure.
- Begin by creating a custom field for the Account object: Navigate to .
- For this scenario, we're using a fixed choice list, so create a fixed choice list and set its list of values. Take note of the API Name since we'll use this later in this procedure.
- Next, navigate to .
- Select the Edit Organization Details Region in the Details Page section.
- Using the Available Fields list, highlight your recently created field and move it to the Selected Fields list.
- Save and close and page.
- Let's move on to the Subscription object: Look for it under the Standard Objects list and expand it.
- Select Fields and create a new, custom field. We're using a simple text object, so make sure that it can hold the length of the values for the fixed choice list.
- Navigate to Pages and select the Details Page Layout. Duplicate the standard layout and edit the copy.
- Click the pencil icon near Edit Subtab: Summary.
- Using the Available Fields list, highlight your recently created field and move it to the Selected Fields list.
- Now let's create a trigger: Begin by selecting Server Scripts .
- In the Triggers field, create a new trigger and set these
values:
- Trigger Name: Name the trigger something easy to remember, like PartyChange.
- Field Name: Name the field PrimaryPartyId.
- In the Trigger Definition use this sample
code:
def org = newView('OrganizationProfile'); def view_Criteria = newViewCriteria(org); def view_criteria_row = view_Criteria.createRow(); def view_condition = view_criteria_row.ensureCriteriaItem('PartyId'); view_condition.setOperator('='); view_condition.setValue(PrimaryPartyId); view_Criteria.insertRow(view_criteria_row); org.appendViewCriteria(view_Criteria); org.setMaxFetchSize(1); org.executeQuery(); if(org.hasNext()) { def o = org.next(); setAttribute('*REPLACE WITH ATTRIBUTE NAME OF CUSTOM SUBSCRIPTION FIELD *',o.*API Name for the Custom field in Account*) //For example //setAttribute('MyCustomSubText_c',o.CustomFCLTest_c)
-
Save your changes and test the change: Go to Setup and Maintenance and search for the Manage Customers task.
- Search for and select an organization and verify that the custom fixed choice list you created is available in the organization information page.
- Select a value, save your changes, and close the page.
- Go to Subscription Management and create a new subscription.
Be sure to select the customer from the previous organization that you queried in the Manage Customers task.
- In the Overview page, you should see the custom field for Subscription Management with the previously selected value.