You need to sign in to do that
Don't have an account?
Creation of a new trigger to update data in a related object
Hi All,
I am new to salesforce and not a developer(I am a BA) however I am in need of some code and I am sure it is possible in Salesforce. In SQL I could do this with an update query.
I have recently installed an app called chargent which has an object called Orders. I use person accounts and on the account I created a custom field to keep track of the customer status with a field called Status_C.
This order has a relationship(lookup) to the account. The key is that there is also a status on the order to manage recurring payments. What I wanted to is:
when the user changes the account.status_C = 'Canceled' then change the order_R.PaymentStatus_C = 'Stopped'
How would I go about this? Is there a trigger I can create to do this?
Since this appears from your description to be a lookup relationship then a trigger would be required.
Basically, for a NON BULKIFIED trigger:
**How do you identify which order to to pull**
**Assuming the lookup field on Orders is Account__c
trigger updateChargeStatus on Account (before update){
Orders__c[] ord = [Select PaymentStatus__c From Orders__c Where Account__c = trigger.new[0].id AND PaymentStatus__c = 'STATUS TO FIND' Limit 1];
if(trigger.new[0].status__c == 'Canceled' && ord.isEmpty() != true){
ord[0].PaymentStatus__c = 'Stopped';
update ord;
}
}
All Answers
Since this appears from your description to be a lookup relationship then a trigger would be required.
Basically, for a NON BULKIFIED trigger:
**How do you identify which order to to pull**
**Assuming the lookup field on Orders is Account__c
trigger updateChargeStatus on Account (before update){
Orders__c[] ord = [Select PaymentStatus__c From Orders__c Where Account__c = trigger.new[0].id AND PaymentStatus__c = 'STATUS TO FIND' Limit 1];
if(trigger.new[0].status__c == 'Canceled' && ord.isEmpty() != true){
ord[0].PaymentStatus__c = 'Stopped';
update ord;
}
}
Great.
Now time to bulkify the trigger so you can handle multiple updates at once.