You need to sign in to do that
Don't have an account?
vivek singh08481200707119766
This is trigger how we mnake its test class please help me
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);
}
}
}
}
}
}
Would help if you could share the code of test class you have written so we can help you solve the errors..if not started - I'd suggest you to write the code and share it here so we can help..
reference:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm
http://salesforce.stackexchange.com/questions/10988/how-to-write-a-unit-test-test-class-for-trigger