You need to sign in to do that
Don't have an account?
Apex Question - Activities/Tasks
I am trying to write apex code for the Activities/Task object.
We have a custom picklist field titled "Task Results".
I want to have whatever is selected in "Task Results" to automaticcaly append/add-to whatever is typed into the Task Subject in parenthesis.
For example, if Subject is "Call" and someone selected "Inbound" from the Task Results picklist, I want the Subject to then be changed to "Call (Inbound)".
Please let me know if that makes sense.
We have a custom picklist field titled "Task Results".
I want to have whatever is selected in "Task Results" to automaticcaly append/add-to whatever is typed into the Task Subject in parenthesis.
For example, if Subject is "Call" and someone selected "Inbound" from the Task Results picklist, I want the Subject to then be changed to "Call (Inbound)".
Please let me know if that makes sense.
Regards,
Mahesh
All Answers
Please use the below code:
Please do let know if it helps you.
Regards,
Mahesh
Regards,
Mahesh
1
2
3
4
5
6
7
8
9
10//
// Trigger put on Task to populate the Subject and add Task Results with parenthesis per Angela.
//
trigger TaskTrigger on Task (before insert, before update) {
for(Task ta: Trigger.new) {
if(ta.Task_Results__c != null && ta.Subject != ta.Task_Results__c) {
ta.Subject += ' ('+ta.Task_Results__c + ')';
}
}
}
Below code will execute only in insert scenario and Task Results changes in the update scenario.
Regards,
Mahesh
Also make sure that you have proper code coverage of 75% and above.
Please look into the below URLs:
https://help.salesforce.com/apex/HTViewHelpDoc?id=changesets_inbound_deploy.htm&language=en
https://developer.salesforce.com/docs/atlas.en-us.dev_lifecycle.meta/dev_lifecycle/deploy.htm
http://help.salesforce.com/HTViewSolution?id=000005283
https://help.salesforce.com/apex/HTViewHelpDoc?id=changesets_about_connection.htm&language=en
Regards,
Mahesh
If you deploy new one then both the triggers will exists in the production.
Regards,
Mahesh
Do you know how to add "does not contain" to an Apex trigger?
For example, I have the following code:
trigger TaskTrigger on Task (before insert, before update) {
for(Task ta: Trigger.new) {
if(ta.Task_Results__c != null && ta.Subject != ta.Task_Results__c) {
ta.Subject += ' ('+ta.Task_Results__c + ')';
}
}
}
What's happening is every time a user "Edits" and "Saves" a Task, it's duplicating the Task Result value in the Subject line. I only want this to happen once. Is there a way to add "and ta.Subject DOES NOT CONTAIN ta.Task_Results_c" or ONLY UPDATE ONCE?
You can use the below code and it will fire only if you change the Task Result.
Regards,
Mahesh