Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
I want to insert a record into a custom object when a TASK record is created.Can we acheive this by a trigger ?
You need write a trigger on Task Object. (Task object is object of Activities).
trigger <name> on Task (after insert) {
if(trigger.isinsert)
{
Customobject obj = new CustomObject();
obj.fieldname = 'Value';
insert obj;
}
* Please mark as solution for other persons help on a same query
Thank You,
Raj Jha
Hi
Yes you can acheive this with trigger.
Here is example trigger for this:-
trigger Createtasks on task (after insert) { List<lead__c> createtasks = new List <lead__c> (); for (task t : trigger.new) { if (t.subject == 'Email') { createtasks.add( new lead__c ( Name = t.CreatedBy.Name ,Date__c=system.today() ,Comments__c=t.Description)); } } try { insert createtasks; } catch (Exception Ex){ system.debug(Ex); } }
I want insert few fields detail so that i can use it to send custom email alerts .So shall i directly refer the fields(assign TASK values fo custom object fields) or use any other process to acheive it .?
if(trigger.isinsert){List<Member_Added__c> objList = new List<Member_Added__c>();Member_Added__c obj = new Member_Added__c();for(Task T: Trigger.new){if(((T.RecordTypeId == '01270000000Q9KJ')||(T.RecordTypeId == '012S0000000DIPs')||(T.RecordTypeId == '012V0000000Co5k'))&&(T.Status == 'Completed')){
obj.Text_1__c = T.Text__c;obj.Text_2__c = T.Detail__c;obj.Text_3__c = T.Subject;obj.Text_4__c = T.Description;if((String.valueof(T.Owner)).substring(0,2)== '005'){obj.User_1__c = String.valueof(T.OwnerName);}String urlForObj= URL.getSalesforceBaseUrl().toExternalForm() + '/'+T.WhatId;obj.Task_Url__c = urlForObj;objList.add(obj);}}insert objList;}This is not inserting records into the custom object ... any suggestions ?
You need write a trigger on Task Object. (Task object is object of Activities).
trigger <name> on Task (after insert) {
if(trigger.isinsert)
{
Customobject obj = new CustomObject();
obj.fieldname = 'Value';
insert obj;
}
}
* Please mark as solution for other persons help on a same query
Thank You,
Raj Jha
Hi
Yes you can acheive this with trigger.
Here is example trigger for this:-
I want insert few fields detail so that i can use it to send custom email alerts .
So shall i directly refer the fields(assign TASK values fo custom object fields) or use any other process to acheive it .?
if(trigger.isinsert)
{
List<Member_Added__c> objList = new List<Member_Added__c>();
Member_Added__c obj = new Member_Added__c();
for(Task T: Trigger.new){
if(((T.RecordTypeId == '01270000000Q9KJ')||(T.RecordTypeId == '012S0000000DIPs')||(T.RecordTypeId == '012V0000000Co5k'))&&(T.Status == 'Completed')){
obj.Text_1__c = T.Text__c;
obj.Text_2__c = T.Detail__c;
obj.Text_3__c = T.Subject;
obj.Text_4__c = T.Description;
if((String.valueof(T.Owner)).substring(0,2)== '005'){
obj.User_1__c = String.valueof(T.OwnerName);
}
String urlForObj= URL.getSalesforceBaseUrl().toExternalForm() + '/'+T.WhatId;
obj.Task_Url__c = urlForObj;
objList.add(obj);
}
}
insert objList;
}
This is not inserting records into the custom object ... any suggestions ?