function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Raghu kattulaRaghu 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);
}





 
Best Answer chosen by Raghu kattula
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Raghu,

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 .
 
select id,LastName from contact where Lastname='xxxxx'


Replace xxxx with the Account Name.

Please Mark it As Best Asnwer If It Helps

Thanks,
 

All Answers

Raghu kattulaRaghu kattula
Hii CharuDutt Happy to see your reply

i tried ur Code its executing but not creating Contact
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Raghu,

Did you tried to update the apex class as i shared? or do you need to pass the map to the method?

Thanks,
 
Raghu kattulaRaghu kattula
Hi Sai Praveen
No Errors are there it has to create contact record automatically after creating Account record but it's failing to create contact record 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Raghu,

As said in my answer did you tried to add that extra line highlited.

con.accountid= EA.ID;

This should solve your issue.

Thanks,
 
Raghu kattulaRaghu kattula
thats really helped alot...sai praveen but i'm expecting to generate separate contact with same account details 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Raghu,

Can you confirm what do you meant by seperate contact. You mean you dont want to relate the contact to the Account?

Thanks,
 
Raghu kattulaRaghu kattula
yes
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Raghu,

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 .
 
select id,LastName from contact where Lastname='xxxxx'


Replace xxxx with the Account Name.

Please Mark it As Best Asnwer If It Helps

Thanks,
 
This was selected as the best answer
Raghu kattulaRaghu kattula
Thank you Sai praveen...