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

create Task with Apex code // Attempt to de-reference a null object
Hi,
I want to create a Task after saving a customer Object.
In my Customer Object I give a User FIeld: Editor.
I try with this Code
And I become this failure:
Thx
Magda
Message Edited by magda on 02-13-2008 12:32 AM
I want to create a Task after saving a customer Object.
In my Customer Object I give a User FIeld: Editor.
I try with this Code
Code:
task.WhatId = Object.id; task.WhoId = Object.Editor__c; task.Subject = 'Other'; task.priority= Object.Priority__c; task.status = 'Not Started'; task.description = 'New Work'; insert task;
And I become this failure:
Attempt to de-reference a null object
Do you have an Idea to help me?Thx
Magda
Message Edited by magda on 02-13-2008 12:32 AM
convert ActivityDate date to datetime variable
Like
datetime DateVar=new datetime ("1/7/2009");
SfObj.ActivityDate=DateVar;
hector.asp2@gmail.com
All Answers
I have on the top of the class: Task task = new Task();
And it is not running....
Do you have another Idea?
know i becom this failure
Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Contact/Lead ID: id value of incorrect type: 005700000014lZZAAY: [WhoId]
And 005700000014lZZAAY is a user.... Do you have an Idea?
Thx
Magda
Ok Solution: Not using WhoId but OwnerId ;)Maybe can help another person having the same problem
Message Edited by magda on 02-13-2008 02:32 AM
Message Edited by magda on 02-13-2008 02:58 AM
Magda,
I need to create the same, could you please post your full code or guide me where i can access related samples.
thanks you very much
Unfortunately the WhoId can only point to a Contact or a Lead. This will not accept a User id. You can't use the WhatId because it will also not allow you to use a User Id in it. Within a task you can only use a UserID in a custom lookup field or the Owner field.
hi all
i am trying to create Task with Apex code and flexbut it not working at all Please help me out
var SfObj:SObject=new SObject("Task");
SfObj.ActivityDate="1/7/2009";
SfObj.Subject="Subject";
SfObj.Status="Active";
SfObj.Description="Description";
SfObj.WhoId="00Q8000000111ww";
thanks
arun thakur
er.arunthakur@gmail.com
convert ActivityDate date to datetime variable
Like
datetime DateVar=new datetime ("1/7/2009");
SfObj.ActivityDate=DateVar;
hector.asp2@gmail.com
Can any body suggest how create stand alone task using apex coding..
Is it possible that we can create tak inside the case....plz plz suggest.
can we have sub cases inside the cases
You have to assign the user to the tasks "OwnerId" not its "WhoId", like follows:
myTask.OwnerId = myAccount.OwnerId;
*NOT* like this:
Task.WhoId = Account.OwnerId;
and also *NOT* like this:
Task.WhoId = Account.Owner.Id;
As that will likely assign it to the current user rather than the record owner.
I had the same issue as magda. The problem was that I had a trigger firing "before insert" that referenced Trigger.oldMap, which obviously doesn't yet exist. I fixed the trigger by adding "if (Trigger.isInsert)" set of logic to avoid references to Trigger.oldMap before insert.
A value cannot be stored to ActivityDate in type Task
Thanks,
Naresh