5 réponses
Please check below sample code
Let us know if this will help youSet<Id> SetAccountId = new Set<Id>();
for(Contact cont: Trigger.new)
{
if(cont.AccountId != null)
{
SetAccountId.add(cont.AccountId);
}
}
if(SetAccountId.size() > 0 )
{
Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, Name, Type from Account where Id IN :SetAccountId ]);
for(Contact cont: Trigger.new)
{
if(cont.AccountId != null && mapAccount.containsKey(cont.AccountId) )
{
cont.Type__c = mapAccount.get(cont.AccountId).Type;
}
}
}