我试图在潜在客户上创建salesforce触发器,该潜在客户自动填充查找字段,该字段将当前潜在客户关联到现有帐户,如果存在与主导公司自定义名称相同的帐户领域。Salesforce触发器来填充查找字段
这是我的代码:
trigger Link_Lead_To_Account on Lead (before insert) {
Set<String> whatIDs = new Set<String>();
MAP<id,String> accountMap= new MAP<id,String>();
// save the leads that have been triggered
for (Lead l : Trigger.new) {
whatIDs.add(l.id);
}
List<Lead> leads = [SELECT Id,Company FROM Lead where ID=:whatIDs ];
// loop through the triggered leads, if the account.name == to lead.company then link the found account to the lead
for (Integer i = 0; i <Trigger.new.size(); i++)
{
// System.Debug('++++++++++++++'+Trigger.new[i].company+Trigger.new[i].id);
if(accountMap.get(Trigger.new[i].company)!=null)
{
for(Account ac :[Select name,id from Account])
{
if(Trigger.new[i].Company==ac.Name)
{
Trigger.new[i].Account__c= ac.id;
break;
}
}
}
// System.Debug('Trigger.new[i].Account__c::::'+Trigger.new[i].Account__c);
// System.Debug('Trigger.new[i].company:::::'+Trigger.new[i].company);
// System.Debug('Trigger.new[i].ID:::::'+Trigger.new[i].ID);
}
update leads;
}
不过,这并不在所有的工作。它引发以下错误:
Review all error messages below to correct your data.
Apex trigger Link_Lead_To_Account caused an unexpected exception, contact your administrator: Link_Lead_To_Account: execution of AfterInsert caused by: System.StringException: Invalid id: TestAccount2: External entry point
,因为它要求公司字段是一个ID,但是当我写一个ID但这并没有进行任何更改。
你为什么更新导致对象? whatIDs将一直是空的。我相信在触发器还没有ID之前。 –
什么是TestAccount2? –
testAccount2是我用于测试目的的帐户的名称 –