I am new to Salesforce.
I am creating an application where the user will email the JSON data to insert that data and attachment to the Lead Object using Email Services.
It is working fine in Sandbox Environment.
Using Change Sets for deployment from sandbox to production the Apex Class created for Email Service.
Not able to deploy it in production getting below error:
System.QueryException: List has no rows for assignment to SObject Stack Trace: Class.MC4SF.UserTest.createPlatformUser: line 17, column 1 Class.MC4SF.DataTest.create_CRUD_negative: line 97, column 1
MC4SF.SecUtil.CRUDException: "Modify" permission to object "MC4SF__Tour_Settings__c" is not allowed for the current user. Stack Trace: Class.MC4SF.SecUtil.checkCRUD: line 20, column 1 Class.MC4SF.SecUtil.checkCRUD: line 32, column 1 Class.MC4SF.Data: line 697, column 1 Class.MC4SF.Data: line 655, column 1 Class.MC4SF.Data: line 596, column 1 Class.MC4SF.Data: line 158, column 1 Class.MC4SF.Data: line 283, column 1 Class.MC4SF.Data: line 314, column 1 Class.MC4SF.Data: line 317, column 1 Class.MC4SF.Data: line 320, column 1 Class.MC4SF.SetupController.setDontShowTour: line 394, column 1 Class.MC4SF.SetupControllerTest.testSetDontShowTourFalse: line 867, column 1
APEX CLASS
global class LeadEmailHandler implements Messaging.InboundEmailHandler {
public Lead lead;
public List<Attachment>attachmentList = new List<Attachment>();
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
System.debug('The Email is '+ email);
String emailAddress = email.plainTextBody;
String jsonStr = email.plainTextBody;
Map<String, Object> m = (Map<String, Object>) JSON.deserializeUntyped(jsonStr);
lead = new Lead();
Decimal decVal_noofpos = Decimal.ValueOf(m.get('noof_pos').toString());
Decimal decVal_price = Decimal.ValueOf(m.get('posamount').toString());
lead.First_Name__c = m.get('first_name').toString();
lead.Last_Name__c =m.get('last_name').toString();
lead.Company =m.get('legal_name').toString();
lead.Ownerid =m.get('ownerid').toString();
lead.GSTN__c =m.get('gstno').toString();
lead.LeadSource = 'FOS';
lead.Lead_Sub_Source__c = 'FOS';
lead.Regional_Manager__c = m.get('rm_name').toString();
lead.Closed_By__c =m.get('rm_name').toString();
lead.DBA_Name__c =m.get('dba_name').toString();
lead.Phone =m.get('contact_no').toString();
lead.Landline__c =m.get('alt_contact_no').toString();
lead.Email = m.get('email').toString();
lead.Street__c = m.get('address1').toString();
lead.Location__c = 'Not Provided';
lead.State_pro__c = m.get('state1').toString();
lead.City__c = m.get('city1').toString();
lead.Zip_Postal_Code__c = m.get('pincode1').toString();
lead.Merchant_Type__c = m.get('shop_type').toString();
lead.Nature_of_Business__c = m.get('nature_ofbusiness').toString();
lead.Products__c = 'POS Terminal';
lead.Product_Description__c = m.get('terminal_type').toString();
lead.No_of_Terminal__c = decVal_noofpos;
lead.Plan__c = m.get('terminal_monthly_rent').toString();
lead.Bank_Name__c = m.get('bank_name').toString();
lead.BANK_BRANCH_NAME__c = m.get('bank_branch').toString();
lead.Account_Holder_Name__c = m.get('bank_account_nam').toString();
lead.Account_Number__c = m.get('bank_account_no').toString();
lead.IFSC_CODE__c = m.get('ifsc_code_no').toString();
lead.BANK_BRANCH_CODE__c = 000;
lead.MSF__c = m.get('mdr_cc_classic').toString();
lead.Payment_details__c = m.get('payment_details').toString();
lead.Remarks__c = m.get('remarks').toString();
lead.Zone__c = m.get('zone').toString();
lead.Amount__c = decVal_price;
insert lead;
if(email.binaryAttachments !=null && email.binaryAttachments.size()>0){
for(integer i=0 ; i<email.binaryAttachments.size() ; i++){
System.debug(email.binaryAttachments[i].body);
system.debug('Saving chatter files '+email.binaryAttachments[i].filename);
ContentVersion version = new ContentVersion();
String oldName = email.binaryAttachments[i].filename;
String newName = oldName.replace('_', ' ');
version.Title= newName;
version.PathOnClient = email.binaryAttachments[i].filename;
version.VersionData = email.binaryAttachments[i].body;
insert version;
ContentDocumentLink cdl = new ContentDocumentLink();
cdl.ContentDocumentId = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id =: version.Id].ContentDocumentId;
cdl.LinkedEntityId = lead.Id;
cdl.ShareType = 'V';
insert cdl;
}
if(!attachmentList.isEmpty()){
insert attachmentList;
System.debug('The Attachment id is '+ attachmentList[0].id);
}
}
result.success=true;
return result;
}}