I need to insert cases in salesforce from an external site. I'm using the Force.com_Toolkit_for_PHP:


I can insert a new case simply using the web to case form. Now I need to insert a CaseComment related to a case.

$oSforceConnection = new SforceEnterpriseClient();
$oSforceConnection->login('username', 'pwd_with_security_code');
$oComment = new stdClass();
$oComment->CommentBody='test comment from my external site';
$oComment->ParentId='case_id'; // the comment will be linked with this case
$oSforceConnection->create(array($oComment), 'CaseComment');

this works nicely, but I would like to link the comment to a contact. Have you some suggestions? I've noticed that it's not possible to create custom fields in the CaseComment object. So I cannot create a lookup relationship with the contact module.

Moreover inside the case detail view, I would like to see the contact that is linked to the comment inside the comment's related list. Is this possible with visualforce?

1 Answer 1


You cannot create lookups (or master-detail) relationships to Case Comment (as you've discovered), nor can you create an object that has a lookup (or master-detail) relationship to a Case Comment.

There are a couple of alternatives you could use, it depends what user experience you want.

If you just want external site comments to be related to a case:

Requests from your external site could create their own custom object (ExternalSiteComment__c for example) which you can display on your Case page using a seperate standard related list which will allow you to display whichever fields you like.

If however, you want a single unified comments list including both regular comments and external site comments:

In this case you have two options.

You could follow the approach above, and then write a Custom Visualforce Component to provide a unified list of both Case Comments and your custom object. This requires you to have a page override on the standard Case view page, and has a number of other limitations in terms of placement on the page compared to a related list.

A much more complicated solution, but the one that ultimately gives you the most control is to replicate the Case Comment functionality using your own custom object. You need to be careful when doing this though as Case Comments can be created in many different places in Salesforce (as well as managed packages etc) so you'll likely need a 'sweep-up' trigger to make sure that all Case Comments create a custom 'comment' object. You would then be able to display all Case Comments and External Site comments in a single unified related list.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .