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
ylandraylandra 

unit test for Opportunity from contact

I have a trigger that updates fields on the opportunity from contact fields when the opportunity is created from the contact.  The problem I have discovered is that there seems to be no way to simulate this in a unit test.

Does anyone have any ideas about how to test this?
Sonam_SFDCSonam_SFDC
I understand that the trigger is written on the Opportunity Object as the trigger runs when an opportunity is created.

You can write a test class which creates an Opportunity and then compare the fields values for the contact and Opportunity to see if the trigger has updated the opportunity field correctly.

Hoping I've understood your requirement correctly..
ylandraylandra
Sorry, I meant to reference the fact that an Opportunity Contact Role is also created during this process and that is the part that cannot be replicated in a unit test (as far as I know).  I understand how to write a unit test for updated fields on an Opportunity, just not one that can replicate the Contact Role being created so that I can compare fields based between the contact and the opportunity (linked by the Contact role created during the New Opportunity process on a Contact record).

Does that make more sense?