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
RVJRVJ 

Trigger Help - To Show Primary Partner on Opportunity Page

We are implementing using SF Approval workflow for our opportunities. Part of the entry criteria and step criteria needs to be on the Primary partner - something like this: *If the Primary Partner on the opportunity = 'my company' then 'step 1' else *If the Primary Partner on the opportunity <> 'my company' then 'step 2'.

 

What I would really, really like is to be able to pull through the Primary Partner account name into a blank field on the opportunity - I could then use this field in filters etc.

I cannot see anywhere an option to lookup on Primary parent is any of the filters. As part of an existing validation rule we do already have an apex trigger set up to show if the primary partner is assigned on an opportunity by updating a checkbox on the opportunity (trigger below), this works fine for its purpose but I think I need to clone and modify it to achieve the above, but just not sure where to start, any help much appreciated!


trigger updatepartnercount on Opportunity (before insert, before update)
{

Boolean isPrimary;
Integer iCount;

Map<String, Opportunity> oppty_con = new Map<String, Opportunity>();//check if the contact role is needed and add it to the oppty_con map
for (Integer i = 0; i < Trigger.new.size(); i++)
{
oppty_con.put(Trigger.new[i].id,
Trigger.new[i]);
}
isPrimary = False;
for (List<Opportunitypartner> oppcntctrle :[select OpportunityId from Opportunitypartner where (Opportunitypartner.IsPrimary = True and Opportunitypartner.OpportunityId in :oppty_con.keySet())])
{
if (oppcntctrle .Size() >0)
{
isPrimary = True;
}
}
iCount = 0;
for (List<Opportunitypartner> oppcntctrle2 : [select OpportunityId from Opportunitypartner where (Opportunitypartner.OpportunityId in :oppty_con.keySet())])//Query for Contact Roles
{
if (oppcntctrle2 .Size()>0)
{
iCount= oppcntctrle2 .Size();
}
}
for (Opportunity Oppty : system.trigger.new) //Check if roles exist in the map or contact role isn't required
{
Oppty.Number_of_partners__c = iCount;
Oppty.Primary_partner_Assigned__c =isPrimary;
}