Creating An Objects Using Apex Through Workbench

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Creating an account using apex through workbench

 New Account

Account acc = new Account();

acc.name = 'Rajesh';

insert acc;

system.debug(acc);

 New Case

Case c = new Case();

c.Status = 'New';

insert c;

System.debug(c);

Where status is a mandatory filed

While creating filed through the workbench mandatory field is to be given

 New Opportunities

Opportunity opp = new Opportunity();

opp.Name = 'Rajesh';

opp.CloseDate = Date.today().addDays(2);

opp.Amount = 5000;

opp.StageName = 'Prospecting';

insert opp;

System.debug(opp);

For opportunities name ,closed date,amount,stagename is mandatory

When account is created contact is to be created

Account acc = new Account();

acc.Name = 'Madhusss';

insert acc; // Insert the new Account record

Contact con = new Contact();

con.FirstName = 'Madhu';

con.LastName = 'sss';
con.AccountId = acc.Id;

 Account to opp

Account acc = new Account();

acc.Name ='acc_opp';

insert acc;

Opportunity opp = new Opportunity();

opp.Name = 'Madhu-opp';

opp.CloseDate = Date.today().addDays(30);

opp.StageName = 'Prospecting';

opp.AccountId = acc.Id;

insert opp;

AccountId is field name for account releted to child object

Course to registration

Lookup fieldname : Course_MD__c

Course__c course = new Course__c();

course.Name = 'Sample Course';

insert course;

Registration__c registration = new Registration__c();

registration.Course_MD__c = course.id;

registration.Candidate_Name__c = 'registration_course';

registration.Email__c = 'registration_course@gmail.com';

insert registration;

You might also like