You need to sign in to do that
Don't have an account?
Parth Srivastava
Please help with test class as i am unable to call wrapper class
public with sharing class NewOpportunityLTNGController {
@AuraEnabled
public static WrapperClass isContact(String contactId){
String objectAPIName = '';
String keyPrefix = contactId.substring(0,3);
for( Schema.SObjectType obj : Schema.getGlobalDescribe().Values() ){
String prefix = obj.getDescribe().getKeyPrefix();
if(prefix == keyPrefix){
objectAPIName = obj.getDescribe().getName();
break;
}
}
Contact objContact = [SELECT Id, Name,LeadSource,Lead_Source_Name__c, AccountId, Account.Name FROM Contact WHERE Id =:contactId];
CampaignMember objCampaignMember = [SELECT Id, Name, contactId, CampaignId FROM CampaignMember WHERE ContactId =: contactId Order By CreatedDate DESC Limit 1];
WrapperClass objWrapper = new WrapperClass();
objWrapper.hasError = false;
objWrapper.errorStr = '';
objWrapper.objOpportunity = new Opportunity();
objWrapper.recordTypes = getItems();
objWrapper.types = getType();
for(MapWrapper objRecordType : objWrapper.recordTypes){
if(objRecordType.recordTypeName == 'Standard Opportunity'){
objWrapper.objOpportunity.RecordTypeId = objRecordType.recordTypeId;
}
}
objWrapper.objOpportunity.Name = objContact.Account.Name;
objWrapper.objOpportunity.AccountId = objContact.AccountId;
objWrapper.objOpportunity.FCRM__FCR_Admin_Originating_Contact__c = objContact.Id;
objWrapper.objOpportunity.CampaignId = objCampaignMember.CampaignId;
objWrapper.objOpportunity.LeadSource = objContact.LeadSource;
objWrapper.objOpportunity.Lead_Source_Name__c = objContact.Lead_Source_Name__c;
if(objectAPIName == 'Contact'){
objWrapper = checkPackageCode(contactId,objWrapper);
}else{
objWrapper.hasError = true;
objWrapper.errorStr = 'Opportunities must be created from a Contact';
}
return objWrapper;
}
public static WrapperClass checkPackageCode(String contactId, WrapperClass objWrapper){
// Required: If in Active Mode then opp must be created from a contact with an active response
if(!FCRM.FCR_SupportAPI.IsPassiveMode()) {
// Required: Contact must be part of an active campaign
List<CampaignMember> activeResponses = FCRM.FCR_SupportAPI.GetActiveResponses(new List<Id>{contactId});
if(activeResponses.size() == 0) {
// Add custom code here to prevent user from creating the opportunity.
// You could display a message like "To create an opportunity the contact must have an active repsonse"
// You could develop your page to show a JavaScript alert with a similar message
// You could redirect user back to the Contact after showing the message
objWrapper.hasError = true;
objWrapper.errorStr = 'To create an opportunity the contact must have an active repsonse';
}
}
return objWrapper;
}
public static List<MapWrapper> getItems(){
List<MapWrapper> options = new List<MapWrapper>();
String objectAPIName = 'Opportunity' ; //any object api
Schema.DescribeSObjectResult sobjectResult = Schema.getGlobalDescribe().get(objectAPIName).getDescribe();
List<Schema.RecordTypeInfo> recordTypeInfo = sobjectResult.getRecordTypeInfos();
//Map<String,Id> mapofNameAndId = new Map<String,Id>();
for(Schema.RecordTypeInfo info : recordTypeInfo){
//mapofCaseRecordTypeNameandId.put(info.getName(),info.getRecordTypeId());
if(info.getName() != 'Master' && info.getName() != 'PoC Opportunity'){
//mapofNameAndId.put(info.getName(),info.getRecordTypeId());
MapWrapper objMapWrapper = new MapWrapper();
objMapWrapper.recordTypeId = info.getRecordTypeId();
objMapWrapper.recordTypeName = info.getName();
options.add(objMapWrapper);
}
}
return options;
}
public static List<MapWrapper> getType(){
String objectAPIName = 'Opportunity' ; //any object api
List<MapWrapper> options = new List<MapWrapper>();
Schema.DescribeSObjectResult sobjectResult = Schema.getGlobalDescribe().get(objectAPIName).getDescribe();
Schema.DescribeFieldResult fieldResult = Opportunity.Type.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple) {
MapWrapper objMapWrapper = new MapWrapper();
objMapWrapper.recordTypeId = f.getValue();
objMapWrapper.recordTypeName = f.getLabel();
options.add(objMapWrapper);
}
return options;
}
public class WrapperClass{
@AuraEnabled
public Boolean hasError;
@AuraEnabled
public String errorStr;
@AuraEnabled
public Opportunity objOpportunity;
@AuraEnabled
public List<NewOpportunityLTNGController.MapWrapper> recordTypes;
@AuraEnabled
public List<NewOpportunityLTNGController.MapWrapper> types;
}
public class MapWrapper{
@AuraEnabled
public String recordTypeId;
@AuraEnabled
public String recordTypeName;
}
}
@AuraEnabled
public static WrapperClass isContact(String contactId){
String objectAPIName = '';
String keyPrefix = contactId.substring(0,3);
for( Schema.SObjectType obj : Schema.getGlobalDescribe().Values() ){
String prefix = obj.getDescribe().getKeyPrefix();
if(prefix == keyPrefix){
objectAPIName = obj.getDescribe().getName();
break;
}
}
Contact objContact = [SELECT Id, Name,LeadSource,Lead_Source_Name__c, AccountId, Account.Name FROM Contact WHERE Id =:contactId];
CampaignMember objCampaignMember = [SELECT Id, Name, contactId, CampaignId FROM CampaignMember WHERE ContactId =: contactId Order By CreatedDate DESC Limit 1];
WrapperClass objWrapper = new WrapperClass();
objWrapper.hasError = false;
objWrapper.errorStr = '';
objWrapper.objOpportunity = new Opportunity();
objWrapper.recordTypes = getItems();
objWrapper.types = getType();
for(MapWrapper objRecordType : objWrapper.recordTypes){
if(objRecordType.recordTypeName == 'Standard Opportunity'){
objWrapper.objOpportunity.RecordTypeId = objRecordType.recordTypeId;
}
}
objWrapper.objOpportunity.Name = objContact.Account.Name;
objWrapper.objOpportunity.AccountId = objContact.AccountId;
objWrapper.objOpportunity.FCRM__FCR_Admin_Originating_Contact__c = objContact.Id;
objWrapper.objOpportunity.CampaignId = objCampaignMember.CampaignId;
objWrapper.objOpportunity.LeadSource = objContact.LeadSource;
objWrapper.objOpportunity.Lead_Source_Name__c = objContact.Lead_Source_Name__c;
if(objectAPIName == 'Contact'){
objWrapper = checkPackageCode(contactId,objWrapper);
}else{
objWrapper.hasError = true;
objWrapper.errorStr = 'Opportunities must be created from a Contact';
}
return objWrapper;
}
public static WrapperClass checkPackageCode(String contactId, WrapperClass objWrapper){
// Required: If in Active Mode then opp must be created from a contact with an active response
if(!FCRM.FCR_SupportAPI.IsPassiveMode()) {
// Required: Contact must be part of an active campaign
List<CampaignMember> activeResponses = FCRM.FCR_SupportAPI.GetActiveResponses(new List<Id>{contactId});
if(activeResponses.size() == 0) {
// Add custom code here to prevent user from creating the opportunity.
// You could display a message like "To create an opportunity the contact must have an active repsonse"
// You could develop your page to show a JavaScript alert with a similar message
// You could redirect user back to the Contact after showing the message
objWrapper.hasError = true;
objWrapper.errorStr = 'To create an opportunity the contact must have an active repsonse';
}
}
return objWrapper;
}
public static List<MapWrapper> getItems(){
List<MapWrapper> options = new List<MapWrapper>();
String objectAPIName = 'Opportunity' ; //any object api
Schema.DescribeSObjectResult sobjectResult = Schema.getGlobalDescribe().get(objectAPIName).getDescribe();
List<Schema.RecordTypeInfo> recordTypeInfo = sobjectResult.getRecordTypeInfos();
//Map<String,Id> mapofNameAndId = new Map<String,Id>();
for(Schema.RecordTypeInfo info : recordTypeInfo){
//mapofCaseRecordTypeNameandId.put(info.getName(),info.getRecordTypeId());
if(info.getName() != 'Master' && info.getName() != 'PoC Opportunity'){
//mapofNameAndId.put(info.getName(),info.getRecordTypeId());
MapWrapper objMapWrapper = new MapWrapper();
objMapWrapper.recordTypeId = info.getRecordTypeId();
objMapWrapper.recordTypeName = info.getName();
options.add(objMapWrapper);
}
}
return options;
}
public static List<MapWrapper> getType(){
String objectAPIName = 'Opportunity' ; //any object api
List<MapWrapper> options = new List<MapWrapper>();
Schema.DescribeSObjectResult sobjectResult = Schema.getGlobalDescribe().get(objectAPIName).getDescribe();
Schema.DescribeFieldResult fieldResult = Opportunity.Type.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple) {
MapWrapper objMapWrapper = new MapWrapper();
objMapWrapper.recordTypeId = f.getValue();
objMapWrapper.recordTypeName = f.getLabel();
options.add(objMapWrapper);
}
return options;
}
public class WrapperClass{
@AuraEnabled
public Boolean hasError;
@AuraEnabled
public String errorStr;
@AuraEnabled
public Opportunity objOpportunity;
@AuraEnabled
public List<NewOpportunityLTNGController.MapWrapper> recordTypes;
@AuraEnabled
public List<NewOpportunityLTNGController.MapWrapper> types;
}
public class MapWrapper{
@AuraEnabled
public String recordTypeId;
@AuraEnabled
public String recordTypeName;
}
}
Try this
I hope you find the above solution helpful. If it does mark as best answer to help others too.
Thanks,
Ramesh D