Search code examples
restsalesforcesalesforce-lightningsalesforce-communitiessalesforce-chatter

Task assign to multiple leads in salesforce using rest api


I am new in Salesforce.Below code working fine,Its created task "Call LeadTest" sucessfully and assignd to only one lead/contact (WhoId). But i wanted to assign same task to multiple leads/contacts.

DefaultHttpClient HttpClient = new DefaultHttpClient();
HttpParams params = HttpClient.getParams();
Date dNow = new Date( );
SimpleDateFormat ft = new SimpleDateFormat ("MM/dd/YYYY hh:mm a");
Instant instant = Instant.now();
String dueDate=instant.toString();
JSONObject json = new JSONObject();
json.put("Subject", "Call LeadTest");
json.put("Status", "Not Started");
json.put("Priority", "Low");
json.put("OwnerId", "xxxxxxxxx");
json.put("WhoId", "xxxxxxxxx");
json.put("ActivityDate", dueDate);
json.put("Description", "this is test Task");
String baseUrl = instanceUrl + "/services/data/v49.0/sobjects/Task/";
oAuthHeader = new BasicHeader("Authorization", "OAuth " + accesstoken);
HttpPost schemaHttpGet = new HttpPost(baseUrl);
schemaHttpGet.addHeader(oAuthHeader);
schemaHttpGet.addHeader(printHeader);
StringEntity params2 = new StringEntity(json.toString());
schemaHttpGet.addHeader("content-type", "application/json");
schemaHttpGet.setEntity(params2);
HttpResponse response = HttpClient.execute(schemaHttpGet);
int iStatusCode = response.getStatusLine().getStatusCode();

So please help me to find out, how to assignd created task to multiple leads/contacts. Thank you for your answer in advance.


Solution

  • You must enable the Shared Activities feature. Once enabled, you will be able to assign either up to 50 Contacts or exactly one Lead to a Task.

    With shared activities, users can relate up to 50 contacts (but only 1 lead) to an event or a task.

    It is not possible to associate multiple Leads to a Task, or a Lead and a Contact.

    You can use the TaskWhoIds field or directly manipulate the TaskRelation junction records between Task and Contact or Lead to control these assignments.