Salesforce -- 代码控制记录共享

来源:互联网 发布:环境污染数据表格 编辑:程序博客网 时间:2024/06/03 05:36

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 recordvar 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

原创粉丝点击