You need to sign in to do that
Don't have an account?

Autopopulate the Lookup field on Accounts with a Trigger.
On Accounts, there is a related list called - Account Technical Profile . One Account can only have one ATP record. It will never have more than one ATP record.
There is a master details relationship between Account and ATP custom object.
I have another lookup field on Account - Copy_TechnicalProfile. I would like this field to be populated when the Account has an ATP record created. Here is my trigger.
trigger Capture_AccountTechnicalProfile on Account (before update) {
Set<Id> accIds = new Set<Id>();
Map(Id, Account> accmap;
for(Account acct: trigger.new)
{
if(acct.Account_Technical_Profile__Id != null)
{
accIds.add(acct.Account_Technical_Profile__Id);
}
accmap = [select Id, Copy_Account_Technical_Profile__c FROM Account where Account_Technical_Profile__Id IN : accIds];
for(Account acct : trigger.new)
{
if(acct.AccountId !=null && accmap.containsKey(acct.Account_Technical_Profile__Id)
{
Copy_Account_Technical_Profile__c = accMap.get(acct.Account_Technical_Profile__Id).Copy_Account_Technical_Profile__c;
}
}
I am getting this error message:-
![]() | Error: Compile Error: unexpected token: 'Map' at line 5 column 0
|
i made more changes, :-
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
trigger Capture_AccountTechnicalProfile on Account (before update) {
Set<Id> accIds = new Set<Id>();
Map<Id, Account> accmap = new Map <Id, Account>();
for(Account acct: trigger.new)
{
if(acct.Account_Technical_Profile__Id != null)
{
accIds.add(acct.Account_Technical_Profile__Id);
}
accmap = [select Id, Copy_Account_Technical_Profile__c FROM Account where Account_Technical_Profile__Id IN : accIds];
for(Account accttechy : trigger.new)
{
if(accttechy.AccountId !=null && accmap.containsKey(accttechy.Account_Technical_Profile__Id)
{
Copy_Account_Technical_Profile__c = accMap.get(accttechy.Account_Technical_Profile__Id).Copy_Account_Technical_Profile__c;
}
}
}
////////////////////////////////////////////////////////////////////////
TRY this code defenitly u get the solution for Autopopulation just you have to make Looup relation with User
trigger populateContactfromUser on Contact (before insert , before update){
Set<ID> setConIds = new Set<ID>();
for(Contact obj : trigger.new){
if(obj.User_Name__c!= null)
setConIds.add(obj.User_Name__c);
}
MAP<ID , User> mapCon = new MAP<ID , User>([Select Id,Email,Phone from User where id in: setConIds]);
for(Contact obj : trigger.new)
{
if(obj.User_Name__c != null)
{
User c = mapCon.get(obj.User_Name__c);
obj.Email= c.Email;
//Similarly you can assign Address fields as well, just add those field in Contact SOQL as well
}
}
}