function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Lookup relationship - Opportunity and Custom Object

Hi All,

I've created a lookup field from the Opportunity to the custom Object, in order to reference different values from the custom Object on the Opportunity. The custom Object holds the products lines from another system. For one Opportunity in Salesforce, there can be up to 2 Orders in the other system. The product lines are being created as separate lines on the custom object.

I want to be able to show on the Opportunity in Salesforce:
  • the default Order number from the other system
  • the second Order number from the other system, if it exists. (there is a checkbox on all the product lines, if they are related to the second Order)
  • change pick-list value on the Opportunity, based on the values of a field on the related records from the custom Object.
What I have tried so far:
  • Trigger to update the order numbers from the other system - in two separate fields on the Opportunity in Salesforce (custom field 1 and custom field 2)
  • PB on the custom object - to change the pick-list values, but the process failed when trying to check if the related records are related to the same Opportunity number in Salesforce). the lookup field not being populated, so I have tried to create a trigger to populate the lookup with the id of one of the related records and create the custom field 1 and custom field 2 as formula fields, instead of using trigger.
Custom field 1:
IF(Custom_Object__r.Check_Box__c = FALSE, Custom_Object__r.custom_field1__c, null)

Custom field 2:
IF(Custom_Object__r.Check_Box__c = TRUE, Custom_Object__r.custom_field2__c, null)

But it doesn't fulfill the requirement, because the Opportunity in Salesforce will always have a default order from the other system, so depending what id I am filling in the lookup, the formula doesn't always populate the default order number, also the second order number needs to be populated, when the checkbox on the related records is true.

Any help will be appreciated on how it's best to achieve the requirements.

Thanks a lot.