• lkp
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi I have a trigger that requires a Contact Role to be provided for each Opportunity (the code is below).  On the Opportunity I also have workflows that are field updates to the record for timestamps when the Opportunity Stage gets changed.  The issue I am having is the since the Order of Execution has workflow's go first, the trigger is firing off on Opportunity creation.  Since the Contact Roles is on a related list, you can not add a Contact Role until after first edit after save.  With this, I can not save any Opportunity since the trigger has already fired off.  I'm not sure if there is a work around to fire off the trigger after save so I don't affect the field update workflows.

Here is the code:

trigger Opportunity_Contact_Required on Opportunity (before update, after update) {
    Set<Id> allOpptyIds = new Set<Id>();
    Set<Id> OpptyswithContactsIds = new Set<Id>();

     // fetch all the Opportunity Id's in SFDC and throw in list
     for(Opportunity opp : trigger.new)
     {
              allOpptyIds.add(opp.Id);   
     }
    

     // fetch Opportunity Id's that have a Primary Contact associated and throw in list
     for(OpportunityContactRole co : [Select OpportunityId, IsPrimary From OpportunityContactRole Where OpportunityId IN : allOpptyIds ])
     {
         if((co.IsPrimary == True))
         {
               OpptyswithContactsIds.add(co.OpportunityId);             
         }
         
     }

     // compare the two sets (one has all Opportunity Id's and other has just Opportunity Id's with a Primary Contact)
     // Left out Opportunity should not be allowed to be edited until a Primary Contact is associated with the Opportunity, so we throw an error.
     for(Opportunity o : trigger.new)
     {
           if(allOpptyIds.contains(o.Id) && !OpptyswithContactsIds.contains(o.Id))
                o.addError('At least one Primary Contact Role is required on the Opportunity.');
     }
}
  • November 19, 2014
  • Like
  • 0
I have this formula to caclulate the age of an employee:


IF(ISBLANK(Birthdate__c),
0,
IF(TODAY()-DATE(YEAR(TODAY()),MONTH(Birthdate__c),DAY(Birthdate__c))<0,
YEAR(TODAY())-YEAR(Birthdate__c)-1,
YEAR(TODAY())-YEAR(Birthdate__c)
)
)

There is one person with their birthdate on on a Leap year and is giving me #ERROR in the Age field.  What can I do to add Leap year information?

Thanks.
  • October 06, 2014
  • Like
  • 0

Hi,

I need to know if Apex Sharing overrides Sharing Rules/Organization Wide Defaults/Role Hierarchy?  My orginization has Apex Sharing that we are trying to remove all together but there are still some triggers/class that are active.  We have set up Sharing Rules/Organization Wide Defaults/Role Hierarchy and it is working for all objects (standard and custom) except 2 objects.  It's like the system is not recognizing the private on Organization Wide Defaults for the 2 new objects.  If anyone can help, that would be great.
 

Thanks!

  • April 02, 2014
  • Like
  • 0
I have this formula to caclulate the age of an employee:


IF(ISBLANK(Birthdate__c),
0,
IF(TODAY()-DATE(YEAR(TODAY()),MONTH(Birthdate__c),DAY(Birthdate__c))<0,
YEAR(TODAY())-YEAR(Birthdate__c)-1,
YEAR(TODAY())-YEAR(Birthdate__c)
)
)

There is one person with their birthdate on on a Leap year and is giving me #ERROR in the Age field.  What can I do to add Leap year information?

Thanks.
  • October 06, 2014
  • Like
  • 0
Hi,

I need to create one formula field (returns number) which will calculate Case Age (In days) such that it will keep incrementing until case is closed. If the case is closed it will stop counting. This excludes weekends.

Can someone please help me on this?

Thanks,
Pooja