You need to sign in to do that
Don't have an account?
Oron Mizrachi
apex triger test
hi i have an apex trigger code that i dont know how to buuild a test for.
the code:
trigger PrimaryProduct on Opportunity (before update) {
list<opportunity> lt = trigger.new;
list<opportunityLineItem> opli = new list<opportunityLineItem>([select id ,product2.name, opportunityId,UnitPrice,Quantity from opportunitylineitem where opportunityId =: trigger.new[0].id]);
string productName='';
decimal salesprice='';
integer Quantity='';
for(opportunityLineItem o : opli){
productName = o.product2.name;
salesprice=o.UnitPrice;
Quantity =o.Quantity;
}
for(Opportunity opp : trigger.new){
opp.Opportunity_Prim_Product_Name__c = productName;
opp.product_qunt__c=Quantity;
opp.product_salesprice__c=salesprice;
}
}
can some one please help me building a test for it .
thanx
the code:
trigger PrimaryProduct on Opportunity (before update) {
list<opportunity> lt = trigger.new;
list<opportunityLineItem> opli = new list<opportunityLineItem>([select id ,product2.name, opportunityId,UnitPrice,Quantity from opportunitylineitem where opportunityId =: trigger.new[0].id]);
string productName='';
decimal salesprice='';
integer Quantity='';
for(opportunityLineItem o : opli){
productName = o.product2.name;
salesprice=o.UnitPrice;
Quantity =o.Quantity;
}
for(Opportunity opp : trigger.new){
opp.Opportunity_Prim_Product_Name__c = productName;
opp.product_qunt__c=Quantity;
opp.product_salesprice__c=salesprice;
}
}
can some one please help me building a test for it .
thanx
Try with below cod eit will help !
I will suggest one thing ,your trigger is bulkified so it will not work for bulk update .
Let m eknow if it helps .
All Answers
Try with below cod eit will help !
I will suggest one thing ,your trigger is bulkified so it will not work for bulk update .
Let m eknow if it helps .
i have a problem with the code its self - error: Compile Error: Illegal assignment from String to Decimal at line 8 column 9
Can you help with that?
thank you
You have initialize with null try to chage like
decimal salesprice=0;
integer Quantity=0;
Let me know if it helps .
Thanks
Manoj
can you help me code a line that will cancel the trigger if the oppertunity dont have a product related?
thanx again.
oron