You need to sign in to do that
Don't have an account?
Zhenyu Zhang
Salesforce trigger for multi picklists
Hi Masters,
I am new to Salesforce.
At the moment, I am trying to create a trigger.
In the code, there is one picklist in my lead, and then there is another exact same picklist in my task. When ther is log a call or new task coming in. The task's picklist value will be default to same as the lead's picklist value automacally.
However, the trigger that I created is not running. Is there anything wrong with what I did? Or I just made it too complicated?
Here is my trigger,
I am new to Salesforce.
At the moment, I am trying to create a trigger.
In the code, there is one picklist in my lead, and then there is another exact same picklist in my task. When ther is log a call or new task coming in. The task's picklist value will be default to same as the lead's picklist value automacally.
However, the trigger that I created is not running. Is there anything wrong with what I did? Or I just made it too complicated?
Here is my trigger,
Trigger PrePopulateTaskPromoCode on Task (before insert) { List<Lead> leadsToUpdate = new List<Lead>(); List<Task> tasks = new List<Task>(); for (Task t : trigger.new) { if (String.valueOf(t.WhoId).substring(0,3) == '00Q') { Lead leadToLookup = [Select promo_code__c FROM Lead WHERE Id = :t.WhoId]; String promoCode = leadToLookup.Promo_Code__c; t.Promo_Code__c = promoCode; tasks.add(t); } } // update tasks; }
So for your code you want to loop through the trigger through the trigger items once, get all the ids that may be lead Ids, then run a query that will return a map to the Id, then loop again and pull items out of the map and apply it.
Now, what do you mean it is "not running" I am sure the trigger is running, but is the value not set on your task after the record is created?
All Answers
The trigger is probably running, but its not really doing anything. I made some edits and this should accomplish what you need.
Try it out and let me know. I did not test this, so there might be a few compilation errors.
So for your code you want to loop through the trigger through the trigger items once, get all the ids that may be lead Ids, then run a query that will return a map to the Id, then loop again and pull items out of the map and apply it.
Now, what do you mean it is "not running" I am sure the trigger is running, but is the value not set on your task after the record is created?
83% is enough to deploy. The minimum is 75%. You should always try to strive for 100% though.
Looking at the code, I don't see how you could be at 83%. What lines are not covered?