Salesforce -- 代码控制记录共享

本文介绍了如何使用JavaScript和Apex实现Salesforce中特定记录的共享。通过创建共享对象,可以指定用户或组对记录的访问级别。此外,还讨论了可能遇到的共享问题及其解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

有几个原因可能导致无法共享对象。 首先,如果您在实体上创建了主从关系,则会禁用该实体的共享,因为可见性是由父级控制的。 在这种情况下,您还会注意到“所有者”字段丢失,因为所有者不能更改,并且始终被视为父记录的所有者。 其次,可能是您的实体处于公共读/写模式。 共享仅适用于不能全局访问的实体(即它们必须是只读或私有的)。 请检查设置>安全控制>共享设置此实体的配置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值