You need to sign in to do that
Don't have an account?
Deepika G P
Want to run trigger for only one object
I have an Custom Object 'Customer participation' and Task is created for this object, now when I send an email from the related list with the subject as executive ,a field on task object should be inserted with an value. I have created a trigger but the trigger is working on all the objects. but i want it to work only on the emails of 'Customer participation'. Could anyone help me on this please.
trigger updatetaskoriginfield on Task (before insert, before update)
{
if(trigger.isBefore)
{
for(Task tsk: trigger.new)
{
String test=tsk.subject;
set<string> a=new Set<string>{'executive','Executive'};
set<string> b=new Set<string>{'award','Award'};
List<String> lsttest=test.split(' ');
for(String s: lsttest)
{
if(a.contains(s))
{
tsk.Task_Origin__c='Executive Summary';
}
else if(b.contains(s))
{
tsk.Task_Origin__c='Award Notification';
}
}
}
}
}
trigger updatetaskoriginfield on Task (before insert, before update)
{
if(trigger.isBefore)
{
for(Task tsk: trigger.new)
{
String test=tsk.subject;
set<string> a=new Set<string>{'executive','Executive'};
set<string> b=new Set<string>{'award','Award'};
List<String> lsttest=test.split(' ');
for(String s: lsttest)
{
if(a.contains(s))
{
tsk.Task_Origin__c='Executive Summary';
}
else if(b.contains(s))
{
tsk.Task_Origin__c='Award Notification';
}
}
}
}
}
All Answers
1) http://amitsalesforce.blogspot.in/2015/12/standard-field-record-id-prefix-decoder.html
Please update your code like below
Let us know if this will help you
Thanks
Amit Chaudhary
I want to know that how have you created task for custom object? I have seen task object active for standard object like contact, opportunity, cases, account. but in case of custom object i dont have any idea for the same. Your answer will be appreciating.
Thanks
Shephali
You can create the task on any custom object but "Track Activities" should be checked on custom object
Please check below post for more information
1) https://help.salesforce.com/apex/HTViewHelpDoc?id=tracking_activities_for_custom_objects.htm
2) https://help.salesforce.com/apex/HTViewSolution?id=000004351&language=en_US
In order for a Custom Object to show in the "Related To" Lookup list for an Event or Task, the "Allow Activities" (Track Activities) check-box must be checked in the Custom Object Definition. To do this:
1. Go to Setup | Create | Objects.
2. Click Edit to modify an existing custom object.
3. Check the "Allow Activities" check-box under Optional Features.
Let us know if this will help you
Thanks a lot :)
Below trigger is working fine as per the requirement but when i run the test class , below error is thrown ,
Can anyone help me on this please?
Stack Trace: Class.UpdateProjectScheduleFieldsTrigger.errorMsg: line 14, column 1
trigger updatetaskoriginfield on Task (before insert, before update)
{
if(trigger.isBefore)
{
// please add your object Name here for Customer_participation__c
String keyPrefix = Customer_participation__c.sObjectType.getDescribe().getKeyPrefix();
// System.debug('PREFIX--' + keyPrefix );
for(Task tsk: trigger.new )
{
String strWhatId = tsk.whatId;
// if(strWhatId.startsWith('a0v'))
if( strWhatId.startsWith(keyPrefix) ) // Chck record is related with Customer_participation__c only
{
String test=tsk.subject;
set<string> a=new Set<string>{'executive','Executive'};
set<string> b=new Set<string>{'award','Award'};
List<String> lsttest=test.split(' ');
for(String s: lsttest)
{
if(a.contains(s))
{
tsk.Task_Origin__c='Executive Summary';
}
else if(b.contains(s))
{
tsk.Task_Origin__c='Award Notification';
}
}
}
}
}
}
Appreciate your help on this!
Below is my test class
@istest
Public class UpdateProjectScheduleFieldsTrigger{
public static testmethod void errorMsg(){
task t= new task();
t.ownerID=userinfo.getuserid();
t.Subject='Run Test Trigger';
t.Status='Not Started';
t.Priority='Normal';
insert t;
update t;
}
}
The test class is already in production, so if i change it , will it effect anyother things in production?