+ Start a Discussion
Devaraj 7Devaraj 7 

how i can create contacts and oppprtunity when account created in salesforce

Ahmad J. KoubeissyAhmad J. Koubeissy
Hello,

You can click on contact's or opportunitys tab then click on new. On the layout of both objects you have lookup field to account called Account name. From there you can choose to which account you want to link the opportunity or the contact.

Kindly mark as best answer if this helps you
Best regards
Saurabh Gupta ManrasSaurabh Gupta Manras
You can do as Ahmad J. Koubeissy suggested , in addition to that you can also write a trigger that will create contacts and oppprtunity as soon as account is created 
Akshay_DhimanAkshay_Dhiman
Hi Devaraj ,
You can do this via Trigger. Below is a code for the same. I have tried in my Dev org its working fine.

Apex Class
public class CreateConOpp {
   public static void createopp(List <Account> actlist){
       list<contact> conList = new list<contact>();
       for(account ac:actlist){
           Contact ct = new Contact ();
           ct.LastName ='test Last Name';
           ct.AccountId = ac.id;
           conList.add(ct);
               }
       insert conList;
       list<Opportunity> oppList = new list<Opportunity>();
       for(account ac:actlist){
           Opportunity op = new Opportunity();
           op.Name = 'Test Opp';
           op.AccountId = ac.id;
           op.StageName = 'closed lost';
           op.CloseDate = date.today();
           oppList.add(op);
       }
       insert oppList;
   }
}

Apex Trigger :
trigger AccountTrigger on Account (after update, before update , after insert) {
   if(trigger.isafter && trigger.isinsert){
       CreateConOpp.createopp(Trigger.new);
   }
}
Regards,
Akshay