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.
  1. Begin by creating a custom field for the Account object: Navigate to Application Composer > Account > Fields.
  2. 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.
  3. Next, navigate to Pages > Application Pages.
  4. Select the Edit Organization Details Region in the Details Page section.
  5. Using the Available Fields list, highlight your recently created field and move it to the Selected Fields list.
  6. Save and close and page.
  7. Let's move on to the Subscription object: Look for it under the Standard Objects list and expand it.
  8. 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.
  9. Navigate to Pages and select the Details Page Layout. Duplicate the standard layout and edit the copy.
  10. Click the pencil icon near Edit Subtab: Summary.
  11. Using the Available Fields list, highlight your recently created field and move it to the Selected Fields list.
  12. Now let's create a trigger: Begin by selecting Server ScriptsTriggers.
  13. 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)
      
  14. Save your changes and test the change: Go to Setup and Maintenance and search for the Manage Customers task.

  15. Search for and select an organization and verify that the custom fixed choice list you created is available in the organization information page.
  16. Select a value, save your changes, and close the page.
  17. 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.

  18. In the Overview page, you should see the custom field for Subscription Management with the previously selected value.