You need to sign in to do that
Don't have an account?
bharath kuppala
i need to display message when mandatory field value is not given and need a test class for this code
@RestResource(urlMapping='/DealRegistration/*')
global with sharing class Ebuy_DealReg
{
@HttpPost
global static String doPost(String Youremail, String DealStatus, String DealName, String CustomerBudget, Decimal ExpectedRevenue,
Date ExpectedBookingDate, String SourcedbyMarketing, Date ProjectImplementationDate,
String MarketingCampaign, String DealDescription, String ProposedAlcatelLucentSolution, String Product,
String CustomerName, String Address1, String Address2, String ZipCode, String City, String Country, String StateProvince,
String Phone, String Salutation, String CustomerContactLastName, String CustomerContactFirstName, String CustomerContactemail,
String CustomercontactRole, String NeworExistingCustomer, String ExistingCustomerSolutionVendor, String ExistingCustomerProduct,
String CurrentsolutionReseller, String CurrentsolutionRelease, String CurrentSolutionAge, String Additionalcomments)
{
Deal__c del = new Deal__c();
del.BP_Email__c = Youremail;
del.Status__c = DealStatus;
del.Name = DealName;
del.CustomerBudget__c = CustomerBudget;
//del.CurrencyIsoCode = Currency;
del.Estimated_Revenue__c = ExpectedRevenue;
del.Expected_Booking_Date__c = ExpectedBookingDate;
del.Sourced_By_Marketing__c = SourcedbyMarketing;
del.Project_Implementation_Date__c = ProjectImplementationDate;
del.Campaign_Name__c = MarketingCampaign;
del.Deal_Description__c = DealDescription;
del.Proposed_Alcatel_Lucent_Solution__c = ProposedAlcatelLucentSolution;
del.Product__c = Product;
del.Company_Name__c = CustomerName;
del.Street1__c = Address1;
del.Street2__c = Address2;
del.ZipCode__c = ZipCode;
del.City__c = City;
del.Country__c = Country;
del.State_Province__c = StateProvince;
del.Phone__c = Phone;
del.Salutation__c = Salutation;
del.Customer_Contact_Last_Name__c = CustomerContactLastName;
del.Customer_Contact_First_Name__c = CustomerContactFirstName;
del.Customer_Contact_email__c = CustomerContactemail;
del.Customer_contact_Role__c = CustomercontactRole;
del.New_or_Existing_Customer__c = NeworExistingCustomer;
del.Existing_Customer_Solution_Vendor__c = ExistingCustomerSolutionVendor;
del.Existing_Customer_Product__c = ExistingCustomerProduct;
del.Current_Release__c = CurrentsolutionReseller;
del.Current_solution_Release__c = CurrentsolutionRelease;
del.Solution_Age__c = CurrentSolutionAge;
del.AdditionalComments__c = Additionalcomments;
Insert del;
return del.Id;
}
}
global with sharing class Ebuy_DealReg
{
@HttpPost
global static String doPost(String Youremail, String DealStatus, String DealName, String CustomerBudget, Decimal ExpectedRevenue,
Date ExpectedBookingDate, String SourcedbyMarketing, Date ProjectImplementationDate,
String MarketingCampaign, String DealDescription, String ProposedAlcatelLucentSolution, String Product,
String CustomerName, String Address1, String Address2, String ZipCode, String City, String Country, String StateProvince,
String Phone, String Salutation, String CustomerContactLastName, String CustomerContactFirstName, String CustomerContactemail,
String CustomercontactRole, String NeworExistingCustomer, String ExistingCustomerSolutionVendor, String ExistingCustomerProduct,
String CurrentsolutionReseller, String CurrentsolutionRelease, String CurrentSolutionAge, String Additionalcomments)
{
Deal__c del = new Deal__c();
del.BP_Email__c = Youremail;
del.Status__c = DealStatus;
del.Name = DealName;
del.CustomerBudget__c = CustomerBudget;
//del.CurrencyIsoCode = Currency;
del.Estimated_Revenue__c = ExpectedRevenue;
del.Expected_Booking_Date__c = ExpectedBookingDate;
del.Sourced_By_Marketing__c = SourcedbyMarketing;
del.Project_Implementation_Date__c = ProjectImplementationDate;
del.Campaign_Name__c = MarketingCampaign;
del.Deal_Description__c = DealDescription;
del.Proposed_Alcatel_Lucent_Solution__c = ProposedAlcatelLucentSolution;
del.Product__c = Product;
del.Company_Name__c = CustomerName;
del.Street1__c = Address1;
del.Street2__c = Address2;
del.ZipCode__c = ZipCode;
del.City__c = City;
del.Country__c = Country;
del.State_Province__c = StateProvince;
del.Phone__c = Phone;
del.Salutation__c = Salutation;
del.Customer_Contact_Last_Name__c = CustomerContactLastName;
del.Customer_Contact_First_Name__c = CustomerContactFirstName;
del.Customer_Contact_email__c = CustomerContactemail;
del.Customer_contact_Role__c = CustomercontactRole;
del.New_or_Existing_Customer__c = NeworExistingCustomer;
del.Existing_Customer_Solution_Vendor__c = ExistingCustomerSolutionVendor;
del.Existing_Customer_Product__c = ExistingCustomerProduct;
del.Current_Release__c = CurrentsolutionReseller;
del.Current_solution_Release__c = CurrentsolutionRelease;
del.Solution_Age__c = CurrentSolutionAge;
del.AdditionalComments__c = Additionalcomments;
Insert del;
return del.Id;
}
}
Please use the below updated class:
@RestResource(urlMapping='/DealRegistration/*')
global with sharing class Ebuy_DealReg
{
@HttpPost
global static String doPost(String Youremail, String DealStatus, String DealName, String CustomerBudget, Decimal ExpectedRevenue,
Date ExpectedBookingDate, String SourcedbyMarketing, Date ProjectImplementationDate,
String MarketingCampaign, String DealDescription, String ProposedAlcatelLucentSolution, String Product,
String CustomerName, String Address1, String Address2, String ZipCode, String City, String Country, String StateProvince,
String Phone, String Salutation, String CustomerContactLastName, String CustomerContactFirstName, String CustomerContactemail,
String CustomercontactRole, String NeworExistingCustomer, String ExistingCustomerSolutionVendor, String ExistingCustomerProduct,
String CurrentsolutionReseller, String CurrentsolutionRelease, String CurrentSolutionAge, String Additionalcomments)
{
String response = '';
Deal__c del = new Deal__c();
del.BP_Email__c = Youremail;
del.Status__c = DealStatus;
del.Name = DealName;
del.CustomerBudget__c = CustomerBudget;
//del.CurrencyIsoCode = Currency;
del.Estimated_Revenue__c = ExpectedRevenue;
del.Expected_Booking_Date__c = ExpectedBookingDate;
del.Sourced_By_Marketing__c = SourcedbyMarketing;
del.Project_Implementation_Date__c = ProjectImplementationDate;
del.Campaign_Name__c = MarketingCampaign;
del.Deal_Description__c = DealDescription;
del.Proposed_Alcatel_Lucent_Solution__c = ProposedAlcatelLucentSolution;
del.Product__c = Product;
del.Company_Name__c = CustomerName;
del.Street1__c = Address1;
del.Street2__c = Address2;
del.ZipCode__c = ZipCode;
del.City__c = City;
del.Country__c = Country;
del.State_Province__c = StateProvince;
del.Phone__c = Phone;
del.Salutation__c = Salutation;
del.Customer_Contact_Last_Name__c = CustomerContactLastName;
del.Customer_Contact_First_Name__c = CustomerContactFirstName;
del.Customer_Contact_email__c = CustomerContactemail;
del.Customer_contact_Role__c = CustomercontactRole;
del.New_or_Existing_Customer__c = NeworExistingCustomer;
del.Existing_Customer_Solution_Vendor__c = ExistingCustomerSolutionVendor;
del.Existing_Customer_Product__c = ExistingCustomerProduct;
del.Current_Release__c = CurrentsolutionReseller;
del.Current_solution_Release__c = CurrentsolutionRelease;
del.Solution_Age__c = CurrentSolutionAge;
del.AdditionalComments__c = Additionalcomments;
try
{
Insert del;
response = del.Id;
}
catch(Exception ex)
{
system.debug('@@@ Exception Message = ' + ex.getMessage());
//response = ex.getMessage();
if(response.contains('REQUIRED_FIELD_MISSING')) {
response = 'REQUIRED FIELD MISSING';
}
else
{
response = ex.getMessage();
}
}
return response;
}
}
=========================
Test Class :
the below test class is enough but please add the params properly if there is any value is restricted then pass that properly.
@IsTest
private class CaseManagerTest {
@isTest static void testCreateDeal() {
// Call the method to test : Please pass the data properly below
ID thisDealId = Ebuy_DealReg.doPost('test@test.com', 'New', 'Test', '100', 150 ,
Date.Today() , 'Test', Date.Today(),
'Test', 'Test', String ProposedAlcatelLucentSolution, String Product,
'Test', 'Test', 'Test', '600119', 'Chennai', 'India', 'CA',
'1234567890', 'Mr', 'Test', 'Test', 'Test@test.com',
'Test Manager', 'Test', 'Test', 'Test',
'Test', 'Test', 'Test', 'Test') ;
// Verify results
System.assert(thisDealId != null);
}
}
Can you please Let me know if it helps or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj