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
lcefalolcefalo 

Getting an error and not sure why?

 

Hi All,

 

I am getting an error and I cant see what in the APEX Trigger is cauing the error in the vlaidation rule.

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger Contact_Opportunity_Synch caused an unexpected exception, contact your administrator: Contact_Opportunity_Synch: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0067000000NfCxeAAF; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Number of Contacts Purchased, NetProspex Product, Seats Purchased & Industry are required for any stage greater or equal to Proposal. THIS REPLACES THE CLOSED WON WIZARD!: []: Trigger.Contact_Opportunity_Synch: line 43, column1

 

here is the validation rule:

AND ( 
OR ( 
ISPICKVAL( StageName, "Proposal / TOS"), 
ISPICKVAL( StageName, "Closing Stage"), 
ISPICKVAL( StageName, "Closed Won")),OR( 
ISBLANK( of_Contacts_Purchased__c ), 
ISBLANK(TEXT( Industry__c )), 
ISBLANK(TEXT( NetProspex_Product__c)), 
ISBLANK( Seats_Purchased__c ) 
))

 

And thenthe APEX Trigger:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

trigger Contact_Opportunity_Synch on Contact (after update) {

  Map <Id, Contact> ContactMap = new Map <Id, Contact>();

  for(Contact c : Trigger.New) {
    if(c.title != Trigger.OldMap.get(c.id).title
     ||c.phone != Trigger.OldMap.get(c.id).phone
     ||c.Email != Trigger.OldMap.get(c.id).Email
     ||c.MailingCity != Trigger.OldMap.get(c.id).MailingCity
     ||c.MailingState != Trigger.OldMap.get(c.id).MailingState
     ||c.MailingStreet != Trigger.OldMap.get(c.id).MailingStreet
     ||c.MailingCountry != Trigger.OldMap.get(c.id).MailingCountry
     ||c.MailingPostalCode != Trigger.OldMap.get(c.id).MailingPostalCode
    ) {
         ContactMap.put(c.id, c);
    }
    
  }
  
  List <Opportunity> OppsToUpdate = new List <Opportunity>();
  
  for(Opportunity o : [Select id, primary_contact__c,Primary_Contact_Title__c,Primary_Contact_Email__c,Primary_Contact_Phone__c,Primary_Mailing_City__c,Primary_Mailing_Country__c,Primary_Mailing_State__c,Primary_Mailing_Street__c,Primary_Mailing_Zip__c from Opportunity where primary_contact__c in :ContactMap.keySet() and isClosed = false]) {
        
      o.Primary_Contact_Title__c = ContactMap.get(o.Primary_Contact__c).title;
          o.Primary_Contact_Email__c = ContactMap.get(o.Primary_Contact__c).email;
          o.Primary_Contact_Phone__c = ContactMap.get(o.Primary_Contact__c).phone;
          o.Primary_Mailing_City__c  = ContactMap.get(o.Primary_Contact__c).MailingCity;
          o.Primary_Mailing_Country__c = ContactMap.get(o.Primary_Contact__c).MailingCountry;
          o.Primary_Mailing_State__c = ContactMap.get(o.Primary_Contact__c).MailingState;
          o.Primary_Mailing_Street__c = ContactMap.get(o.Primary_Contact__c).MailingStreet;
          o.Primary_Mailing_Zip__c = ContactMap.get(o.Primary_Contact__c).MailingPostalCode;
    
      OppsToUpdate.add(o);
      
      if(OppsToUpdate.size() == 200) {
        update OppsToUpdate;
        OppsToUpdate.clear();
      }
    
  }

  if(OppsToUpdate.size() > 0)
    update OppsToUpdate;








}

Any help would be appreciated!!

Thanks,

Leif

 
Best Answer chosen by Admin (Salesforce Developers) 
steve456steve456

 

Number of Contacts Purchased, NetProspex Product, Seats Purchased & Industry are required for any stage greater or equal to Proposal..........................................Make sure you give all these fields in the for loop and update them too or give a stage lesser than "Proposal"

 

 

for(Opportunity o : [Select id, primary_contact__c,Primary_Contact_Title__c,Primary_Contact_Email__c,Primary_Contact_Phone__c,Primary_Mailing_City__c,Primary_Mailing_Country__c,Primary_Mailing_State__c,Primary_Mailing_Street__c,Primary_Mailing_Zip__c from Opportunity where primary_contact__c in :ContactMap.keySet() and isClosed = false]) {

All Answers

steve456steve456

 

Number of Contacts Purchased, NetProspex Product, Seats Purchased & Industry are required for any stage greater or equal to Proposal..........................................Make sure you give all these fields in the for loop and update them too or give a stage lesser than "Proposal"

 

 

for(Opportunity o : [Select id, primary_contact__c,Primary_Contact_Title__c,Primary_Contact_Email__c,Primary_Contact_Phone__c,Primary_Mailing_City__c,Primary_Mailing_Country__c,Primary_Mailing_State__c,Primary_Mailing_Street__c,Primary_Mailing_Zip__c from Opportunity where primary_contact__c in :ContactMap.keySet() and isClosed = false]) {

This was selected as the best answer
lcefalolcefalo

Thanks for the info. I'm now looking thinking I might just kill that legacey APEX trigger.  I can get the smae info it was getting with out of the box functionaility.

 

Thanks again!