You need to sign in to do that
Don't have an account?
BCDBSA
Batch update records in the same object under the same Account name with a specific value in a field when that field in one record is updated to that specific value
Hi All,
I have a sObject SSS that has a Customer_Account__c field looking up to Account standard object. I have a Status field in that sObject with default value "Open". I have setup an auto-update through Process Builder--whenever an SSS Line Item sObject (which is the child in a master-detail relationship with SSS) is checked in Billed__c checkbox field, the Status field in parent SSS sObject would be auto-populated to "On Hold".
Would it be possible to set up a trigger that once Status field is updated to "On Hold", the rest of SSS with the same Account and Status = "Open" would be auto-updated with the Status = "On Hold"? I have written the following codes, but I need some help with it...
Thanks
I have a sObject SSS that has a Customer_Account__c field looking up to Account standard object. I have a Status field in that sObject with default value "Open". I have setup an auto-update through Process Builder--whenever an SSS Line Item sObject (which is the child in a master-detail relationship with SSS) is checked in Billed__c checkbox field, the Status field in parent SSS sObject would be auto-populated to "On Hold".
Would it be possible to set up a trigger that once Status field is updated to "On Hold", the rest of SSS with the same Account and Status = "Open" would be auto-updated with the Status = "On Hold"? I have written the following codes, but I need some help with it...
Thanks
Jolie,
A flow with a screen added to it, such as the interface you're thinking of is referred to as a "Visual Flow" or "Visual Workflow". Otherwise, the Flow is referred to as a "Headless flow" or a "Triggered flow" in some cases. The terminology is confusing often.
The only difference between them is the addition of the screen for allowing user input / output.
You can invoke flows via processes, urls, visualforce pages, and more.
If you're looking for a declarive solution then I'd suggest looking at tinkering with Flows.
Otherwise, your trigger needs just a bit of work. For one, it's not bulkified (for every account you insert, you're querying records, which is a bad practice). Furthermore, you query to bring in additional SSS records and you change the field, but you never call a DML update on the record(s). Let's dive into this real quick:
If you were to iterate over records in the trigger scope, and since you're using a before update, the change would stick. An example of this is the following:
However, you're querying records, and the records returned from the query are not part of the trigger scope, so the changes need an update operation so that the changes are written back to the object.
Putting the bulkifying of the trigger to move the query outside of the for loop AND the update statement all together, you get something like the following:
Bam, there you have it: a bulkified and hopefully working trigger. Note: there may be a few typos or incorrect field names in there you'll have to correct.
If the solution works, please go ahead and mark this as a best answer.
- James
All Answers
There is no error for the trigger, but when one of the SSS fired, the other SSS with Open status do not change the value.
Jolie,
A flow with a screen added to it, such as the interface you're thinking of is referred to as a "Visual Flow" or "Visual Workflow". Otherwise, the Flow is referred to as a "Headless flow" or a "Triggered flow" in some cases. The terminology is confusing often.
The only difference between them is the addition of the screen for allowing user input / output.
You can invoke flows via processes, urls, visualforce pages, and more.
If you're looking for a declarive solution then I'd suggest looking at tinkering with Flows.
Otherwise, your trigger needs just a bit of work. For one, it's not bulkified (for every account you insert, you're querying records, which is a bad practice). Furthermore, you query to bring in additional SSS records and you change the field, but you never call a DML update on the record(s). Let's dive into this real quick:
If you were to iterate over records in the trigger scope, and since you're using a before update, the change would stick. An example of this is the following:
However, you're querying records, and the records returned from the query are not part of the trigger scope, so the changes need an update operation so that the changes are written back to the object.
Putting the bulkifying of the trigger to move the query outside of the for loop AND the update statement all together, you get something like the following:
Bam, there you have it: a bulkified and hopefully working trigger. Note: there may be a few typos or incorrect field names in there you'll have to correct.
If the solution works, please go ahead and mark this as a best answer.
- James
Thank you so much!! That has been too helpful!