How to create Test Class Example
----------------------------------------------------------------------------------------------------------------------
This is a Test Class Example
----------------------------------------------------------------------------------------------------------------------
@isTest
public class CaseLineItemsQACloneCtrlTest {
@TestSetup
public static void TestSetup(){
string recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('OEM').getRecordTypeId();
Account acc = new Account();
acc.Name='testAcc';
acc.RecordTypeId = recordTypeId;
insert acc;
Account acc1 = new Account();
acc1.Name ='testAcc1';
acc1.RecordTypeId = recordTypeId;
insert acc1;
Id caseRecordTypeId = Schema.SObjectType.case.getRecordTypeInfosByName().get('Complaint - Technical').getRecordTypeId();
Contact objcon = new Contact();
objcon.LastName= 'TestContact';
insert objcon;
Partners__c objpart= new Partners__c();
objpart.Name='TestName';
objpart.SoldTo_Account__c=acc.Id;
objpart.Ship_To_Party__c=acc.Id;
insert objpart;
User u=[Select id from User Limit 1];
Case caseObj = new Case();
caseObj.Origin='Working';
caseObj.Status='new';
caseObj.Product_Family__c = 'Tapeline';
caseObj.Date_of_Reporting__c=System.today();
caseObj.Complaint_Classification__c ='Internal';
caseObj.Complaint_Period__c='PREINSTL';
caseObj.RecordTypeId = caseRecordTypeId;
caseObj.ContactId=objcon.Id;
caseObj.Internal_Reference__c=u.Id;
caseObj.Sold_To__c=acc.Id;
caseObj.Ship_To_Party__c=acc.Id;
insert caseObj;
Case_line_Item__c cLIObj = new Case_line_Item__c ();
cLIObj.Case__c = caseObj.Id;
cLIObj.Object__c ='treg';
cLIObj.Sub_Assembly__c='hhgk';
cLIObj.Cause__c='qwert';
insert cLIObj;
string brnd;
string prCatId;
Product_Category__c prCat = new Product_Category__c();
prCat.Name = 'testing';
prCat.Brand_1__c = 'NTN';
Insert prCat;
brnd = prCat.Brand_1__c;
Vendor_Product_Category__c venobj= new Vendor_Product_Category__c();
venobj.Vendor__c= acc.id;
venobj.Brand__c = 'NTN';
venobj.Product_Category__c = prCat.id;
// insert venobj;
prCatId = prCat.id;
Problem_Catalogue__c probCat = new Problem_Catalogue__c();
probCat.Problem_Category__c='problem';
probCat.Affected_Sub_Assembly__c='Assemble';
probCat.Affected_Part__c='parts';
probCat.Problem__c='prob';
probCat.Case_Record_Type__c='Complaint - Technical';
probCat.Code_Group_Object_Parts__c='codegroup';
probCat.Product_Family__c='ProductFamily';
insert probCat;
product2 prod2 = new product2 ();
prod2.Name='prodName';
prod2.SAP_Material_Ref__c='1234';
prod2.Description='WERTT';
insert prod2;
string recTypeName = 'E&C Request';
string tap = 'Tapeline';
string assembly = probCat.Affected_Sub_Assembly__c;
String caseRcTpId = probCat.Case_Record_Type__c;
String ids = caseObj.Id;
String caseRcd = probCat.Case_Record_Type__c;
String prbCat = probCat.Problem_Category__c='problem';
CaseLineItemsQACloneCtrl.getPartNamesFieldValue(prbCat, brnd, caseRcTpId,assembly);
CaseLineItemsQACloneCtrl.getSubAssemblyFieldValue(prbCat, brnd, caseRcTpId);
CaseLineItemsQACloneCtrl.getAssetRecords(ids);
CaseLineItemsQACloneCtrl.fetchVendors(prCatId, brnd);
CaseLineItemsQACloneCtrl.getLineItemsRecords(ids);
CaseLineItemsQACloneCtrl.getObjectsFieldValue(recTypeName, tap);
}
@isTest
public static void testMethod1(){
string recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('OEM').getRecordTypeId();
Account acc = new Account();
acc.Name='testAcc';
acc.RecordTypeId = recordTypeId;
insert acc;
Account acc1 = new Account();
acc1.Name='testAcc1';
acc1.RecordTypeId = recordTypeId;
insert acc1;
Id caseRecordTypeId = Schema.SObjectType.case.getRecordTypeInfosByName().get('Complaint - Technical').getRecordTypeId();
Contact objcon = new Contact();
objcon.LastName= 'TestContact';
insert objcon;
Partners__c objpart= new Partners__c();
objpart.Name='TestName';
objpart.SoldTo_Account__c=acc.Id;
objpart.Ship_To_Party__c=acc.Id;
insert objpart;
User u=[Select id from User Limit 1];
Case caseObj = new Case();
caseObj.Origin='Working';
caseObj.Status='new';
caseObj.Product_Family__c = 'Tapeline';
caseObj.Date_of_Reporting__c=System.today();
caseObj.Complaint_Classification__c ='Internal';
caseObj.Complaint_Period__c='PREINSTL';
caseObj.RecordTypeId = caseRecordTypeId;
caseObj.ContactId=objcon.Id;
caseObj.Internal_Reference__c=u.Id;
caseObj.Sold_To__c=acc.Id;
caseObj.Ship_To_Party__c=acc.Id;
insert caseObj;
List<Case_line_Item__c> caseLineItems = new List<Case_line_Item__c>();
Case_line_Item__c cLIObj = new Case_line_Item__c ();
cLIObj.Case__c = caseObj.Id;
cLIObj.Object__c ='treg';
cLIObj.Sub_Assembly__c='hhgk';
cLIObj.Cause__c='qwert';
insert cLIObj;
caseLineItems.add(cLIObj);
string brnd;
string prCatId;
Product_Category__c prCat = new Product_Category__c();
prCat.Name = 'testing';
prCat.Brand_1__c = 'NTN';
Insert prCat;
brnd = prCat.Brand_1__c;
Vendor_Product_Category__c venobj= new Vendor_Product_Category__c();
venobj.Vendor__c=RecordTypeId;
venobj.Brand__c = 'NTN';
venobj.Product_Category__c = prCat.id;
// insert venobj;
prCatId = prCat.id;
Problem_Catalogue__c probCat = new Problem_Catalogue__c();
probCat.Problem_Category__c='problem';
probCat.Affected_Sub_Assembly__c='Assemble';
probCat.Affected_Part__c='parts';
probCat.Problem__c='prob';
probCat.Case_Record_Type__c='Complaint - Technical';
probCat.Code_Group_Object_Parts__c='codegroup';
probCat.Product_Family__c='ProductFamily';
insert probCat;
product2 prod2 = new product2 ();
prod2.Name='prodName';
prod2.SAP_Material_Ref__c='1234';
prod2.Description='WERTT';
insert prod2;
string recTypeName = 'E&C Request';
string tap = 'Tapeline';
string assembly = probCat.Affected_Sub_Assembly__c;
String caseRcTpId = probCat.Case_Record_Type__c;
String ids = caseObj.Id;
String productIds = prod2.Id ;
String caseRcd = probCat.Case_Record_Type__c;
String prbCat = probCat.Problem_Category__c='problem';
Test.startTest();
CaseLineItemsQACloneCtrl.getPartNamesFieldValue(prbCat, brnd, caseRcTpId,assembly);
CaseLineItemsQACloneCtrl.getSubAssemblyFieldValue(prbCat, brnd, caseRcTpId);
CaseLineItemsQACloneCtrl.getAssetRecords(ids);
CaseLineItemsQACloneCtrl.fetchVendors(prCatId, brnd);
CaseLineItemsQACloneCtrl.getLineItemsRecords(ids);
CaseLineItemsQACloneCtrl.getObjectsFieldValue(recTypeName, tap);
CaseLineItemsQACloneCtrl.getObjectsFieldValue('Complaint - Technical', 'Loom');
CaseLineItemsQACloneCtrl.getCataloguePartsProblemsFieldValue('','','','','');
CaseLineItemsQACloneCtrl.getCatalogueCauseDescription('','','','','','');
CaseLineItemsQACloneCtrl.fetchProductSapNumber(productIds);
CaseLineItemsQACloneCtrl.saveLineItems(caseLineItems);
Test.stopTest();
}
@isTest
public static void testMethod2(){
string recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('OEM').getRecordTypeId();
Account acc = new Account();
acc.Name='testAcc';
acc.RecordTypeId = recordTypeId;
insert acc;
Account acc1 = new Account();
acc1.Name='testAcc1';
acc1.RecordTypeId = recordTypeId;
insert acc1;
Id caseRecordTypeId = Schema.SObjectType.case.getRecordTypeInfosByName().get('Complaint - Technical').getRecordTypeId();
Contact objcon = new Contact();
objcon.LastName= 'TestContact';
insert objcon;
Partners__c objpart= new Partners__c();
objpart.Name='TestName';
objpart.SoldTo_Account__c=acc.Id;
objpart.Ship_To_Party__c=acc.Id;
insert objpart;
User u=[Select id from User Limit 1];
Case caseObj = new Case();
caseObj.Origin='Working';
caseObj.Status='new';
caseObj.Product_Family__c = 'Tapeline';
caseObj.Date_of_Reporting__c=System.today();
caseObj.Complaint_Classification__c ='Internal';
caseObj.Complaint_Period__c='PREINSTL';
caseObj.RecordTypeId = caseRecordTypeId;
caseObj.ContactId=objcon.Id;
caseObj.Internal_Reference__c=u.Id;
caseObj.Sold_To__c=acc.Id;
caseObj.Ship_To_Party__c=acc.Id;
insert caseObj;
List<Case_line_Item__c> caseLineItems = new List<Case_line_Item__c>();
Case_line_Item__c cLIObj = new Case_line_Item__c ();
cLIObj.Case__c = caseObj.Id;
cLIObj.Object__c ='treg';
cLIObj.Sub_Assembly__c='hhgk';
cLIObj.Cause__c='qwert';
insert cLIObj;
caseLineItems.add(cLIObj);
string brnd;
string prCatId;
Product_Category__c prCat = new Product_Category__c();
prCat.Name = 'testing';
prCat.Brand_1__c = 'NTN';
Insert prCat;
brnd = prCat.Brand_1__c;
Vendor_Product_Category__c venobj= new Vendor_Product_Category__c();
venobj.Vendor__c=RecordTypeId;
venobj.Brand__c = 'NTN';
venobj.Product_Category__c = prCat.id;
// insert venobj;
prCatId = prCat.id;
Problem_Catalogue__c probCat = new Problem_Catalogue__c();
probCat.Problem_Category__c='problem';
probCat.Affected_Sub_Assembly__c='Assemble';
probCat.Affected_Part__c='parts';
probCat.Problem__c='prob';
probCat.Case_Record_Type__c='Complaint - Technical';
probCat.Code_Group_Object_Parts__c='codegroup';
probCat.Product_Family__c='ProductFamily';
insert probCat;
product2 prod2 = new product2 ();
prod2.Name='prodName';
prod2.SAP_Material_Ref__c='1234';
prod2.Description='WERTT';
insert prod2;
string recTypeName = 'E&C Request';
string tap = 'Tapeline';
string assembly = probCat.Affected_Sub_Assembly__c;
String caseRcTpId = probCat.Case_Record_Type__c;
String ids = caseObj.Id;
String productIds = prod2.Id ;
String caseRcd = probCat.Case_Record_Type__c;
String prbCat = probCat.Problem_Category__c='problem';
Test.startTest();
CaseLineItemsQACloneCtrl.getPartNamesFieldValue(prbCat, brnd, caseRcTpId,assembly);
CaseLineItemsQACloneCtrl.getSubAssemblyFieldValue(prbCat, brnd, caseRcTpId);
CaseLineItemsQACloneCtrl.getAssetRecords(ids);
CaseLineItemsQACloneCtrl.fetchVendors(prCatId, brnd);
CaseLineItemsQACloneCtrl.getLineItemsRecords(ids);
// CaseLineItemsQACloneCtrl.getObjectsFieldValue(recTypeName, tap);
CaseLineItemsQACloneCtrl.getObjectsFieldValue('Complaint - Technical', 'Loom');
CaseLineItemsQACloneCtrl.getCataloguePartsProblemsFieldValue('','','','','');
CaseLineItemsQACloneCtrl.getCatalogueCauseDescription('','','','','','');
CaseLineItemsQACloneCtrl.fetchProductSapNumber(productIds);
CaseLineItemsQACloneCtrl.saveLineItems(caseLineItems);
Test.stopTest();
}
}
------------------------------------------------------------------------------------------
This Is a Apex Class
------------------------------------------------------------------------------------------
/* @purpose: Apex controller for lightning component "CaseLineItemsQA", "CaseLineItemsQA_Child"
*
*
*/
/*
Modified By : Manjeet Kumar
Description : Ability to add multiple case line items from single screen
Inputs : Case Line Itmes that are being Created
Method/Segment : getLineItemsRecords
Modified Date : 20-04-2022
*/
/*
* @Purpose: get Case and Case Line Items Records
* @Parameters: getLineItemsRecords
* @Return: ResponseOne
**/
public class CaseLineItemsQACloneCtrl {
@AuraEnabled
public static AssestWrapper getAssetRecords(String recordId) {
system.debug('recordId '+recordId);
AssestWrapper objAssetWrap = new AssestWrapper();
List<Case> caseLst = [SELECT Id, CaseNumber,RecordType.Name, Sold_To__c,Sold_To__r.name, Ship_To_Party__r.Name,Ship_To_Party__c , Product_Family__c ,Account.Name
FROM Case
WHERE Id =:recordId LIMIT 1];
objAssetWrap.lstProductCategory = [SELECT Id,Name,Brand_1__c,Brand_2__c,Brand_3__c FROM Product_Category__c];
List<Asset> assetLst = new List<Asset>();
if(caseLst[0].Sold_To__c != null){
System.debug('caseLst[0].Sold_To__c '+caseLst[0].Sold_To__c );
objAssetWrap.lstCase = caseLst;
String caseProductFamily='%'+caseLst[0].Product_Family__c+'%';
System.debug(caseProductFamily);
assetLst = [SELECT Id,Name,AccountId,Model__c,Machine_No__c,Affected_Part_No__c,
Part_Sl_No_Batch_No__c,Quantity,Problem__c,Model_Description__c,Equipment_Number__c,Serial_Number__c,SerialNumber
FROM Asset WHERE (AccountId = :caseLst[0].Sold_To__c OR Sold_to_Party_Account__c=:caseLst[0].Sold_To__c)
and Ship_to_Party_Account__c = : caseLst[0].Ship_To_Party__c and ProductFamily LIKE :caseProductFamily
ORDER BY Equipment_Number__c DESC];
objAssetWrap.lstAsset = assetLst;
System.debug('AssetList>>>>'+assetLst);
}
return objAssetWrap;
}
@AuraEnabled
public static List<Vendor_Product_Category__c> fetchVendors(String brandValue, String ProdCategId){
List<Vendor_Product_Category__c> lstVendorProductCategory = [SELECT Id,Vendor__c, Vendor__r.Name
FROM Vendor_Product_Category__c WHERE Product_Category__c=: ProdCategId AND
Brand__c =: brandValue ];
System.debug(lstVendorProductCategory);
return lstVendorProductCategory;
}
//Wrapper class AssetWrapper
public class AssestWrapper {
@AuraEnabled public List<Case> lstCase ;
@AuraEnabled public List<Asset> lstAsset;
@AuraEnabled public List<Product_Category__c> lstProductCategory;
public assestWrapper(){
lstCase = new List<Case>();
lstAsset = new List<Asset>();
lstProductCategory = new List<Product_Category__c>();
}
}
@AuraEnabled
public static ResponseOne getLineItemsRecords(String recordId) {
CLIWrapper cli = new CLIWrapper();
cli.caseList = [SELECT Id, CaseNumber, Sold_To__r.name, Ship_To_Party__r.name, Product_Family__c ,Account.Name
FROM Case
WHERE Id =:recordId];
cli.caseLinItemRecords = [SELECT Id, Name, Case__c, Account__c, Model__c, Machine_No__c, Part_Name__c,
Affected_Part_No__c, Part_Sl_No_Batch_No__c, Quantity__c, Object__c , LastModifiedDate,
Problem__c, Cause__c , Account__r.Name, Case__r.CaseNumber, Asset__c, Asset__r.Name,
Product__c, Product__r.Name, ObjectAPI__c, Part_NameAPI__c, ProblemAPI__c, CauseAPI__c,CCM_Relevant__c
FROM Case_line_Item__c
WHERE Case__c =:recordId
ORDER by LastModifiedDate DESC];
return new ResponseOne(true,'Success', cli);
}
/*
* @Purpose: insert records of Case Line Items.
* @Parameters: getLineItemsRecords
* @Return: ResponseOne
**/
@AuraEnabled
public static string saveLineItems(List<Case_line_Item__c> cliRecords){
System.debug('cliRecords>>>'+cliRecords);
Savepoint sp = Database.setSavepoint();
try{
insert cliRecords;
return 'true';
} catch(Exception ex) {
Database.rollback(sp);
String errorVal = 'Error>>'+ex.getMessage()+'----at line number>>>'+ex.getLineNumber();
return errorVal;
}
}
/*
* @Purpose: getSearch result 3rd picklist
* @Parameters: String ObjectName, String fieldName, String value, String accountValue
* @Return: List<SObJectResult>
*
@AuraEnabled
public static List<SObJectResult> getResults(String ObjectName, String fieldName, String value, String accountValue, String productFamilyVal) {
String fieldSerialNumber ='SerialNumber';
List<SObJectResult> sObjectResultList = new List<SObJectResult>();
for(sObject so : Database.Query('Select Id, AccountId, Account.name,SerialNumber,ProductFamily,'+fieldName+' FROM '+ObjectName+' WHERE ( SerialNumber LIKE\'%' + value + '%\' OR ProductFamily LIKE\'%' +
value + '%\' OR Name LIKE\'%' + value + '%\' ) AND AccountId =: accountValue AND ProductFamily =: productFamilyVal')) {
String snumber = ' ';
snumber = (String)so.get('SerialNumber');
String spfamily = ' ';
spfamily = (String)so.get('ProductFamily');
String fieldvalue = (String)so.get(fieldName);
sObjectResultList.add(new SObjectResult(fieldvalue, so.Id, snumber, spfamily));
}
system.debug('sObjectResultList>>>'+sObjectResultList);
return sObjectResultList;
} */
/*
* @Purpose: getObjectsFieldValue 1st picklist Problem Catgory Value
**/
@AuraEnabled
public static List<OptionWrapper> getObjectsFieldValue(String productFamilyName, String caseRecTypeName){
system.debug('productFamilyName'+productFamilyName);
system.debug('caseRecTypeName'+caseRecTypeName);
List<AggregateResult> lstProbCatg = new List<AggregateResult>();
System.debug('productFamilyName'+productFamilyName);
System.debug('caseRecTypeName'+caseRecTypeName);
If(caseRecTypeName == 'Complaint - Technical' && (productFamilyName == 'Conversion' || productFamilyName == 'Loom' || productFamilyName == 'Tapeline') ){
lstProbCatg = [SELECT Problem_Category__c probCatg,Code_Group_Object_Parts__c codeGpObj FROM Problem_Catalogue__c WHERE (Case_Record_Type__c=:caseRecTypeName AND
(Product_Family__c = :productFamilyName OR Product_Family__c = 'Common for all product families')) Group BY Problem_Category__c,Code_Group_Object_Parts__c];
}else{
lstProbCatg = [SELECT Problem_Category__c probCatg,Code_Group_Object_Parts__c codeGpObj FROM Problem_Catalogue__c WHERE Case_Record_Type__c=:caseRecTypeName and Product_Family__c = 'Common for all product families'
Group BY Problem_Category__c,Code_Group_Object_Parts__c];
}
List<OptionWrapper> optionWrappers = new List<OptionWrapper>();
if(lstProbCatg.size() > 0){
for(AggregateResult pcRec : lstProbCatg){
optionWrappers.add(new OptionWrapper(String.valueOf(pcRec.get('probCatg')),String.valueOf(pcRec.get('codeGpObj'))));
}
}
return optionWrappers;
}
public class OptionWrapper {
@AuraEnabled public String label;
@AuraEnabled public String value;
public OptionWrapper(String label, String value) {
this.label = label;
this.value = value;
}
}
/*
* @Purpose: getPartNamesFieldValue 2nd picklist PartName (SubAssembly Value)
**/
@AuraEnabled
public static List<OptionWrapper> getSubAssemblyFieldValue(String objProbCatgName, String productFamilyName, String caseRecTypeName ){
system.debug('objProbCatgName '+objProbCatgName);
system.debug('objProbCatgName '+productFamilyName);
system.debug('objProbCatgName '+caseRecTypeName);
List<OptionWrapper> optionWrappers = new List<OptionWrapper>();
System.debug('objProbCatgName'+objProbCatgName);
List<AggregateResult> lstSubAssembly = new List<AggregateResult>();
If(caseRecTypeName == 'Complaint - Technical' && (productFamilyName == 'Conversion' || productFamilyName == 'Loom' || productFamilyName == 'Tapeline') ){
lstSubAssembly = [SELECT Affected_Sub_Assembly__c affSubAssembly,Object_Part_Code__c objPartCode FROM Problem_Catalogue__c WHERE (Case_Record_Type__c=:caseRecTypeName AND
Problem_Category__c=:objProbCatgName) AND (Product_Family__c = :productFamilyName OR Product_Family__c = 'Common for all product families') Group BY Affected_Sub_Assembly__c,Object_Part_Code__c];
}else{
lstSubAssembly = [SELECT Affected_Sub_Assembly__c affSubAssembly,Object_Part_Code__c objPartCode FROM Problem_Catalogue__c WHERE (Case_Record_Type__c=:caseRecTypeName AND
Problem_Category__c=:objProbCatgName) Group BY Affected_Sub_Assembly__c,Object_Part_Code__c];
}
if(lstSubAssembly.size() > 0){
for(AggregateResult subAssb : lstSubAssembly){
optionWrappers.add(new OptionWrapper(String.valueOf(subAssb.get('affSubAssembly')),String.valueOf(subAssb.get('objPartCode'))));
}
}
system.debug('optionWrappers '+optionWrappers);
return optionWrappers;
}
/*
* @Purpose: getCataloguePartsProblemsFieldValue 3rd picklist (Affected part)
**/
@AuraEnabled
public static List<OptionWrapper> getPartNamesFieldValue(String objProbCatgName,String catalogueSubAssbLabel, String productFamilyName, String caseRecTypeName){
List<OptionWrapper> optionWrappers = new List<OptionWrapper>();
List<AggregateResult> lstAffPart = new List<AggregateResult>();
If(caseRecTypeName == 'Complaint - Technical' && (productFamilyName == 'Conversion' || productFamilyName == 'Loom' || productFamilyName == 'Tapeline') ){
lstAffPart = [SELECT Affected_Part__c afPrt,Code_Group_Problem__c codeGpProb FROM Problem_Catalogue__c WHERE (Case_Record_Type__c=:caseRecTypeName AND
Affected_Sub_Assembly__c=:catalogueSubAssbLabel AND Problem_Category__c=:objProbCatgName) AND (Product_Family__c = :productFamilyName OR Product_Family__c = 'Common for all product families') Group BY Affected_Part__c,Code_Group_Problem__c];
}else{
lstAffPart = [SELECT Affected_Part__c afPrt,Code_Group_Problem__c codeGpProb FROM Problem_Catalogue__c WHERE (Case_Record_Type__c=:caseRecTypeName AND
Affected_Sub_Assembly__c=:catalogueSubAssbLabel AND Problem_Category__c=:objProbCatgName) Group BY Affected_Part__c,Code_Group_Problem__c];
}
if(lstAffPart.size() > 0){
for(AggregateResult affpart : lstAffPart){
optionWrappers.add(new OptionWrapper(String.valueOf(affpart.get('afPrt')),String.valueOf(affpart.get('codeGpProb'))));
}
}
return optionWrappers;
}
/*
* @Purpose: getCataloguePartsProblemsFieldValue 4th picklist (Problem)
**/
@AuraEnabled
public static List<OptionWrapper> getCataloguePartsProblemsFieldValue(String objProbCatgName,String catalogueSubAssbLabel, String cataloguePartsName, String productFamilyName, String caseRecTypeName){
List<OptionWrapper> optionWrappers = new List<OptionWrapper>();
List<AggregateResult> lstProblem = new List<AggregateResult>();
If(caseRecTypeName == 'Complaint - Technical' && (productFamilyName == 'Conversion' || productFamilyName == 'Loom' || productFamilyName == 'Tapeline') ){
lstProblem = [SELECT Problem__c probm,Damage_Code__c dmCode FROM Problem_Catalogue__c WHERE ( Case_Record_Type__c=:caseRecTypeName AND
Affected_Part__c=:cataloguePartsName AND Affected_Sub_Assembly__c=:catalogueSubAssbLabel AND Problem_Category__c=:objProbCatgName ) AND (Product_Family__c = :productFamilyName OR Product_Family__c = 'Common for all product families') Group BY Problem__c,Damage_Code__c];
}else{
lstProblem = [SELECT Problem__c probm,Damage_Code__c dmCode FROM Problem_Catalogue__c WHERE ( Case_Record_Type__c=:caseRecTypeName AND
Affected_Part__c=:cataloguePartsName AND Affected_Sub_Assembly__c=:catalogueSubAssbLabel AND Problem_Category__c=:objProbCatgName ) Group BY Problem__c,Damage_Code__c];
}
if(lstProblem.size() > 0){
for(AggregateResult prob : lstProblem){
optionWrappers.add(new OptionWrapper(String.valueOf(prob.get('probm')),String.valueOf(prob.get('dmCode'))));
}
}
return optionWrappers;
}
/*
* @Purpose: getCatalogueCauseDescription 5th picklist (Cause)
**/
@AuraEnabled
public static List<OptionWrapper> getCatalogueCauseDescription(String objProbCatgName,String catalogueSubAssbLabel, String cataloguePartsName,String problemName,String productFamilyName, String caseRecTypeName){
List<OptionWrapper> optionWrappers = new List<OptionWrapper>();
List<AggregateResult> lstCause = new List<AggregateResult>();
If(caseRecTypeName == 'Complaint - Technical' && (productFamilyName == 'Conversion' || productFamilyName == 'Loom' || productFamilyName == 'Tapeline') ){
lstCause = [SELECT Cause__c cau,Cause_Code__c cauCode FROM Problem_Catalogue__c WHERE ( Case_Record_Type__c=:caseRecTypeName AND
Affected_Part__c=:cataloguePartsName AND Affected_Sub_Assembly__c=:catalogueSubAssbLabel AND Problem_Category__c=:objProbCatgName AND Problem__c=:problemName ) AND (Product_Family__c = :productFamilyName OR Product_Family__c = 'Common for all product families') Group BY Cause__c,Cause_Code__c];
}else{
lstCause = [SELECT Cause__c cau,Cause_Code__c cauCode FROM Problem_Catalogue__c WHERE ( Case_Record_Type__c=:caseRecTypeName AND
Affected_Part__c=:cataloguePartsName AND Affected_Sub_Assembly__c=:catalogueSubAssbLabel AND Problem_Category__c=:objProbCatgName AND Problem__c=:problemName ) Group BY Cause__c,Cause_Code__c];
}
if(lstCause.size() > 0){
for(AggregateResult cu : lstCause){
optionWrappers.add(new OptionWrapper(String.valueOf(cu.get('cau')),String.valueOf(cu.get('cauCode'))));
}
}
// System.debug('optionWrappers: '+optionWrappers);
return optionWrappers;
}
@AuraEnabled
public static List<product2> fetchProductSapNumber(String prodtId){
System.debug('prodtId'+prodtId);
List<product2> lstProd = [SELECT Id,Name,SAP_Material_Ref__c,Description FROM product2 WHERE Id=:prodtId];
System.debug(lstProd);
return lstProd;
}
/* @AuraEnabled
public static String fetchProductName(String affectPartNum){
System.debug('affectPartNum'+affectPartNum);
String prodName = '';
List<product2> lstProd = [select id,Name,SAP_Material_Ref__c,Description from product2 where SAP_Material_Ref__c =: affectPartNum AND SAP_Material_Ref__c != ''];
if(!lstProd.isEmpty()){
prodName = lstProd[0].Name;
}
System.debug(prodName);
return prodName;
}*/
//Wrapper class response
public class CLIWrapper {
@AuraEnabled public List<Case_line_Item__c> caseLinItemRecords = new List<Case_line_Item__c>();
@AuraEnabled public List<Case> caseList = new List<Case>();
}
//Wrapper class for lookup search
public class SObJectResult {
@AuraEnabled
public String recName;
@AuraEnabled
public Id recId;
@AuraEnabled
public String serialNumber;
@AuraEnabled
public String productFamily;
public SObJectResult(String recNameTemp, Id recIdTemp, String serialNum, String productFam) {
recName = recNameTemp;
recId = recIdTemp;
serialNumber = serialNum;
productFamily = productFam;
}
}
//Wrapper class for lookup search
public class SObJectResultOne {
@AuraEnabled
public String recName;
@AuraEnabled
public Id recId;
public SObJectResultOne(String recNameTemp, Id recIdTemp) {
recName = recNameTemp;
recId = recIdTemp;
}
}
}
Comments
Post a Comment