You need to sign in to do that
Don't have an account?
need to cover code
Public class GE_OG_CalcCustomerCreditLimit
{
//AfterInsert
public void calcCustomerCreditLimitAfterInsert(List<Opportunity> newOpptyList)
{
List<Opportunity> newOpptyList1= (List<Opportunity>)newOpptyList;
Set<Id> setAccId = new Set<Id>();
List<GE_HQ_CUST_CREDIT_HIST__c> lstCustCreditHistoryUpdate = new List<GE_HQ_CUST_CREDIT_HIST__c>();
for (Opportunity Opp : newOpptyList1)
{
if((Opp.StageName=='Active - Commit' || Opp.StageName=='Closed Won')&& (Opp.GE_ES_R_Status__c !=null) && (Opp.GE_ES_R_Status__c != 'R0') && Opp.GE_HQ_Business_Tier1__c == 'Oil & Gas (O&G)')
{
if(Opp.AccountId != null)
{
setAccId.add(Opp.AccountId);
}
}
}
if(!setAccId.isEmpty())
{
for(GE_HQ_CUST_CREDIT_HIST__c Cch: [select Id, GE_HQ_Acct_Cr_Limit__c, GE_HQ_Cr_Limit_Exceeded__c, GE_HQ_Tot_AR_s__c, GE_HQ_Acc__c from GE_HQ_CUST_CREDIT_HIST__c where GE_HQ_Acc__c in: setAccId])
{
GE_HQ_CUST_CREDIT_HIST__c CchUpdate = new GE_HQ_CUST_CREDIT_HIST__c(Id=Cch.Id);
CchUpdate.GE_HQ_Acct_Cr_Limit__c = Cch.GE_HQ_Acct_Cr_Limit__c;
lstCustCreditHistoryUpdate.add(CchUpdate);
}
}
if(!lstCustCreditHistoryUpdate.isEmpty())
{
update lstCustCreditHistoryUpdate ;
}
}
//afterInser closed
//for AfterUpdate
public void calcCustomerCreditLimitAfterUpdate(List<Opportunity> newOpptyList,Map<Id,Opportunity> OldMapOpportunity)
{
List<Opportunity> newOpptyList1= (List<Opportunity>)newOpptyList;
Map<Id,Opportunity> oldMapOpportunity1=(Map<Id,Opportunity>) OldMapOpportunity;
Set<Id> setAccId = new Set<Id>();
List<GE_HQ_CUST_CREDIT_HIST__c> lstCustCreditHistoryUpdate = new List<GE_HQ_CUST_CREDIT_HIST__c>();
for (Opportunity Opp : newOpptyList1)
{
Opportunity OppBeforeUpdate = oldMapOpportunity1.get(Opp.Id);
if(OppBeforeUpdate.Amount != Opp.Amount || OppBeforeUpdate.StageName != Opp.StageName || OppBeforeUpdate.GE_ES_R_Status__c != Opp.GE_ES_R_Status__c)
{
System.debug('In Update====');
if(Opp.AccountId != null){setAccId.add(Opp.AccountId);}
}
}
if(!setAccId.isEmpty())
{
for(GE_HQ_CUST_CREDIT_HIST__c Cch: [select Id, GE_HQ_Acct_Cr_Limit__c, GE_HQ_Cr_Limit_Exceeded__c, GE_HQ_Tot_AR_s__c, GE_HQ_Acc__c from GE_HQ_CUST_CREDIT_HIST__c where GE_HQ_Acc__c in: setAccId])
{
GE_HQ_CUST_CREDIT_HIST__c CchUpdate = new GE_HQ_CUST_CREDIT_HIST__c(Id=Cch.Id);
CchUpdate.GE_HQ_Acct_Cr_Limit__c = Cch.GE_HQ_Acct_Cr_Limit__c;
lstCustCreditHistoryUpdate.add(CchUpdate);
}
}
if(!lstCustCreditHistoryUpdate.isEmpty())
{
update lstCustCreditHistoryUpdate ;
}
}
// for AfterUpdate close
}
---------------------
@isTest
private class GEOGCalcCustomerCreditLimit_Test{
static testMethod void GEOGCalcCustomerCreditLimit_Test(){
//User usr = new User(LastName='test user',Alias='tuser',DefaultGroupNotificationFrequency='N',DigestFrequency='N',Email='testuser@ge.com',Username='testuserr2@ge.com',EmailEncodingKey='UTF-8',LanguageLocaleKey='en_US',LocaleSidKey='IN',ProfileId= ProfId,TimeZoneSidKey='Asia/Kolkata',UserPermissionsCallCenterAutoLogin=false,UserPermissionsMarketingUser=false,UserPermissionsOfflineUser=false);
//Insert usr;
Account Acc = new Account();
Acc.Name = 'Test account';
Acc.BillingCountry = 'USA';
Acc.ShippingCountry = 'USA';
Acc.ShippingState = 'AT';
Acc.ShippingCity = 'TestShipping City';
Acc.ShippingStreet = 'Test Shipping Street';
Acc.ShippingPostalCode = '101010';
Acc.GE_HQ_Request_Status__c = 'CMF Approved';
insert Acc;
GE_HQ_CUST_CREDIT_HIST__c Cch = new GE_HQ_CUST_CREDIT_HIST__c();
Cch.GE_HQ_Acc__c = Acc.Id;
Cch.GE_HQ_Acct_Cr_Limit__c = 2500000;
Cch.GE_HQ_Cr_Limit_Remaining__c = 1000;
Cch.GE_HQ_Tot_AR_s__c = 2000;
insert Cch;
GE_Configuration_Setting__c cs= new GE_Configuration_Setting__c();
cs.GE_OG_DTS_OpptyID__c=5490;
cs.GE_PWNUC_Oppty_ID__c=5490;
cs.GE_OGGS_Oppty_Id__c=5490;
cs.GE_OG_Oppty_Id_Counter__c=5490;
cs.GE_OG_PII_OIDCnt__c=5490;
cs.GE_OG_SS_WSIDCntr__c=5490;
cs.name='OG Counter';
insert cs;
GE_ES_Project__c prj = new GE_ES_Project__c();
prj.Name = 'TestProject1';
prj.GE_OG_SS_First_Oil_Date__c=Date.today();
insert prj;
Opportunity oppty = new Opportunity();
oppty.RecordTypeId =[select id,name from recordtype where name like 'Grouped Flow' limit 1].id;
oppty.Name= 'Test Oppty1';
oppty.GE_ES_Project__c = prj.Id;
oppty.AccountId = Acc.Id;
oppty.Type = 'Primary';
oppty.StageName = 'Active - Commit';
oppty.GE_ES_R_Status__c = 'R1 Submitted';
oppty.GE_HQ_Business_Tier1__c = 'Oil & Gas (O&G)';
oppty.CurrencyIsoCode = 'USD';
oppty.GE_ES_Bid_Due_Date__c = Date.today();
oppty.CloseDate= Date.today();
oppty.Amount= 1000;
oppty.GE_OG_TM_Commercial_Center__c= 'Bari';
oppty.GE_OG_Stream__c = 'Core Services - Aberdeen';
oppty.GE_OG_TM_Quote_Type__c = 'Budget';
oppty.GE_OG_TM_Industrial_Sector__c = 'LNG';
oppty.GE_OG_TM_Subsector__c = 'CCR';
oppty.GE_OG_TM_Application_Center__c = 'Bari';
oppty.GE_OG_TM_RFQ_Received_Date__c = Date.today();
oppty.GE_OG_TM_Proposal_Assesment__c = 'Tech & Comm With Same Due Date';
//oppty.GE_OG_Oppty_End_User__c = buyer.Id;
oppty.End_User__c = Acc.Id;
oppty.GE_ES_OPPTY_CM__c = 35;
insert oppty;
test.startTest();
GE_Configuration_Setting__c cs1= new GE_Configuration_Setting__c();
cs1.GE_OG_DTS_OpptyID__c=5490;
cs1.GE_PWNUC_Oppty_ID__c=5490;
cs1.GE_OGGS_Oppty_Id__c=5490;
cs1.GE_OG_Oppty_Id_Counter__c=5490;
cs1.GE_OG_PII_OIDCnt__c=5490;
cs1.GE_OG_SS_WSIDCntr__c=5490;
cs1.name='OG Counter';
insert cs1;
}
}
for after update is not covering can you please help me out
Fresco
Can you share code of trigger, which is calling this class "GE_OG_CalcCustomerCreditLimit".?
i am facing the same error after adding the code even i tried it
System.DmlException: Update failed. First exception on row 0 with id 006K000000CgDkqIAF; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, GE_OG_Opportunity_Trigger: execution of AfterUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object
Class.GE_OG_Updating_Stage_Reason.updateStageReasonAfterUpdate: line 479, column 1
Class.GE_OG_Opportunity_TriggerHandlerManager.afterUpdateStageReasonUpdate: line 250, column 1
Trigger.GE_OG_Opportunity_Trigger: line 199, column 1: []
Above is the error i am facing could you please help me with this