You need to sign in to do that
Don't have an account?
Need Help adding IF statement in Trigger
Any idea on how I could make this trigger fire to another field if the 1st field is full?
I have a custom object called Quote_Ocean_Container__c that is a Master-Detail to the Quote and I'm unable to create a workflow to update the custom field on the quote. Whenever a record is created in the Quote_Ocean_Container__c, the trigger will combine to fields and update a custom field on the Quote called "Container_1__c".
However, if Container_1__c is already filled in, I want the trigger to update Container_2__c, and if that is filled in, then update Container_3__c and so on. There are 6 Container fields.
Thanks in advance for any guidance or advise.
Trigger UpdateQuoteContainer1 on Quote_Ocean_Container__c(after insert, after update)
{
Set<Id> ids = trigger.newmap.keySet();
List<Quote_Ocean_Container__c> quocon=[select Quote__r.Container_1__c, Number_Required__c, Container_Type__c, from Quote_Ocean_Container__c where id IN :ids];
List<Quote> updateQuote=new List<Quote>();
For(Quote_Ocean_Container__c Quocon:quo)
{
Quocon.Quote__r.Ocean_Container__c=Quocon.Number_Required__c + '-' + ' ' + Quocon.Container_Type__c;
updateQuote_Ocean_Container__c.add(Quocon.Quote__r);
}
Update updateQuote_Ocean_Container__c;
}
I am not sure of a better way to do this but here is my 2 cents.
The way you have your data model set up I don't think there is anything else you can do. The else if statements will only fire the one that is true and move on so you don't have to worry about over writing the container fields.
One question will there ever be more then 6 containers? If so you might want to solve this problem with so visualforce.
Hope this helps.
All Answers
I am not sure of a better way to do this but here is my 2 cents.
The way you have your data model set up I don't think there is anything else you can do. The else if statements will only fire the one that is true and move on so you don't have to worry about over writing the container fields.
One question will there ever be more then 6 containers? If so you might want to solve this problem with so visualforce.
Hope this helps.
Thanks Mike,
That's what I was looking for, the If's and else If's, your code worked with a little modifications.
My only issue now is deleting the updated field when the corresponding record in the Container object is deleted.
Maybe I should just put an idea in to allow custom controllers on the Quote templates.
Thanks again!