我想改变机会.创造是为了领导.Ownerid,修改我的代码



我想改变机会。CreatedById为lead。Ownerid,纠正我的代码

trigger on opportunity(after insert)
lst<ooportunity> opps=[select opportunityId,CreatedById from opportunity where opportunityId IN 
: Trigger.New];
list<lead> leads=[SELECT Id,ConvertedOpportunityId,OwnerId From lead where isConverted=true];
for(opportunity ops:opps)
{if(leads.Id==opps.OpportunityId)
{ opps.CreatedById=leads.OwnerId;
ops.add(opps);
}
update ops;

你不能,至少不能那样。

审计字段(createdbyid, createddate, lastmodifiedbyid, lastmodifieddate)为只读,由SF内部修改。

有一个技巧可以打开它们,例如数据迁移(你加载了7年的机会,你想记录它们的真实创建日期,这样它就不会在报告中显示为峰值)。但你只有一次机会。

https://help.salesforce.com/s/articleView?id=000334139&type=1和https://help.salesforce.com/s/articleView?id=000331038&type=1

你需要在设置中勾选一些东西,这会导致在配置文件/权限集中出现2个魔术复选框。然后,您可以编辑您的配置文件(或创建新的权限集并分配给自己)。

你需要改变你的触发器到before insert(但如果它之前-铅仍在转换,opp id还不知道-所以你不能匹配它的铅.机会id)…即使这样-这个功能是针对系统管理员的,我怀疑普通用户没有"修改所有数据";我能做到。

重新考虑您的业务场景。也许你想设置机遇号。OwnerId,而不是CreatedById?

最新更新