You need to sign in to do that
Don't have an account?

i need to create a new task with every new account via Apex Trigger
Hello All,
Please help me out with suggesting that how i need to proceed with Apex Trigger for creating new task on successful creation of new Account.
Regards,
RudrAbhishek
If you *must* use a trigger, it's a pretty simple one. There are a few examples on Developerforce:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_HelloWorld.htm
http://developer.force.com/cookbook/category/triggers/recent
This is possible with a Workflow rule.
Goto Setup > Create > Workflow & Approvals > Workflow Rules.
Create a new Workflow rule.
Object: Account.
Rule Name: anything
Evaluation Criteria: Created
Rule Criteria :
Run the rule if the following: 'Formula evaluates to true'
In the formula box just type true (this fires the rule everytime an account is created)\
'Save & Next'
Add A Workflow Action:
New Task
The fields are self explanatory. Activate the Workflow rule and you are done.
However, if you want it done through a trigger the following code should help.
<pre>
trigger AccountTrigger on Account (after insert) {
List<Task> lstTasks = new List<Task>();
for(Account a : Trigger.new){
Task t = new Task();
t.OwnerID = a.OwnerID;
t.Subject = 'Any Subject';
t.WhatID=a.Id;
t.Status = 'Not Started';
//Add any other fields you need.
lstTasks.add(t);
}
insert lstTasks;
}
</pre>
Hope this helps.
Regards,
Satish Kumar