• Mark Liu
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 4
    Questions
  • 7
    Replies
Hello,

I have written a few triggers for my company's org, all seems to be working correctly except one on Account... It was working for the last few months and just today, I have noticed that it stopped working. There is no error message, it just does nothing.

The code coverage for this code is 100% given the test class is in place.

This is an "After" trigger, in which I have switched to "Before" and again, it works in Sandbox, but does nothing in Production... So I have switched it back to the original state when it worked the first few months after I have deployed it into Production. I have also checked and made sure that all custom validation rules on Accounts and Contacts are mirroring each other between Sandbox and Production.

See code below. Any help or explanation is greatly appreciated!!! Thanks in advance!
 
trigger moveContactsOutOfView on Account (After Update) {
      if(checkRecursive.runOnce()){

  set<String> notAccId = New Set<String>();     
  set<String> accId = New Set<string>();
  List<Contact> conUpdate = new List<Contact>();
  List<Contact> con1Update = new list<Contact>();
  List<AccountTeamMember> d1 = new List<AccountTeamMember>();
  
      for (Account a1: trigger.new){
      if (a1.ID != null && a1.Move_out_of_view__c == true && a1.LastModifiedById != '00500000006xZUv' && a1.LastModifiedById != '00500000006wsIm' && a1.LastModifiedById != '00500000006xdMm' && a1.LastModifiedById != '00500000006wnoE'){
          accId.Add(a1.ID);
          }
      else if(a1.ID != null && a1.Move_out_of_view__c == false && a1.LastModifiedById != '00500000006xZUv' && a1.LastModifiedById != '00500000006wsIm' && a1.LastModifiedById != '00500000006xdMm' && a1.LastModifiedById != '00500000006wnoE'){
        notAccId.add(a1.ID);
        
        }
      }
                                   
  LIST<Contact> cY = [SELECT AccountID, LastModifiedById FROM Contact WHERE AccountID In: AccId];
  LIST<Contact> cN = [SELECT AccountID, LastModifiedById FROM Contact WHERE AccountID In: notAccId];
  List<AccountTeamMember> toBeDeleted =[SELECT ID, LastModifiedById FROM AccountTeamMember WHERE AccountID In: AccId];

       for (Account a1: trigger.new){
            for (Contact c1:cY){
                if (c1.LastModifiedById != '00500000006xdMm' && c1.LastModifiedById != '00500000006wnoE' && c1.LastModifiedById != '00500000006wsIm' && c1.LastModifiedById != '00500000006xZUv'){
                    c1.Move_out_of_view__c = True;
                    conUpdate.add(c1);
                }
            }
            for (Contact c2:cN){
                if (c2.LastModifiedById != '00500000006xdMm'&& c2.LastModifiedById != '00500000006wnoE' && c2.LastModifiedById != '00500000006wsIm' && c2.LastModifiedById != '00500000006xZUv'){
                    c2.Move_out_of_view__c = False;
                    con1Update.add(c2);
                }
            }
       }
          for (AccountTeamMember t1:toBeDeleted){
                if (t1.LastModifiedById != '00500000006xdMm' && t1.LastModifiedById != '00500000006wnoE' && t1.LastModifiedById != '00500000006wsIm' && t1.LastModifiedById != '00500000006xZUv'){
                    d1.add(t1);
                }
          }
    

try{ 
update conUpdate;
}

catch (DMLException e) {
            for (Account con : trigger.new) {
                con.addError(e.getDmlMessage(0));
            }
        }
try{
update con1Update;
}
catch (DMLException a){
	for (Account acc:trigger.new){
		acc.addError(a.getDmlMessage(0));
	}
}
try{
delete d1;
}
catch (DMLException b){
	for (Account acc1:trigger.new){
		acc1.addError(b.getDmlMessage(0));
	}
}
        
        
        
}

}





 
Hi all,

I have tried to search up on this for a while now but couldn't find any answer to my question... I have wrote a simple trigger that when an Account record is moved out of view (Moved out of view = true), then all the contacts associated with that specific account will be automatically marked as moved out of view (Moved out of view = true). Trigger works in sandbox and also before this incident, I was able to deploy this into production, but now as I was trying to add onto the same existing test class, I have noticed through System.assertEquals() that the trigger is not firing... Can someone please help explain what's going on? Thanks in advance...

Trigger:
trigger moveContactsOutOfView on Account (After Update) {
	if(checkRecursive.runOnce()){
  set<String> notAccId = New Set<String>();		
  set<String> accId = New Set<string>();
  List<Contact> conUpdate = new List<Contact>();
  List<Contact> con1Update = new list<Contact>();
  List<AccountTeamMember> d1 = new List<AccountTeamMember>();
  
      for (Account a1: trigger.new){
      if (a1.ID != null && a1.Move_out_of_view__c == True){
          accId.Add(a1.ID);
          }
      else {
      	notAccId.add(a1.ID);
      	}
      }
                                   
  LIST<Contact> cY = [SELECT AccountID, LastModifiedById FROM Contact WHERE AccountID In: AccId];
  LIST<Contact> cN = [SELECT AccountID, LastModifiedById FROM Contact WHERE AccountID In: notAccId];
  List<AccountTeamMember> toBeDeleted =[SELECT ID, LastModifiedById FROM AccountTeamMember WHERE AccountID In: AccId];

       for (Account a1: trigger.new){
          	for (Contact c1:cY){
          		if (c1.LastModifiedById != '00500000006xdMm' && c1.LastModifiedById != '00500000006wnoE' && c1.LastModifiedById != '00500000006wsIm'){
            		c1.Move_out_of_view__c = True;
              		conUpdate.add(c1);
          		}
            }
          	for (Contact c2:cN){
          		if (c2.LastModifiedById != '00500000006xdMm'&& c2.LastModifiedById != '00500000006wnoE' && c2.LastModifiedById != '00500000006wsIm'){
          	  		c2.Move_out_of_view__c = False;
          	  		con1Update.add(c2);
          		}
          	}
       }
          for (AccountTeamMember t1:toBeDeleted){
          		if (t1.LastModifiedById != '00500000006xdMm' && t1.LastModifiedById != '00500000006wnoE' && t1.LastModifiedById != '00500000006wsIm'){
          			d1.add(t1);
          		}
          }
    
update conUpdate;
update con1Update;
delete d1;
	}
}

test class:
@isTest
public class TestPrimaryLiaisonCount2{
    static testMethod void insertNewContact(){
    
    //NEW Account record
    Account ACC = new Account();
    ACC.recordtypeID = '012000000000j8S';
    ACC.Name = 'Liu Inc';
    ACC.Industry = 'Advertising';
    ACC.NumberOfEmployees = 500;
    ACC.Center__c = 'Full Service';
    ACC.Move_out_of_view__c = False;
    insert ACC;
    
    string accId = ACC.id;
    
    //NEW Contact record for 'ACC'
    Contact ACDC = new Contact();
    ACDC.FirstName = 'Testing';
    ACDC.LastName = 'DEV';
    ACDC.Primary_Liaison__c = 'Center';
    ACDC.AccountID = ACC.Id;
    insert ACDC;
    
    ACDC = [SELECT Id, AccountID, Move_out_of_view__c FROM Contact WHERE AccountID =: accId limit 1];
    system.assertEquals(false, ACDC.Move_out_of_view__c);
    
    ACC.Move_out_of_view__c = True;
    update ACC;
    
    ACDC = [SELECT Id, AccountID, Move_out_of_view__c FROM Contact WHERE AccountID =: accId limit 1];
    system.assertEquals(true, ACDC.Move_out_of_view__c);
    }
 }

 
Trigger and test class works in Sandbox with 100% code coverage (trigger code listed below)

I have checked the following:
1.My code coverage in Production is 98% and Sandbox is 94% according to Salesforce's "Developer Console"
2. I have turned off all Validation and Workflow rule in production to make sure it's not an issue with these rules before deployment (same result of 38% overall coverage where at least 75% is required)

I have reached with the conclusion that my trigger below is somehow breaking Apex Test Classes that are in place when I try to deploy, because along with the "38%" error message, it tells me that there are 5 other triggers (that are successfully deployed previously in production and is in production with 100% coverage) with 0% test coverage during deployment.

Please see my trigger below and please help resolve this mistery, thanks! 
(P.S. This trigger had worked before but I added MAP near the bottom of this new trigger hoping that this would resolve any issues when our users use CRM tools like Dataloader to mass update/insert old/new Contact records).
 
trigger primaryLiaisonCount2 on Contact(after update) {
  if(checkRecursive.runOnce())
  {
    List<Account> accList = new List<account>();
    List<Account> accListToUpdate = new List<account>();
    Set<Account> accSet = new Set<Account>();
    set<String> allAccIds = new Set<String>();    
    
    for (Contact c1: trigger.new){
        if (c1.Contact_ID_18_Characters__c != null){
        allAccIds.add(c1.AccountID);} }
   
   
    decimal amount1=[SELECT count() FROM Contact WHERE AccountID IN :allAccIds AND Primary_Liaison__c != null AND Marketing_Status__c != 'Gone From Company' LIMIT 25];
    LIST<Account> acc1=[SELECT ID FROM Account WHERE ID IN :allAccIds AND recordtypeID ='012000000000j8S' LIMIT 25];                             
       
    MAP<String, Account> firstMap = new MAP<String, Account>();
   for (Account acc2: acc1){
    firstMap.put(acc2.id, acc2);
   }
    
    for (Contact c1: trigger.new){
   Account acc3 = firstMap.get(c1.accountId);
   acc3.Primary_Liaisons__c = amount1;
   accList.add(acc3);                           
                        }
                                  
accSet.addall(accList);
accListToUpdate.addall(accSet);
Update accListToUpdate;
  }
  }
Best regards,
Mark
 
Hey guys,

Was wondering if someone could help me out… I have built a trigger(below) to count the amount of contacts (that are marked as Primary Liaisons) in each account (of a certain account type) and this number is reported on a custom field that resides on each Account. However, whenever I use dataloader or any other CRM tools to mass update contacts, it gives me this error: “caused by: System.ListException: Duplicate id in list: 001……..” I believe it’s because many accounts of this specific record type have multiple contacts, therefore it was trying to update the same Account over and over again causing duplicate IDs?

Please let me know what I can do to resolve this duplicate ID issue. Help is much appreciated! :)

trigger primaryLiaisonCount2 on Contact(after update) {
LIST<account> accList = new List<account>();
set<String> allAccIds = new Set<String>();

for (Contact c1: trigger.new){
if (c1.Contact_ID_18_Characters__c != null){
allAccIds.add(c1.AccountID);} }

Decimal amount1=[SELECT count() FROM Contact WHERE AccountID IN :allAccIds AND Primary_Liaison__c != null AND Marketing_Status__c != 'Gone From Company' LIMIT 25];

LIST<account> acc1=[SELECT ID FROM Account WHERE ID IN :allAccIds AND recordtypeID ='012000000000j8S' LIMIT 25];

for (Contact c1: trigger.new){

for (Account acc2:acc1){
acc2.Primary_Liaisons__c = amount1;
accList.add(acc2);

}
}
Update accList;
}
Hello,

I have written a few triggers for my company's org, all seems to be working correctly except one on Account... It was working for the last few months and just today, I have noticed that it stopped working. There is no error message, it just does nothing.

The code coverage for this code is 100% given the test class is in place.

This is an "After" trigger, in which I have switched to "Before" and again, it works in Sandbox, but does nothing in Production... So I have switched it back to the original state when it worked the first few months after I have deployed it into Production. I have also checked and made sure that all custom validation rules on Accounts and Contacts are mirroring each other between Sandbox and Production.

See code below. Any help or explanation is greatly appreciated!!! Thanks in advance!
 
trigger moveContactsOutOfView on Account (After Update) {
      if(checkRecursive.runOnce()){

  set<String> notAccId = New Set<String>();     
  set<String> accId = New Set<string>();
  List<Contact> conUpdate = new List<Contact>();
  List<Contact> con1Update = new list<Contact>();
  List<AccountTeamMember> d1 = new List<AccountTeamMember>();
  
      for (Account a1: trigger.new){
      if (a1.ID != null && a1.Move_out_of_view__c == true && a1.LastModifiedById != '00500000006xZUv' && a1.LastModifiedById != '00500000006wsIm' && a1.LastModifiedById != '00500000006xdMm' && a1.LastModifiedById != '00500000006wnoE'){
          accId.Add(a1.ID);
          }
      else if(a1.ID != null && a1.Move_out_of_view__c == false && a1.LastModifiedById != '00500000006xZUv' && a1.LastModifiedById != '00500000006wsIm' && a1.LastModifiedById != '00500000006xdMm' && a1.LastModifiedById != '00500000006wnoE'){
        notAccId.add(a1.ID);
        
        }
      }
                                   
  LIST<Contact> cY = [SELECT AccountID, LastModifiedById FROM Contact WHERE AccountID In: AccId];
  LIST<Contact> cN = [SELECT AccountID, LastModifiedById FROM Contact WHERE AccountID In: notAccId];
  List<AccountTeamMember> toBeDeleted =[SELECT ID, LastModifiedById FROM AccountTeamMember WHERE AccountID In: AccId];

       for (Account a1: trigger.new){
            for (Contact c1:cY){
                if (c1.LastModifiedById != '00500000006xdMm' && c1.LastModifiedById != '00500000006wnoE' && c1.LastModifiedById != '00500000006wsIm' && c1.LastModifiedById != '00500000006xZUv'){
                    c1.Move_out_of_view__c = True;
                    conUpdate.add(c1);
                }
            }
            for (Contact c2:cN){
                if (c2.LastModifiedById != '00500000006xdMm'&& c2.LastModifiedById != '00500000006wnoE' && c2.LastModifiedById != '00500000006wsIm' && c2.LastModifiedById != '00500000006xZUv'){
                    c2.Move_out_of_view__c = False;
                    con1Update.add(c2);
                }
            }
       }
          for (AccountTeamMember t1:toBeDeleted){
                if (t1.LastModifiedById != '00500000006xdMm' && t1.LastModifiedById != '00500000006wnoE' && t1.LastModifiedById != '00500000006wsIm' && t1.LastModifiedById != '00500000006xZUv'){
                    d1.add(t1);
                }
          }
    

try{ 
update conUpdate;
}

catch (DMLException e) {
            for (Account con : trigger.new) {
                con.addError(e.getDmlMessage(0));
            }
        }
try{
update con1Update;
}
catch (DMLException a){
	for (Account acc:trigger.new){
		acc.addError(a.getDmlMessage(0));
	}
}
try{
delete d1;
}
catch (DMLException b){
	for (Account acc1:trigger.new){
		acc1.addError(b.getDmlMessage(0));
	}
}
        
        
        
}

}





 
Hi all,

I have tried to search up on this for a while now but couldn't find any answer to my question... I have wrote a simple trigger that when an Account record is moved out of view (Moved out of view = true), then all the contacts associated with that specific account will be automatically marked as moved out of view (Moved out of view = true). Trigger works in sandbox and also before this incident, I was able to deploy this into production, but now as I was trying to add onto the same existing test class, I have noticed through System.assertEquals() that the trigger is not firing... Can someone please help explain what's going on? Thanks in advance...

Trigger:
trigger moveContactsOutOfView on Account (After Update) {
	if(checkRecursive.runOnce()){
  set<String> notAccId = New Set<String>();		
  set<String> accId = New Set<string>();
  List<Contact> conUpdate = new List<Contact>();
  List<Contact> con1Update = new list<Contact>();
  List<AccountTeamMember> d1 = new List<AccountTeamMember>();
  
      for (Account a1: trigger.new){
      if (a1.ID != null && a1.Move_out_of_view__c == True){
          accId.Add(a1.ID);
          }
      else {
      	notAccId.add(a1.ID);
      	}
      }
                                   
  LIST<Contact> cY = [SELECT AccountID, LastModifiedById FROM Contact WHERE AccountID In: AccId];
  LIST<Contact> cN = [SELECT AccountID, LastModifiedById FROM Contact WHERE AccountID In: notAccId];
  List<AccountTeamMember> toBeDeleted =[SELECT ID, LastModifiedById FROM AccountTeamMember WHERE AccountID In: AccId];

       for (Account a1: trigger.new){
          	for (Contact c1:cY){
          		if (c1.LastModifiedById != '00500000006xdMm' && c1.LastModifiedById != '00500000006wnoE' && c1.LastModifiedById != '00500000006wsIm'){
            		c1.Move_out_of_view__c = True;
              		conUpdate.add(c1);
          		}
            }
          	for (Contact c2:cN){
          		if (c2.LastModifiedById != '00500000006xdMm'&& c2.LastModifiedById != '00500000006wnoE' && c2.LastModifiedById != '00500000006wsIm'){
          	  		c2.Move_out_of_view__c = False;
          	  		con1Update.add(c2);
          		}
          	}
       }
          for (AccountTeamMember t1:toBeDeleted){
          		if (t1.LastModifiedById != '00500000006xdMm' && t1.LastModifiedById != '00500000006wnoE' && t1.LastModifiedById != '00500000006wsIm'){
          			d1.add(t1);
          		}
          }
    
update conUpdate;
update con1Update;
delete d1;
	}
}

test class:
@isTest
public class TestPrimaryLiaisonCount2{
    static testMethod void insertNewContact(){
    
    //NEW Account record
    Account ACC = new Account();
    ACC.recordtypeID = '012000000000j8S';
    ACC.Name = 'Liu Inc';
    ACC.Industry = 'Advertising';
    ACC.NumberOfEmployees = 500;
    ACC.Center__c = 'Full Service';
    ACC.Move_out_of_view__c = False;
    insert ACC;
    
    string accId = ACC.id;
    
    //NEW Contact record for 'ACC'
    Contact ACDC = new Contact();
    ACDC.FirstName = 'Testing';
    ACDC.LastName = 'DEV';
    ACDC.Primary_Liaison__c = 'Center';
    ACDC.AccountID = ACC.Id;
    insert ACDC;
    
    ACDC = [SELECT Id, AccountID, Move_out_of_view__c FROM Contact WHERE AccountID =: accId limit 1];
    system.assertEquals(false, ACDC.Move_out_of_view__c);
    
    ACC.Move_out_of_view__c = True;
    update ACC;
    
    ACDC = [SELECT Id, AccountID, Move_out_of_view__c FROM Contact WHERE AccountID =: accId limit 1];
    system.assertEquals(true, ACDC.Move_out_of_view__c);
    }
 }

 
Trigger and test class works in Sandbox with 100% code coverage (trigger code listed below)

I have checked the following:
1.My code coverage in Production is 98% and Sandbox is 94% according to Salesforce's "Developer Console"
2. I have turned off all Validation and Workflow rule in production to make sure it's not an issue with these rules before deployment (same result of 38% overall coverage where at least 75% is required)

I have reached with the conclusion that my trigger below is somehow breaking Apex Test Classes that are in place when I try to deploy, because along with the "38%" error message, it tells me that there are 5 other triggers (that are successfully deployed previously in production and is in production with 100% coverage) with 0% test coverage during deployment.

Please see my trigger below and please help resolve this mistery, thanks! 
(P.S. This trigger had worked before but I added MAP near the bottom of this new trigger hoping that this would resolve any issues when our users use CRM tools like Dataloader to mass update/insert old/new Contact records).
 
trigger primaryLiaisonCount2 on Contact(after update) {
  if(checkRecursive.runOnce())
  {
    List<Account> accList = new List<account>();
    List<Account> accListToUpdate = new List<account>();
    Set<Account> accSet = new Set<Account>();
    set<String> allAccIds = new Set<String>();    
    
    for (Contact c1: trigger.new){
        if (c1.Contact_ID_18_Characters__c != null){
        allAccIds.add(c1.AccountID);} }
   
   
    decimal amount1=[SELECT count() FROM Contact WHERE AccountID IN :allAccIds AND Primary_Liaison__c != null AND Marketing_Status__c != 'Gone From Company' LIMIT 25];
    LIST<Account> acc1=[SELECT ID FROM Account WHERE ID IN :allAccIds AND recordtypeID ='012000000000j8S' LIMIT 25];                             
       
    MAP<String, Account> firstMap = new MAP<String, Account>();
   for (Account acc2: acc1){
    firstMap.put(acc2.id, acc2);
   }
    
    for (Contact c1: trigger.new){
   Account acc3 = firstMap.get(c1.accountId);
   acc3.Primary_Liaisons__c = amount1;
   accList.add(acc3);                           
                        }
                                  
accSet.addall(accList);
accListToUpdate.addall(accSet);
Update accListToUpdate;
  }
  }
Best regards,
Mark
 
Hey guys,

Was wondering if someone could help me out… I have built a trigger(below) to count the amount of contacts (that are marked as Primary Liaisons) in each account (of a certain account type) and this number is reported on a custom field that resides on each Account. However, whenever I use dataloader or any other CRM tools to mass update contacts, it gives me this error: “caused by: System.ListException: Duplicate id in list: 001……..” I believe it’s because many accounts of this specific record type have multiple contacts, therefore it was trying to update the same Account over and over again causing duplicate IDs?

Please let me know what I can do to resolve this duplicate ID issue. Help is much appreciated! :)

trigger primaryLiaisonCount2 on Contact(after update) {
LIST<account> accList = new List<account>();
set<String> allAccIds = new Set<String>();

for (Contact c1: trigger.new){
if (c1.Contact_ID_18_Characters__c != null){
allAccIds.add(c1.AccountID);} }

Decimal amount1=[SELECT count() FROM Contact WHERE AccountID IN :allAccIds AND Primary_Liaison__c != null AND Marketing_Status__c != 'Gone From Company' LIMIT 25];

LIST<account> acc1=[SELECT ID FROM Account WHERE ID IN :allAccIds AND recordtypeID ='012000000000j8S' LIMIT 25];

for (Contact c1: trigger.new){

for (Account acc2:acc1){
acc2.Primary_Liaisons__c = amount1;
accList.add(acc2);

}
}
Update accList;
}

Job Applications is a custom object with a lookup relationship to the custom object Positions, A

developer would like to modify the Position fields displayed in the console mini view when a job

application record is viewed in the console detail view. What would a developer customize to

accomplish this?

 

A. the mini page layout of the position page layout

B. the related objects on the job application page layout

C. the related objects on the position page layout

D. the mini page layout on the job aplication layout

 

A developer wants to build an application on force.com platform. The data model that the users need access to applications, and the application business logic have been considered. The report and dashboard requirements have not been considered, which is true?

 

A. Data model may not be support the business logic

B. Dashboard may not be visible to management users

C. Developer will not be able to load data

D. Data model may not support the required reports

 


CreatedDate is a Date/time data type field.


What formula returns the number of days since the record was created?

 

A. TODAY() - DATEVALUE(CreatedDate)

B. CreatedDate - TODAY()

C. TODAY() - (CreatedDate)

D. NOW() - DATEVALUE(CreateDate)


When performing or updating with Data Loader, the comma delimited file must contain a column with what values?

 

A. Logical names of records

B. Profile names of record owners

C. Force.com Record IDs and Value of Record

D. Created time and date of records


A developer needs to support multiple currencies for a custom object in an application? Multi-currency has been enabled, what does the developer need to know to support the application?

(2 answers)

 

A. Must input currency ISO Field

B. Admin can add additional currencies once set up

C. Roll up summary fields will calculate incorrectly if children have multiple currencies

D. Track Currency changes automatically.


Job Applications is a custom object with a lookup relationship to the custom object Positions.

A developer would like to modify the Position fields displayed in the console mini view when a job application record is viewed in the console detail view.

What would a developer customize to accomplish this?

 

A. The mini page layout of the position page layout

B. The mini page layout on the Job application page layout

C. The related objects on the job application page layout

D. The related objects on the position page layouts

 

 

 

 

 

 

 

 

Hello,

 

We have a custom object named "Bidder & Contractors" which is linked to Opportunities via a Lookup relationship.

As we want to have Roll-up summary functionality on the opportunity counting the 'Bidders & Contractors' set to 'Won' we put in the below trigger.

 

It is working fine until you try to delete a 'Bidder & Contractor' entry, which gives the following error: 

 

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger OpportunityRollUpContractors caused an unexpected exception, contact your administrator: OpportunityRollUpContractors: execution of AfterDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.OpportunityRollUpContractors: line 6, column 1". 

 

Many thanks for your help! 

 

trigger OpportunityRollUpContractors on Bidder_Contractors__c (after delete, after insert, after update) {
 
    Set<id> OpportunityIds = new Set<id>();
    List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();
 
    for (Bidder_Contractors__c item : Trigger.new)
        OpportunityIds.add(item.Opportunity__c);
 
    if (Trigger.isUpdate || Trigger.isDelete) {
        for (Bidder_Contractors__c item : Trigger.old)
            OpportunityIds.add(item.Opportunity__c);
    }
 
    // get a map of the shipments with the number of items
    Map<id,Opportunity> opportunityMap = new Map<id,Opportunity>([select id, Contractor_Count__c from Opportunity where id IN :OpportunityIds]);
 
    // query the Opportunities and the related Competition items and add the size of the Competition items to the Opportunity's Contractor_Count__c
    for (Opportunity opp: [select Id, Name, Contractor_Count__c,(select id from Awarded_Contractors_Bidders__r WHERE Awarded__c ='Won') from Opportunity where Id IN :OpportunityIds]) {
        opportunityMap.get(opp.Id).Contractor_Count__c = opp.Awarded_Contractors_Bidders__r.size();
        // add the value/shipment in the map to a list so we can update it
        opportunitiesToUpdate.add(opportunityMap.get(opp.Id));
    }
 
    update opportunitiesToUpdate;
    
    }