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
Lars SundbergLars Sundberg 

User Managed Sharing via PHP

Is it possible to set sharing for a record to a certain user directly when creating a record though PHP?

 

With this as reference:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm

 

I tried:

 

        $records = array();
        $records[0] = new SObject();
        $records[0]->fields = array(
            'Name' => $note_name,
            'Note_body__c' => $note_body
        );
        $records[0]->type = 'Note__c';
        $response = $client->create($records);
 
        foreach ($response as $i => $result) {
            $sharingrecords = array();
            $sharingrecords[$i] = new SObject();
            $sharingrecords[$i]->fields = array(
                'ParentId' => $result->id,
                'UserOrGroupId' => $recipient,
                'AccessLevel' => 'Read'
            );
            $sharingrecords[$i]->type = 'Note__Share';
            $sharingresponse = $client->create($sharingrecords);
        }

 

And got the error:

 

Post failed: SoapFault exception: [sf:INVALID_TYPE] INVALID_TYPE: sObject type 'Note__Share' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name.

 

(Note is a custom object, $note_name and $note_body are texts, $recipient is a user id).

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Lars SundbergLars Sundberg

Never mind. I had to set Default Access for the Note object to private. Now it works.