function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SunsterSunster 

API - Lead Activity Newb

I have some general methodology questions regarding updating and inserting new Activities(i.e. - Tasks) in a Salesforce Organization.

 

I am able to insert tasks to a lead fairly easily. And those tasks all appear in the OpenActivity list properly.

 

  • But, when I attempt to insert a "Closed" or "Completed" task, so that the task will appear in the Activity History of the Lead, the task is inserted into the Lead, but appears in the Open Activities list.
  • Is there something else that I should be doing here?
  • How can I get a newly created Task that is closed to appear in the Activity History List of the lead?

Please forgive my ignorance....:smileyhappy:

Any help that you can give me would be very much appreciated...
Best Answer chosen by Admin (Salesforce Developers) 
ad75ad75

Here are a few points that strike me:

Firstly, you definitely can create new tasks with status=completed and they will appear in activity history.  I have done this in my own apps.

Next, unless I'm misreading your code, the line that sets status to Completed is commented out, so there is no status set at all on the task.

 

Next, if the task is created without error but does not appear on the lead page related lists, are you sure that you have set the correct lead id?  The creation should return you an object Id - look up the task in the browser and see which lead the task is linked to.

 

Next, as you have noticed, the WhatId field must be empty if you have set the WhoId field to a lead id.  However I'm not sure that it's correct to explicitly set the value to String.Empty - personally I do not set the field at all - I just create a new Task object then set the WhoId and status fields.  Maybe instead of setting it to string.empty just don't attempt to set it at all?  I'm not sure about this but it might be worth a go.

Lastly, the task object whose fields you are assigning values to is passed as an argument to the function; is it possible that this task object already has some field values set that are causing you problems, such as a status field or even an Id field?

 

Hope this helps.

 

All Answers

SuperfellSuperfell
Set the Status field to a status value that's marked as completed (in the web ui, look at setup -> activities -> fields -> status )
Message Edited by SimonF on 03-26-2009 12:18 PM
SunsterSunster

SimonF,

 

     Thank you for your response. I did attempt to perform an upsert of a Task Object with the Status field set to "Completed". No Errors occured during the upsert. But, the "Completed" Task did not appear anywhere on the associated lead. It did not appear in Open Activities or Activity History.

 

     This leads me to ask another question:
  • Should I upsert a Task with a status of "Not Started" and then perform another upsert of that task with a status of "Completed"
    • It doesn't sound like this should be the case, but may give me the behavior that I require.

     Would you happen to have any other suggestions?
SuperfellSuperfell
did you set the whoId of the task to the Id of the lead ?
SunsterSunster

Well, I haven't posted the code yet..... Here it is...

 

 

Protected Sub PushingTask(ByVal submission As ListrakIntegration.Common.LARTS.Entity.Submission, ByVal lead As SForceDevEnterpriseService.Lead, ByVal task As SForceDevEnterpriseService.Task) Dim activities As New List(Of SForceDevEnterpriseService.Task) Dim upsertResult() As Salesforce.SForceDevEnterpriseService.UpsertResult Try activities.Clear() task.WhoId = lead.Id task.WhatId = String.Empty task.CallType = "Inbound" task.Description = "Listrak.com submission" Me.PerformActivityMapping(submission, task) activities.Add(task) upsertResult = Me.SalesforceEnterpriseService.upsert("Listrak_Marketing_SubmissionID__c", activities.ToArray()) Me.CheckForErrors(upsertResult, "Task") 'If Not (submission.CallMe) Then ' activities.Clear() ' task.Status = "Completed" ' activities.Add(task) ' upsertResult = Me.SalesforceEnterpriseService.upsert("Listrak_Marketing_SubmissionID__c", activities.ToArray()) ' Me.CheckForErrors(upsertResult, "Task") 'End If Catch SoapEx As SoapException Dim sMessage As String = SoapEx.Message Catch ex As Exception Me.LogError(ex) End Try End Sub Protected Sub PerformActivityMapping(ByVal submission As Submission, ByRef activity As SForceDevEnterpriseService.Task) activity.Listrak_Marketing_SubmissionID__c = submission.SubmissionID.ToString().Trim() activity.Listrak_Marketing_CreatedDate__c = submission.CreatedDate.ToString() activity.Subject = Me.BuildActivityMappingSubject(submission) If (submission.Type = "contact") Then activity.Listrak_Submission_Source__c = "Email Expert" ElseIf (submission.Type = "demo") Then activity.Listrak_Submission_Source__c = "Demo Request" Else activity.Listrak_Submission_Source__c = submission.Type.Trim() End If 'If Not (submission.CallMe) Then ' activity.Status = "Completed" 'End If If Not (submission.ResourceID = Integer.MinValue) Then activity.Listrak_Marketing_ResourceID__c = submission.ResourceID.ToString().Trim() activity.Listrak_Marketing_ResourceTitle__c = submission.ResourceTitle.Trim() End If If Not (submission.TrackingID = Integer.MinValue) Then activity.Listrak_Marketing_TrackingID__c = submission.TrackingID.ToString().Trim() activity.Listrak_Marketing_TrackingLabel__c = submission.TrackingLabel.Trim() End If activity.Listrak_Submission_Source__c = submission.Type.Trim() End Sub Protected Sub CheckForErrors(ByVal upsertResult() As SForceDevEnterpriseService.UpsertResult, ByVal objectName As String) Dim badResults As New List(Of SForceDevEnterpriseService.UpsertResult) Dim errorFound As Boolean = False Try badResults.Clear() For i As Integer = 0 To (upsertResult.Count - 1) If Not (upsertResult(i).success) Then badResults.Add(upsertResult(i)) End If Next For Each oresult As SForceDevEnterpriseService.UpsertResult In badResults Me.LogError(New Exception(Me.BuildSalesforceErrorMessage(oresult, objectName))) Next Catch ex As Exception Me.LogError(ex) End Try End Sub

 

 

 

SunsterSunster

Also, I did attempt to upsert the Task twice. Once with "Not Started" and the next time with "Completed". That didn't work. The tasks that were not set to "Completed"did not appear. However, If I upsert the task once with the status set to "Not Started" all tasks appear in the Open Activities list. Therefore, I am not sure how to upsert a task and get it to appear in the ActivityHistory.

 

Any suggestions are welcome.

SuperfellSuperfell
Perhaps i missed it, but are you setting an activityDate ?
ad75ad75

Here are a few points that strike me:

Firstly, you definitely can create new tasks with status=completed and they will appear in activity history.  I have done this in my own apps.

Next, unless I'm misreading your code, the line that sets status to Completed is commented out, so there is no status set at all on the task.

 

Next, if the task is created without error but does not appear on the lead page related lists, are you sure that you have set the correct lead id?  The creation should return you an object Id - look up the task in the browser and see which lead the task is linked to.

 

Next, as you have noticed, the WhatId field must be empty if you have set the WhoId field to a lead id.  However I'm not sure that it's correct to explicitly set the value to String.Empty - personally I do not set the field at all - I just create a new Task object then set the WhoId and status fields.  Maybe instead of setting it to string.empty just don't attempt to set it at all?  I'm not sure about this but it might be worth a go.

Lastly, the task object whose fields you are assigning values to is passed as an argument to the function; is it possible that this task object already has some field values set that are causing you problems, such as a status field or even an Id field?

 

Hope this helps.

 

This was selected as the best answer
SunsterSunster

 Simon,

Thank you for the information that you have provided, your insight has been very helpful. The advice that you gave me previously was right on. Switching the Task.Status field to "Completed" and performing an upsert does indeed place the task in the Activity History List for the Lead.

 

After looking over the code I discovered a mistake above the code that I provided. I apologize for the mistake.

 

Thanks for sticking with me through the pain.