You need to sign in to do that
Don't have an account?
need to devlope query on three object for inserting records in newly created object according to query
need to devlope query on Opportunity for id,name,stage & Oppounitylineitem for id,name & OpportunityContactRole for phone,email in a single query for this objects and this fields to be inserted in other custom object
i have devlope this query
select id,name, (select id,name from OpportunityLineItems), (Select id from OpportunityContactRoles) from Opportunity
but unale to insert records in my custom object:-
my cutstom obejct Name :- myobject__c
fields in that :- Oppid__c,Oppname__c,Productid__c,ProductName__c,Phone__c,Email__c need to insert in this object
can anyone please help me for to achive this requiremnt
public class mappingclass {
public static void Insert_Records(){
List<Mapping__c> lstCO = new List<Mapping__c>();
for(Opportunity opp : [select id,name, (select id,name from OpportunityLineItems), (Select id,phone,email from OpportunityContactRoles) from Opportunity ])
{
system.debug(opp.OpportunityLineItems);
Mapping__c co = new Mapping__c();
co.Name = opp.name;
for(OpportunityLineItem li : opp.OpportunityLineItems)
{
co.Oli_name =li.name;
}
for(OpportunityContactRole ocr : opp.OpportunityContactRoles)
{
co.Ocr_contactid__c=ocr.id;
}
lstCO.add(co);
}
insert lstCO;
}
}
now this class is working fine accordig to my requiremnt now i am just getting governer limits how can i avoaid can you please help in that
System.LimitException: Too many DML rows: 10001
Two possible solutions:
Reduce the size of the list by using the where clause.
Write a Batch class.
for(Opportunity opp : [select id,name, (select id,name from OpportunityLineItems), (Select id,phone,email from OpportunityContactRoles) from Opportunity WHERE Name= 'Test' LIMIT 1000])
OR
for(Opportunity opp : [select id,name, (select id,name from OpportunityLineItems), (Select id,phone,email from OpportunityContactRoles) from Opportunity LIMIT 1000])