With the single statement, i dont think it is posssible to inser the record for 4 different object's records.
But you can call one method and it will do the insert for multiple objects. See the sample code below :-
public class multipleObjectRecordPriya {
public Account acc {set;get;}
public Contact con {set;get;}
public Opportunity opp {set;get;}
public multipleObjectRecordPriya(){
acc = new Account();
con = new Contact();
opp = new Opportunity();
}
public pagereference create(){
insert acc;
insert con;
insert opp;
pagereference p = new pagereference('/'+acc.id);
return p;
}
}
If this information helps, then kindly mark it as best answer.
You can use Sobject to handle this. Sample code is below:
List<Sobject> SobjList = new List<Sobject>();
Lead l = new Lead(LastName='Lead 1', Company='Salesforce');
Account a = new Account(Name = 'Salesforce Account');
Contact c = new Contact(LastName = 'SFContact');
Opportunity o = new Opportunity(Name='Salesforce Opp', CloseDate = System.Today(),StageName = 'Prospecting' );
SobjList.add(l);
SobjList.add(a);
SobjList.add(c);
SobjList.add(o);
insert SobjList;
But you to handle the parent and child relationships between Account & Contact , Account & Opportunity.
With the single statement, i dont think it is posssible to inser the record for 4 different object's records.
But you can call one method and it will do the insert for multiple objects. See the sample code below :-
If this information helps, then kindly mark it as best answer.
Thanks!
You can use Sobject to handle this. Sample code is below:
But you to handle the parent and child relationships between Account & Contact , Account & Opportunity.
Thanks,
Maharajan.C