You need to sign in to do that
Don't have an account?
vivek singh08481200707119766
please tell me how we make this trigger test class ,i make but no coverage increse this time its coverage is 0(zero)
“trigger makeInvoice on Opportunity (after insert, after update) {
for(Opportunity op :trigger.new){
if(op.StageName == 'Closed Won - Signed'){
List<OpportunityLineItem> opli = new List<OpportunityLineItem>();
opli = [select id,Gross__c, Product2id, OpportunityId from OpportunityLineItem where OpportunityId =: op.id order by Product2id];
if(opli.size() > 0){
String tmpId = '';
List<Invoices__c> lstInvoice = new List<Invoices__c>();
Invoices__c objInvoice = new Invoices__c();
Integer lm = opli.size();
Integer i = 1;
for(OpportunityLineItem ob: opli){
if(tmpId == ''){
tmpId = ob.Product2id;
objInvoice = new Invoices__c();
objInvoice.Opportunity_invoices__c = ob.OpportunityId;
objInvoice.Amount__c = ob.Gross__c;
}else{
if(tmpId == ob.Product2id){
objInvoice.Amount__c = objInvoice.Amount__c + ob.Gross__c;
}else{
lstInvoice.add(objInvoice);
tmpId = ob.Product2id;
objInvoice = new Invoices__c();
objInvoice.Opportunity_invoices__c = ob.OpportunityId;
objInvoice.Amount__c = ob.Gross__c;
}
}
if(i == lm){
lstInvoice.add(objInvoice);
}
i++;
}
if(lstInvoice.size() > 0){
try{
insert lstInvoice;
system.debug('!Lst '+lstInvoice);
}catch(Exception e){
system.debug('!Bingo '+e);
}
}
}
}
}
}”
for(Opportunity op :trigger.new){
if(op.StageName == 'Closed Won - Signed'){
List<OpportunityLineItem> opli = new List<OpportunityLineItem>();
opli = [select id,Gross__c, Product2id, OpportunityId from OpportunityLineItem where OpportunityId =: op.id order by Product2id];
if(opli.size() > 0){
String tmpId = '';
List<Invoices__c> lstInvoice = new List<Invoices__c>();
Invoices__c objInvoice = new Invoices__c();
Integer lm = opli.size();
Integer i = 1;
for(OpportunityLineItem ob: opli){
if(tmpId == ''){
tmpId = ob.Product2id;
objInvoice = new Invoices__c();
objInvoice.Opportunity_invoices__c = ob.OpportunityId;
objInvoice.Amount__c = ob.Gross__c;
}else{
if(tmpId == ob.Product2id){
objInvoice.Amount__c = objInvoice.Amount__c + ob.Gross__c;
}else{
lstInvoice.add(objInvoice);
tmpId = ob.Product2id;
objInvoice = new Invoices__c();
objInvoice.Opportunity_invoices__c = ob.OpportunityId;
objInvoice.Amount__c = ob.Gross__c;
}
}
if(i == lm){
lstInvoice.add(objInvoice);
}
i++;
}
if(lstInvoice.size() > 0){
try{
insert lstInvoice;
system.debug('!Lst '+lstInvoice);
}catch(Exception e){
system.debug('!Bingo '+e);
}
}
}
}
}
}”
hope that gets you started..
Daniel B Probert ,how we use invoice in test class please send bulkify test class
if that's the case then you don't need to reference this in the test class other than to do a system.assetequals check to verfiy that the invoice has been created?
i noticed i got something wrong in what i've sent though the stage should be set to something else on insert - then the oppline items needs to be add then the opportunity should be updated to the correct stage..
i might be wrong though - i don't have an invoice object in my order to test with..