+ Start a Discussion
rotvizrotviz 

Add new activity in Java via API in Contract´s related list "Activity History"

Can we add a new activity via API in Contract´s related list "Activity History"?

In a business point of view, what we want to do is :

We are developing a Java application via API that send mails when a contract finished, so we want to add a activity like "Mail sent to Customer" in the Contract´s related list "Activity History".

It is possible to do it in Java via API?

Thanks .

Best Regards.
DevAngelDevAngel

Hi rotviz,

To create an activity that will display in the Activity History, you would create a Task and assign the WhatId field to the id of the contract that the activity is related to.

Activities show up in the Activity History when the task is closed.  Since there is an IsClosed boolean property on a task, you may be tempted to try to set that to true to indicate that it is closed.  This will fail as the IsClosed property is read only.  To create a "closed" task you will need to create the task with the correct status.  The status field of a task is an  extended picklist field meaning that the values of the picklist have additional attributes beyond the valued and label.  In the case of the task status, there are two additional attributes - default and closed.  You can configure which status indicates that the task is closed.  So, to create a closed task, you need to create it with the status that has the closed attribute.

In the example below (C#, but almost identical in Java) the field that is designated as the "closed" field is "Deferred".

string contractId = "800300000000sbu";

sforce.Task task = new Tester.sforce.Task();

task.ActivityDate = DateTime.Now;

task.ActivityDateSpecified = true;

task.Description = "Test for contracts";

task.Priority = "High";

task.Status = "Deferred";

task.Subject = "This is a test";

task.Type = "Other";

task.WhatId = contractId;

sforce.SaveResult sr = binding.create(new sforce.sObject[] {task})[0];

 

Cheers

rotvizrotviz

Hi Dave,

It works.

Thanks.

Víctor �lvarez

The_PhoenixThe_Phoenix

Hi rotviz,

To create an activity that will display in the Activity History, you would create a Task and assign the WhatId field to the id of the contract that the activity is related to.

Activities show up in the Activity History when the task is closed.  Since there is an IsClosed boolean property on a task, you may be tempted to try to set that to true to indicate that it is closed.  This will fail as the IsClosed property is read only.  To create a "closed" task you will need to create the task with the correct status.  The status field of a task is an  extended picklist field meaning that the values of the picklist have additional attributes beyond the valued and label.  In the case of the task status, there are two additional attributes - default and closed.  You can configure which status indicates that the task is closed.  So, to create a closed task, you need to create it with the status that has the closed attribute.

In the example below (C#, but almost identical in Java) the field that is designated as the "closed" field is "Deferred".

string contractId = "800300000000sbu";

sforce.Task task = new Tester.sforce.Task();

task.ActivityDate = DateTime.Now;

task.ActivityDateSpecified = true;

task.Description = "Test for contracts";

task.Priority = "High";

task.Status = "Deferred";

task.Subject = "This is a test";

task.Type = "Other";

task.WhatId = contractId;

sforce.SaveResult sr = binding.create(new sforce.sObject[] {task})[0];

 

Cheers

Dave
Developer Program Manager

---

Dave, do you know if we can hit the Activity History when uploading via the Excel connector, or is this only available through the API?

DevAngelDevAngel

--------------------------------------------------------------------------------------------------------------------------------------

----  Dave, do you know if we can hit the Activity History when uploading via the Excel connector, or is this only available through the API?

--------------------------------------------------------------------------------------------------------------------------------------

 

I'm not sure.  I don't think the Excel connector is any different.

 

Message Edited by DevAngel on 03-28-2005 11:29 AM

ScotScot

Yep .. as Dave said, it's the same in the Connector as in the API. The Task object/table is available, and if you build one that's closed, it shows up in the history.

Scot

VickiTVickiT

How can I change the default Task Status that is auto-filled when the user clicks Add an Email as a Task?  Currently, most of my users are still on SF Connect for Outlook.