You need to sign in to do that
Don't have an account?
Raghu kattula
can anyone help me with this Trigger.newmap
Class
public class Trigger_New_Map
{
public Static void CreateContactRecord(Set<id> a)
{
List<Account> acc = [select id,Name,Phone,Industry from Account where id in :a];
List<Contact> Cont = New List<Contact>();
for(Account EA: acc)
{
Contact Con = New Contact();
Con.LastName = EA.Name;
Con.Phone = EA.phone;
Con.Description = EA.Industry;
Cont.add(Con);
}
Insert Cont;
}
}
TRIGGER
trigger Trigger_New_Map_Trigger on Account (After insert)
{
Map<id,Account> acc = Trigger.NewMap;
set<id> a = acc.keySet();
Trigger_New_Map.CreateContactRecord(a);
}
public class Trigger_New_Map
{
public Static void CreateContactRecord(Set<id> a)
{
List<Account> acc = [select id,Name,Phone,Industry from Account where id in :a];
List<Contact> Cont = New List<Contact>();
for(Account EA: acc)
{
Contact Con = New Contact();
Con.LastName = EA.Name;
Con.Phone = EA.phone;
Con.Description = EA.Industry;
Cont.add(Con);
}
Insert Cont;
}
}
TRIGGER
trigger Trigger_New_Map_Trigger on Account (After insert)
{
Map<id,Account> acc = Trigger.NewMap;
set<id> a = acc.keySet();
Trigger_New_Map.CreateContactRecord(a);
}
In that scenerio the code which you shared is working as expected. You just need to search the contact with the account name. Go to All contacts list view and search for the same.
Or use the below soql query and search the contact id .
Replace xxxx with the Account Name.
Please Mark it As Best Asnwer If It Helps
Thanks,
All Answers
i tried ur Code its executing but not creating Contact
Did you tried to update the apex class as i shared? or do you need to pass the map to the method?
Thanks,
No Errors are there it has to create contact record automatically after creating Account record but it's failing to create contact record
As said in my answer did you tried to add that extra line highlited.
con.accountid= EA.ID;
This should solve your issue.
Thanks,
Can you confirm what do you meant by seperate contact. You mean you dont want to relate the contact to the Account?
Thanks,
In that scenerio the code which you shared is working as expected. You just need to search the contact with the account name. Go to All contacts list view and search for the same.
Or use the below soql query and search the contact id .
Replace xxxx with the Account Name.
Please Mark it As Best Asnwer If It Helps
Thanks,