Salesforce -- 代碼控制記錄共享

JS:

var objSharing = new sforce.SObject("objname__share");//here you have to supply the name of the sharing object corresponding to that object for which you want to share the record. 
objSharing.ParentId = objectId;//which you are getting in javascript.
objSharing.AccessLevel = 'Read';
objSharing.UserOrGroupId = userId;//to whom you have to share the record
var result = sforce.connection.create([objSharing]);

Apex:

// Create a new Job__Share record to be inserted in to the Job_Share table.
        Job__Share hiringManagerShare = new Job__Share();

        // Populate the Job__Share record with the ID of the record to be shared.
        hiringManagerShare.ParentId = job.Id;

        // Then, set the ID of user or group being granted access. In this case,
        // we’re setting the Id of the Hiring Manager that was specified by 
        // the Recruiter in the Hiring_Manager__c lookup field on the Job record.  
        // (See Image 1 to review the Job object's schema.)
        hiringManagerShare.UserOrGroupId = job.Hiring_Manager__c;

        // Specify that the Hiring Manager should have edit access for 
        // this particular Job record.
        hiringManagerShare.AccessLevel = 'edit';

        // Specify that the reason the Hiring Manager can edit the record is 
        // because he’s the Hiring Manager.
        // (Hiring_Manager_Access__c is the Apex Sharing Reason that we defined earlier.)
        hiringManagerShare.RowCause = Schema.Job__Share.RowCause.Hiring_Manager_Access__c;

        // Add the new Share record to the list of new Share records.
        jobShares.add(hiringManagerShare);
        //後面插入集合/單個記錄

業務機會共享:

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_opportunityshare.htm

__Share找不到:

https://developer.salesforce.com/forums/?id=906F00000008ymLIAQ

有幾個原因可能導致無法共享對象。 首先,如果您在實體上創建了主從關係,則會禁用該實體的共享,因爲可見性是由父級控制的。 在這種情況下,您還會注意到“所有者”字段丟失,因爲所有者不能更改,並且始終被視爲父記錄的所有者。 其次,可能是您的實體處於公共讀/寫模式。 共享僅適用於不能全局訪問的實體(即它們必須是隻讀或私有的)。 請檢查設置>安全控制>共享設置此實體的配置。
發佈了95 篇原創文章 · 獲贊 39 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章