You need to sign in to do that
Don't have an account?
shwetha prabhakar
Test class for order product trigger
Hi all,
Can anyone help me writing the test class for my trigger.
trigger orderproduct on Order__c (after insert,after update) {
Set<Id> opportunityIds = new Set<Id>();
Set<Id> orderIds = new Set<Id>();
List<Order__c> orderList = new List<Order__c>();
Map<Id,Id> mapof = new Map<Id,Id>();
for(Order__c o : Trigger.new)
{
if(o.Opportunity__c != NULL)
{
opportunityIds.add(o.Opportunity__c );
orderIds.add(o.Id);
mapof.put(o.Opportunity__c ,o.Id);
}
}
if(opportunityIds.size() > 0)
{
list<OpportunityLineItem__c> oppprodList = new list<OpportunityLineItem__c>([Select id,name,Product2Id__r.name,ListPrice__c,OpportunityId__c,Sales_Price__c,Quantity__c from OpportunityLineItem__c WHERE OpportunityId__c=:opportunityIds]);
// Loop through orders
List<OrderItem__c> orderItemsForInsert = new List<OrderItem__c>();
for(OpportunityLineItem__c pd : oppprodList)
{
OrderItem__c oi = new OrderItem__c();
oi.OrderId__c = mapof.get(pd.OpportunityId__c);
oi.Name = pd.Product2Id__r.name;
oi.ListPrice__c = pd.ListPrice__c;
oi.Unit_Price__c = pd.Sales_Price__c;
oi.Quantity__c = pd.Quantity__c;
orderItemsForInsert.add(oi);
}
system.debug('sucess');
if(orderItemsForInsert.size() > 0)
{
system.debug('orderItemsForInsert +' +orderItemsForInsert);
insert orderItemsForInsert;
}
}
}
Can anyone help me writing the test class for my trigger.
trigger orderproduct on Order__c (after insert,after update) {
Set<Id> opportunityIds = new Set<Id>();
Set<Id> orderIds = new Set<Id>();
List<Order__c> orderList = new List<Order__c>();
Map<Id,Id> mapof = new Map<Id,Id>();
for(Order__c o : Trigger.new)
{
if(o.Opportunity__c != NULL)
{
opportunityIds.add(o.Opportunity__c );
orderIds.add(o.Id);
mapof.put(o.Opportunity__c ,o.Id);
}
}
if(opportunityIds.size() > 0)
{
list<OpportunityLineItem__c> oppprodList = new list<OpportunityLineItem__c>([Select id,name,Product2Id__r.name,ListPrice__c,OpportunityId__c,Sales_Price__c,Quantity__c from OpportunityLineItem__c WHERE OpportunityId__c=:opportunityIds]);
// Loop through orders
List<OrderItem__c> orderItemsForInsert = new List<OrderItem__c>();
for(OpportunityLineItem__c pd : oppprodList)
{
OrderItem__c oi = new OrderItem__c();
oi.OrderId__c = mapof.get(pd.OpportunityId__c);
oi.Name = pd.Product2Id__r.name;
oi.ListPrice__c = pd.ListPrice__c;
oi.Unit_Price__c = pd.Sales_Price__c;
oi.Quantity__c = pd.Quantity__c;
orderItemsForInsert.add(oi);
}
system.debug('sucess');
if(orderItemsForInsert.size() > 0)
{
system.debug('orderItemsForInsert +' +orderItemsForInsert);
insert orderItemsForInsert;
}
}
}
Huiz hou
I found the perfect place for my needs. Contains wonderful and useful messages (https://cofoam.com/). |