+ Start a Discussion
Tobias HaggeTobias Hagge 

Trigger: hitting limits? API/Bulk

trigger Trigger_Opportunity2Contact on Opportunity (after update) {
	Opportunity[] opportunities = Trigger.New;
	// Fetch fields we'll be using AND filter out Opportunities != 1
	List<Opportunity> oppsWithContact = new List<Opportunity>([Select Underwriter_Notes__c, Account.Contact__c, Approval_Decision__c, Decision_Date__c, Reason_for_Deferring__c, Reason_for_Rejecting__c From Opportunity where Id in: opportunities and Opportunity_Number__c = 1]);
	Map<String, Opportunity> opportunityMap = new Map<String, Opportunity>();
	for(Opportunity opportunity: oppsWithContact)
		opportunityMap.put(opportunity.Account.Contact__c, opportunity);
	List<Contact> contacts = new List<Contact>([SELECT Id, Additional_Info_for_Easycallnow__c, Approval_Decision__c, Decision_Date__c, Reason_for_Deferring__c, Reason_for_Rejecting__c FROM Contact WHERE Id in :opportunityMap.keySet()]);

	for(Contact contact: contacts)
		Opportunity opp = opportunityMap.get(contact.Id);
		if(opp != null){
			contact.Approval_Decision__c = opp.Approval_Decision__c;
			contact.Decision_Date__c = opp.Decision_Date__c;
			contact.Reason_for_Deferring__c = opp.Reason_for_Deferring__c;
			contact.Reason_for_Rejecting__c = opp.Reason_for_Rejecting__c;
			contact.Additional_Info_for_Easycallnow__c = opp.Underwriter_Notes__c;
	update contacts;

Having a trigger that simply triggers field updates from Opportunity to Contact. Works fine on a simple manual update. However we sync/update all Opportunities in the night, so it should have triggered all Opportunity values to the Contact, but didn't trigger at all. The Opportunities are updated in 200 batches.
Afterwards bulk-changed 1000 Opportunities on a arbitrary field and it triggered and updated part of the fields, but then suddenly seemed to stop. E.g. updated all Approval_Decision__c, but no Decision_Date__c. Running the same bulk change again then updated the Decision_Date__c, which lets me think there might  be a limit on how many values you can change in one job?
Priority has to update all through the API.

Instead of updating the records in trigger code, you can implemente this using Process builder in salesforce.

1. Create a process for the object 'Opportunity'
2. Then set the criteria as "Opportunity_Number__c="
3. Then select update records in the process builder action and choose AccountId->contact
4. Then you can able to select fields from the contact object and then map the values with the the opportunity value
5. Then save your actions and activate the processbuilder.

First test with single record, whether its working as per business criteria, then perform the bulk insert operation to test. If you are implementing this in declarative way, then you don't need to worry about the bulk insert operation

Check this process builder overview - https://help.salesforce.com/HTViewHelpDoc?id=process_overview.htm
Tobias HaggeTobias Hagge
Unfortunately problematic, because two of the fields are multi-picklists and therefore not available in the process builder, as far as I can see.