You need to sign in to do that
Don't have an account?
Aashi Aditi
trigger to create a new account on basis of first name and last name of contact
insertaccount: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.insertaccount: line 14, column 1
trigger insertaccount on Contact (after insert,after update)
{
set<id> accountIdList = new Set<id>();
for(contact con : Trigger.new)
{
accountIdList.add(con.accountid);
}
Map<Id,account> mapVar = new Map<Id,account>([SELECT id,name
FROM account WHERE Id IN : accountIdList]);
for(contact cont : Trigger.new)
{
mapVar.get(cont.accountid).name = cont.firstname + cont.LastName;
}
update mapVar.values();
}
when I create a new contact so on basis of first name and last name of contact we have to create new account.
trigger insertaccount on Contact (after insert,after update)
{
set<id> accountIdList = new Set<id>();
for(contact con : Trigger.new)
{
accountIdList.add(con.accountid);
}
Map<Id,account> mapVar = new Map<Id,account>([SELECT id,name
FROM account WHERE Id IN : accountIdList]);
for(contact cont : Trigger.new)
{
mapVar.get(cont.accountid).name = cont.firstname + cont.LastName;
}
update mapVar.values();
}
when I create a new contact so on basis of first name and last name of contact we have to create new account.
Try The Following Code Please Mark it As Best if it Helps
Thank You
My question before I give you the working code - if you want to create a new Account, why are you querying for the Account records?