You need to sign in to do that
Don't have an account?
sai_kumar_sfdc1.3903397698928884E12
how to pass other objects values in trigger
Hi All,
I have requirement like below
1) I have trigger on case ( Already existing)
2) based on business( custom field) that is there on case object....hard coding the record ids of product line id.
for example;
if case business==appliances
hardcoding the product line id on case object
like case.prodcutlineid==09bfhdsgw1
Like this for 10 businesses hard coding is happening...
I want to get rid of this hard coding....with program logic
like select the values(product line id's) from product line object based on the value of business received from case object...and pass it to case.productline(get(id)).......some thing like this to avoid hardcoding......so that it will pick up the product line id from prodcut line object based on the business ...
can you please help to get this done thru code...
Thanks
sai
I have requirement like below
1) I have trigger on case ( Already existing)
2) based on business( custom field) that is there on case object....hard coding the record ids of product line id.
for example;
if case business==appliances
hardcoding the product line id on case object
like case.prodcutlineid==09bfhdsgw1
Like this for 10 businesses hard coding is happening...
I want to get rid of this hard coding....with program logic
like select the values(product line id's) from product line object based on the value of business received from case object...and pass it to case.productline(get(id)).......some thing like this to avoid hardcoding......so that it will pick up the product line id from prodcut line object based on the business ...
can you please help to get this done thru code...
Thanks
sai
set<String> businesses = new set<String>();
for(Case c : trigger.new) {
businesses.add(c.business);
}
list<ProductLine> productLines = [SELECT id,Business FROM ProductLine WHERe Business in :businesses];
map<String,ProductLine> productLineMap = new map<String,ProductLine>();
for(ProductLine pl : productLines){
productLineMap.put(pl.Business,pl);
}
for(Case c : trigger.new) {
c.productline = productLineMap.get(c.business);
}
This assumes that each business is associated to only one productline. Some adjustments would be made if you needed to bring back multiple product lines for a single business. If you need more help just let me know. Also, providing some more code might help.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_bestpract.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm