You need to sign in to do that
Don't have an account?
pintoo rajput
How to write test class for this type of class??
global with sharing class GAPContractLoadXML
{
WebService static String updateGapContractData(String xmlMessage)
{
Dom.Document xmlDoc = new Dom.Document();
xmlDoc.load(xmlMessage);
Gap gapObject = new Gap(xmlDoc.getRootElement());
GapApplicant applicant = gapObject.applicant;
GapContract contract = applicant.gapContract;
try
{
// If no error sent, update gap fields in loan object
if(String.isEmpty(contract.errorMessage))
{
// Get loan record to update
Opportunity loan = [select Id from Opportunity where RemRef__c =: applicant.remRef limit 1];
// Update loan
loan.Gap_Contract_Document__c = contract.contractDocument;
loan.Gap_Contract_Number__c = contract.contractNumber;
loan.Gap_Effective_Date__c = contract.effectiveDate;
loan.Gap_Effective_Odometer__c = contract.effectiveOdometer;
loan.Gap_Expiration_Date__c = contract.expirationDate;
loan.Gap_Expiration_Odometer__c = contract.expirationOdometer;
update loan;
return 'Gap Contract Data Updated Sucessfully';
}
// Error sent - print to debug logs
else
{
System.debug('=> Integration error updating Gap Contract Data: ' + contract.errorMessage);
return '=> Integration error updating Gap Contract Data: ' + contract.errorMessage;
}
}
catch(Exception e)
{
System.debug('=> Salesforce error updating Gap Contract Data: ' + e.getMessage());
return '=> Salesforce error updating Gap Contract Data: ' + e.getMessage();
}
}
global class Gap
{
global GapApplicant applicant{get;set;}
global Gap(Dom.XmlNode node)
{
Dom.XmlNode child = node.getChildElement('applicant', null);
if(child != null)
{
applicant = new GapApplicant(child);
}
}
}
global class GapApplicant
{
global GapContract gapContract;
global String origenateAppNumber;
global String remRef;
global GapApplicant(Dom.XmlNode node)
{
Dom.XmlNode child = node.getChildElement('GapContract', null);
if(child != null)
{
gapContract = new GapContract(child);
}
child = node.getChildElement('OrigenateAppNumber', null);
if(child != null)
{
origenateAppNumber = child.getText();
}
child = node.getChildElement('RemRef', null);
if(child != null)
{
remRef = child.getText();
}
}
}
global class GapContract
{
global String contractDocument;
global String contractNumber;
global DateTime effectiveDate;
global Integer effectiveOdometer;
global DateTime expirationDate;
global Integer expirationOdometer;
global String errorMessage;
global GapContract(Dom.XmlNode node)
{
Dom.XmlNode child = node.getChildElement('ContractDocument', null);
if(child != null)
{
contractDocument = child.getText();
}
child = node.getChildElement('ContractNumber', null);
if(child != null)
{
contractNumber = child.getText();
}
child = node.getChildElement('EffectiveDate', null);
if(child != null)
{
effectiveDate = DateTime.valueOf(child.getText());
}
child = node.getChildElement('EffectiveOdometer', null);
if(child != null)
{
effectiveOdometer = Integer.valueOf(child.getText());
}
child = node.getChildElement('ExpirationDate', null);
if(child != null)
{
expirationDate = DateTime.valueOf(child.getText());
}
child = node.getChildElement('ExpirationOdometer', null);
if(child != null)
{
expirationOdometer = Integer.valueOf(child.getText());
}
child = node.getChildElement('ErrorMessage', null);
if(child != null)
{
errorMessage = child.getText();
}
}
}
}
{
WebService static String updateGapContractData(String xmlMessage)
{
Dom.Document xmlDoc = new Dom.Document();
xmlDoc.load(xmlMessage);
Gap gapObject = new Gap(xmlDoc.getRootElement());
GapApplicant applicant = gapObject.applicant;
GapContract contract = applicant.gapContract;
try
{
// If no error sent, update gap fields in loan object
if(String.isEmpty(contract.errorMessage))
{
// Get loan record to update
Opportunity loan = [select Id from Opportunity where RemRef__c =: applicant.remRef limit 1];
// Update loan
loan.Gap_Contract_Document__c = contract.contractDocument;
loan.Gap_Contract_Number__c = contract.contractNumber;
loan.Gap_Effective_Date__c = contract.effectiveDate;
loan.Gap_Effective_Odometer__c = contract.effectiveOdometer;
loan.Gap_Expiration_Date__c = contract.expirationDate;
loan.Gap_Expiration_Odometer__c = contract.expirationOdometer;
update loan;
return 'Gap Contract Data Updated Sucessfully';
}
// Error sent - print to debug logs
else
{
System.debug('=> Integration error updating Gap Contract Data: ' + contract.errorMessage);
return '=> Integration error updating Gap Contract Data: ' + contract.errorMessage;
}
}
catch(Exception e)
{
System.debug('=> Salesforce error updating Gap Contract Data: ' + e.getMessage());
return '=> Salesforce error updating Gap Contract Data: ' + e.getMessage();
}
}
global class Gap
{
global GapApplicant applicant{get;set;}
global Gap(Dom.XmlNode node)
{
Dom.XmlNode child = node.getChildElement('applicant', null);
if(child != null)
{
applicant = new GapApplicant(child);
}
}
}
global class GapApplicant
{
global GapContract gapContract;
global String origenateAppNumber;
global String remRef;
global GapApplicant(Dom.XmlNode node)
{
Dom.XmlNode child = node.getChildElement('GapContract', null);
if(child != null)
{
gapContract = new GapContract(child);
}
child = node.getChildElement('OrigenateAppNumber', null);
if(child != null)
{
origenateAppNumber = child.getText();
}
child = node.getChildElement('RemRef', null);
if(child != null)
{
remRef = child.getText();
}
}
}
global class GapContract
{
global String contractDocument;
global String contractNumber;
global DateTime effectiveDate;
global Integer effectiveOdometer;
global DateTime expirationDate;
global Integer expirationOdometer;
global String errorMessage;
global GapContract(Dom.XmlNode node)
{
Dom.XmlNode child = node.getChildElement('ContractDocument', null);
if(child != null)
{
contractDocument = child.getText();
}
child = node.getChildElement('ContractNumber', null);
if(child != null)
{
contractNumber = child.getText();
}
child = node.getChildElement('EffectiveDate', null);
if(child != null)
{
effectiveDate = DateTime.valueOf(child.getText());
}
child = node.getChildElement('EffectiveOdometer', null);
if(child != null)
{
effectiveOdometer = Integer.valueOf(child.getText());
}
child = node.getChildElement('ExpirationDate', null);
if(child != null)
{
expirationDate = DateTime.valueOf(child.getText());
}
child = node.getChildElement('ExpirationOdometer', null);
if(child != null)
{
expirationOdometer = Integer.valueOf(child.getText());
}
child = node.getChildElement('ErrorMessage', null);
if(child != null)
{
errorMessage = child.getText();
}
}
}
}
Use this : http://forceschool.blogspot.in/search/label/Test%20Apex