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
koti91koti91 

Need Help in a trigger

i had two objects Lead and a custom object named: thisoppurtunity(tO).

 

thisoppurtunity(tO) had a look up to lead. thisoppurtunity  has  custom fileds check box named: primarytO(Read Only Field)

and primaryoverride .

 

now my requirement is:

when ever a tO gets created or updated . i need to make sure that tO is the only tO on the lead with primarytO field checked.i.e  a Lead can have only one tO as primarytO

 

only one tO can be primary for a lead.if there is only one tO for a lead ,it will be default be the primary

when a second tO is added if that needs to be primary then user needs to then click on the primaryoverride checkbox   to then switch the primarytO flag- also at that point primaryoverride field will be unchecked.

and also as per ownership the ownership of primary tO is reflected on the lead(i.e lead owner will be same as the owner of primary tO).

 

 

I am trying to write the logic this way but could not complete it. 

 

when trigger is fired :

checks for the primary tO

   if the tO is the only tO on the lead it leaves the primarytO flag turned on

   if there is more than one tO it ensures there is always only one primarytO

   if a primary override flag is checked it transfers the primarytO flag over to requesting tO

      steps:

         1) sets the old primarytO flag to false

         2) sets the requesting tO flag to true

         3) unchecks the primaryoverride flag on the requesting tO

  on the next iteration of trigger batch if the tO is marked as primary it updates the lead with same owner .

 

can any one help me in writing a trigger for this. Trigger should be ia bulkify way.