You need to sign in to do that
Don't have an account?
Allen2
please anyone help me to write test class for this apex class
public class ProReqClass
{
public String checkPro(Opportunity[] old_oppValue,Opportunity[] new_oppValue)
{
String message='';
List<OpportunityLineItem> oppProductList = new List<OpportunityLineItem>();
Set<Id> priceBookEntryIds = new Set<Id>();
Set<String> productName = new Set<String>();
Set<String> stagNames = new Set<String>();
stagNames.add('5. Prove');
stagNames.add('6. Negotiate');
stagNames.add('7. Contract');
stagNames.add('8. Won');
stagNames.add('4. Negotiate');
stagNames.add('5. Closed Won');
try
{
if(new_oppValue[0].RecordTypeId !=null)
{
List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true and Id=:new_oppValue[0].RecordTypeId];
if (rtypes.size()==1)
{
if((rtypes[0].Name == 'AB Opportunity') && stagnames.contains(new_OppValue[0].StageName))
{
oppProductList = [Select Id, PriceBookEntryId, OpportunityId, Source__c, Custom_Hardware_or_Software__c, Service__c, Input__c, Envelope_Finishing_System__c, Selective_Opener_Inbound_Only__c, OCR_Reading__c, Inline_Scale_or_Meter__c, Retrofit__c, Status__c from OpportunityLineItem where OpportunityId=:new_oppValue[0].Id];
if(oppProductList.size() > 0)
{
for (integer i=0; i<oppProductList.size(); i++)
{
if(oppProductList[i].Source__c ==null || oppProductList[i].Custom_Hardware_or_Software__c ==null || oppProductList[i].Service__c==null || oppProductList[i].Input__c==null || oppProductList[i].Envelope_Finishing_System__c == null || oppProductList[i].Selective_Opener_Inbound_Only__c ==null ||oppProductList[i].OCR_Reading__c == null || oppProductList[i].Inline_Scale_or_Meter__c ==null || oppProductList[i].Retrofit__c ==null || oppProductList[i].Status__c==null)
{
priceBookEntryIds.add(oppProductList[i].PriceBookEntryId);
}
}
if(priceBookEntryIds.size()>0)
{
List<PricebookEntry> productIdsList = new List<PricebookEntry>();
productIdsList = [select Name from PricebookEntry where id in :priceBookEntryIds];
if(productIdsList.size()>0)
{
for (Integer j=0;j<productIdsList.size();j++)
{
message+=productIdsList[j].Name+',';
}
return message;
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
Catch(Exception e)
{
System.debug('While Processing:'+e.getMessage());
return message;
}
}
}
{
public String checkPro(Opportunity[] old_oppValue,Opportunity[] new_oppValue)
{
String message='';
List<OpportunityLineItem> oppProductList = new List<OpportunityLineItem>();
Set<Id> priceBookEntryIds = new Set<Id>();
Set<String> productName = new Set<String>();
Set<String> stagNames = new Set<String>();
stagNames.add('5. Prove');
stagNames.add('6. Negotiate');
stagNames.add('7. Contract');
stagNames.add('8. Won');
stagNames.add('4. Negotiate');
stagNames.add('5. Closed Won');
try
{
if(new_oppValue[0].RecordTypeId !=null)
{
List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true and Id=:new_oppValue[0].RecordTypeId];
if (rtypes.size()==1)
{
if((rtypes[0].Name == 'AB Opportunity') && stagnames.contains(new_OppValue[0].StageName))
{
oppProductList = [Select Id, PriceBookEntryId, OpportunityId, Source__c, Custom_Hardware_or_Software__c, Service__c, Input__c, Envelope_Finishing_System__c, Selective_Opener_Inbound_Only__c, OCR_Reading__c, Inline_Scale_or_Meter__c, Retrofit__c, Status__c from OpportunityLineItem where OpportunityId=:new_oppValue[0].Id];
if(oppProductList.size() > 0)
{
for (integer i=0; i<oppProductList.size(); i++)
{
if(oppProductList[i].Source__c ==null || oppProductList[i].Custom_Hardware_or_Software__c ==null || oppProductList[i].Service__c==null || oppProductList[i].Input__c==null || oppProductList[i].Envelope_Finishing_System__c == null || oppProductList[i].Selective_Opener_Inbound_Only__c ==null ||oppProductList[i].OCR_Reading__c == null || oppProductList[i].Inline_Scale_or_Meter__c ==null || oppProductList[i].Retrofit__c ==null || oppProductList[i].Status__c==null)
{
priceBookEntryIds.add(oppProductList[i].PriceBookEntryId);
}
}
if(priceBookEntryIds.size()>0)
{
List<PricebookEntry> productIdsList = new List<PricebookEntry>();
productIdsList = [select Name from PricebookEntry where id in :priceBookEntryIds];
if(productIdsList.size()>0)
{
for (Integer j=0;j<productIdsList.size();j++)
{
message+=productIdsList[j].Name+',';
}
return message;
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
Catch(Exception e)
{
System.debug('While Processing:'+e.getMessage());
return message;
}
}
}
I am getting this error Initial expression is of incorrect type, expected: Opportunity but was: Id on line 54
below part is not covering
f(new_oppValue[0].RecordTypeId !=null)
{
List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true and Id=:new_oppValue[0].RecordTypeId];
if (rtypes.size()==1)
{
if((rtypes[0].Name == 'AB Opportunity') && stagnames.contains(new_OppValue[0].StageName))
{
oppProductList = [Select Id, PriceBookEntryId, OpportunityId, Source__c, Custom_Hardware_or_Software__c, Service__c, Input__c, Envelope_Finishing_System__c, Selective_Opener_Inbound_Only__c, OCR_Reading__c, Inline_Scale_or_Meter__c, Retrofit__c, Status__c from OpportunityLineItem where OpportunityId=:new_oppValue[0].Id];
if(oppProductList.size() > 0)
{
for (integer i=0; i<oppProductList.size(); i++)
{
if(oppProductList[i].Source__c ==null || oppProductList[i].Custom_Hardware_or_Software__c ==null || oppProductList[i].Service__c==null || oppProductList[i].Input__c==null || oppProductList[i].Envelope_Finishing_System__c == null || oppProductList[i].Selective_Opener_Inbound_Only__c ==null ||oppProductList[i].OCR_Reading__c == null || oppProductList[i].Inline_Scale_or_Meter__c ==null || oppProductList[i].Retrofit__c ==null || oppProductList[i].Status__c==null)
{
priceBookEntryIds.add(oppProductList[i].PriceBookEntryId);
}
}
if(priceBookEntryIds.size()>0)
{
List<PricebookEntry> productIdsList = new List<PricebookEntry>();
productIdsList = [select Name from PricebookEntry where id in :priceBookEntryIds];
if(productIdsList.size()>0)
{
for (Integer j=0;j<productIdsList.size();j++)
{
message+=productIdsList[j].Name+',';
}
return message;
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
}
}
else
{
return message;
okay... I will check it again then will let you know.
Thanks Raj