+ Start a Discussion
RejonesRejones 

Trigger Help

I need help building a trigger on my customer object called Vendor Relationship.  WHen a user changes the status to Declined and the Declined Reason code to one of the Pickvalues.  I want the trigger to auto Share the record with one of my Salesforce to Salesforce Connections. 

 

 

SLockardSLockard

I'm not exactly sure what you mean by share to one of your salesforce to salesforce connections, but this code should be a good place to start:

trigger shareDeclinedObject on Vendor_Relationship__c(after update)
{
	List<Vendor_Relationship__c> vrsToSend = new List<Vendor_Relationship__c>();

	for (Vendor_Relationship__c vr: Trigger.New)
	{
		Vendor_Relationship__c oldVR = Trigger.oldMap.get(vr.Id);
		if (vr.Status__c != oldVR.Status__c || vr.Declined_Reason_Code__c != oldVR.Declined_Reason_Code__c)
		{
			if (vr.Status__c == 'Declined' && (vr.Declined_Reason_Code__c == 'Option 1' || vr.Declined_Reason_Code__c == 'Option 2'))
			{
				vrsToSend.add(vr);
			}
		}
	}

	if (vrsToSend.size() > 0)
	{
		// send list of vrs to other salesforce connection or whatever
	}
}

 I hope that helps a little!