-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
4Questions
-
2Replies
Trigger to Fields Auto populate
I have Custom object named Team__c and Fields are like, Category__c(Picklist), Close_Date__c(Date), Stage__c(Picklist) also have Standard Opportunity object. The Team__c object and Opportunity has look-up relationship with Category__c(Picklist), Close_Date__c(Date), Stage__c(Picklist) fields . In opportunity I have custom field named Type__c(Picklist), whenever the Type__c from Opportunity is equal to 'New Team' (Type__c == 'New Team') the Category__c, Close_Date__c, Stage__c fields should populate in Team__c record while it create. Can anyone help on this? Thanks in advance. I have try with following trigger,
if(trigger.isAfter && trigger.isInsert) { List<Team__c> tt = new List<Team__c>(); Opportunity opp = new Opportunity(); if(opp.Type__c == 'New Team') { for(Opportunity oppty : trigger.new) { Team__c team = new Team__c(); team.Category__c = oppty.Category__c; team.Close_Date__c = oppty.Close_Date__c; team.Stage__c = oppty.Stage__c; tt.add(team); } } }
- Poorna Priya 16
- October 27, 2022
- Like
- 0
How to start learning about salesforce vlocity?
Hi Everyone,
I'm new to vlocity development. I wish to learn salesforce vlocity. Is there any trailhead course? or anything else?
Thanks in advance.
I'm new to vlocity development. I wish to learn salesforce vlocity. Is there any trailhead course? or anything else?
Thanks in advance.
- Poorna Priya 16
- September 16, 2021
- Like
- 0
Need test class with 75% code coverage
Trigger:
trigger GenerateAffiliate on Account (before insert)
{
for(Account account: Trigger.new)
{
if(Trigger.isInsert)
{
String jsonString,paymentAccessKey;
if (account != null)
{
String[] allowedAccountType = new String[] { 'Craftsman' };
String selectedRecType = account.RecordType.Name;
if (allowedAccountType.contains(selectedRecType) == true)
{
List<Novalnet_Global_Configuration__c> novalnetConfigList = [Select Id,Product_Activation_Key__c,Payment_Access_Key__c from Novalnet_Global_Configuration__c where Account_Record_Type__c =: selectedRecType];
if (novalnetConfigList.isEmpty() == false)
{
Novalnet_Global_Configuration__c novalnetConfig = novalnetConfigList[0];
paymentAccessKey = novalnetConfig.Payment_Access_Key__c;
Map<String, Object> merchant = new Map<String, Object>();
merchant.put('signature', novalnetConfig.Product_Activation_Key__c);
Map<String, Object> address = new Map<String, Object>();
address.put('street', account.BillingStreet);
address.put('city', account.BillingCity);
address.put('zip', account.BillingPostalCode);
address.put('country_code', account.BillingCountry);
Map<String, Object> affiliate = new Map<String, Object>();
affiliate.put('first_name', account.Name);
affiliate.put('last_name', account.Name);
affiliate.put('email', account.Email__c);
affiliate.put('customer_no', account.Website);
affiliate.put('tel', account.Phone);
affiliate.put('account_holder', account.Name);
affiliate.put('iban', account.IBAN__c);
affiliate.put('address', address);
String language = UserInfo.getLanguage();
String[] languageAry = language.split('_');
Map<String, Object> custom = new Map<String, Object>();
custom.put('lang', languageAry[0].toUppercase());
Map<String, Object> requestData = new Map<String, Object>();
requestData.put('merchant', merchant);
requestData.put('affiliate', affiliate);
requestData.put('custom', custom);
List <String> result = getValidatedRequest(requestData);
jsonString = result[0];
System.debug('Result List 0:: '+result[0]);
System.debug('Result List 1::' +result[1]);
if(result[1] == '')
{
if(Trigger.isInsert) //Testclass
{
// ServerCallouts.getCalloutData(jsonString, paymentAccessKey);
}
//Servercallouts.getCalloutData(jsonString, paymentAccessKey);
System.debug('Server Callout');
}
else
{
account.addError('ErrorMessage ::: '+result[1]);
}
}
}
}
}
}
public static List<String> getValidatedRequest(Map<String, Object> requestData)
{
String[] mandatoryParams = new String []{'signature', 'first_name', 'last_name', 'email', 'street', 'city', 'zip', 'country_code'};
String errorMsg = '';
List<String> result = new List<String>();
//return result;
for(String category : requestData.KeySet())
{
Map<String, Object> requestDataObj = (Map<String, Object>)requestData.get(String.valueOf(category));
for(Object categoryKey : requestDataObj.KeySet())
{
if(categoryKey == 'address')
{
Map<String, Object> subCategory = (Map<String, Object>) requestDataObj.get(String.valueOf(categoryKey));
for(Object subCategoryKey : subCategory.KeySet()) {
Map<String, Object> subCategoryParam = (Map<String, Object>) requestDataObj.get(String.valueOf(categoryKey));
string paramValue = String.valueOf(subCategoryParam.get(String.valueOf(subCategoryKey)));
if(paramValue == '' || paramValue == null)
{
if(mandatoryParams.contains(String.valueOf(subCategoryKey)))
{
errorMsg = 'Required parameter - ' + subCategoryKey + ' in the category ' + categoryKey + ' not received. ' +'\n';
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
subCategory.remove(String.valueOf(subCategoryKey));
}
requestDataObj.put(String.valueOf(categoryKey), subCategory);
}
}
else
{
string paramValue = String.valueOf(requestDataObj.get(String.valueOf(categoryKey)));
if(paramValue == '' || paramValue == null)
{
if(mandatoryParams.contains(String.valueOf(categoryKey)))
{
errorMsg = 'Required parameter - ' + categoryKey + ' in the category ' + category + ' not received. ' +'\n';
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
requestDataObj.remove(String.valueOf(categoryKey));
}
}
}
requestData.put(category, requestDataObj);
}
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
}
Test Class:
@isTest
private class AccountTriggerTest
{
@isTest
static void AccountTrigger()
{
Account acc = new Account(Name = 'Max', RecordTypeId = '0125g000000AMDLAA4',BillingStreet = 'Musterstr', BillingCity = 'Jaipur', BillingState = 'Raj', BillingPostalCode = '12345', BillingCountry = 'DE', Phone = '+49 089 123456', Fax = '+49 089 123456', Website = 'info@nova.com', Email__c = 'test@nova.com', IBAN__c = 'DE24300225090024114523523761956');
Insert acc;
acc = [select Id, Name,BillingStreet,BillingCity,Email__c,IBAN__c from Account where Id = :acc.Id];
String requestData = '{"merchant":{"signature":"7ibc7ob5|tu3454363345345674JEH3gNbeWJfIHah||567856|doU3HJVoyfsggm7MQ44qf7cpn7pc"},"customer":{"lang":"EN"},"affiliate":{"vat_id":"DE123453456","tel":"98744564563210","reference":"affiliateXXX","password":"Nova123123","mobile":"9874563210","login":"Nova","last_name":"Sample Acc","iban":null,"gender":"Female","first_name":"Sample Acc","fax":"+41054879","email":"test@nova.com","company_email":"info@nova.com","address":{"zip":"DE","street":"Musterstr","house_no":"2","country_code":"DE","company":"ABC GmbH","city":"Musterhausen"},"account_holder":"Sample Acc"}}';
String PaymentAccesskey = 'YTg3ZmY2NzlhMmYzZTcxZDkxODFhfgsdg4retget34trtrfdgdNjdiNzU0MjEyMmM=';
Account account = new Account( Name = 'Max' );
ServerCallouts.getCalloutData(requestData, PaymentAccesskey);
System.assertEquals(account.Name, 'Max');
}
}
trigger GenerateAffiliate on Account (before insert)
{
for(Account account: Trigger.new)
{
if(Trigger.isInsert)
{
String jsonString,paymentAccessKey;
if (account != null)
{
String[] allowedAccountType = new String[] { 'Craftsman' };
String selectedRecType = account.RecordType.Name;
if (allowedAccountType.contains(selectedRecType) == true)
{
List<Novalnet_Global_Configuration__c> novalnetConfigList = [Select Id,Product_Activation_Key__c,Payment_Access_Key__c from Novalnet_Global_Configuration__c where Account_Record_Type__c =: selectedRecType];
if (novalnetConfigList.isEmpty() == false)
{
Novalnet_Global_Configuration__c novalnetConfig = novalnetConfigList[0];
paymentAccessKey = novalnetConfig.Payment_Access_Key__c;
Map<String, Object> merchant = new Map<String, Object>();
merchant.put('signature', novalnetConfig.Product_Activation_Key__c);
Map<String, Object> address = new Map<String, Object>();
address.put('street', account.BillingStreet);
address.put('city', account.BillingCity);
address.put('zip', account.BillingPostalCode);
address.put('country_code', account.BillingCountry);
Map<String, Object> affiliate = new Map<String, Object>();
affiliate.put('first_name', account.Name);
affiliate.put('last_name', account.Name);
affiliate.put('email', account.Email__c);
affiliate.put('customer_no', account.Website);
affiliate.put('tel', account.Phone);
affiliate.put('account_holder', account.Name);
affiliate.put('iban', account.IBAN__c);
affiliate.put('address', address);
String language = UserInfo.getLanguage();
String[] languageAry = language.split('_');
Map<String, Object> custom = new Map<String, Object>();
custom.put('lang', languageAry[0].toUppercase());
Map<String, Object> requestData = new Map<String, Object>();
requestData.put('merchant', merchant);
requestData.put('affiliate', affiliate);
requestData.put('custom', custom);
List <String> result = getValidatedRequest(requestData);
jsonString = result[0];
System.debug('Result List 0:: '+result[0]);
System.debug('Result List 1::' +result[1]);
if(result[1] == '')
{
if(Trigger.isInsert) //Testclass
{
// ServerCallouts.getCalloutData(jsonString, paymentAccessKey);
}
//Servercallouts.getCalloutData(jsonString, paymentAccessKey);
System.debug('Server Callout');
}
else
{
account.addError('ErrorMessage ::: '+result[1]);
}
}
}
}
}
}
public static List<String> getValidatedRequest(Map<String, Object> requestData)
{
String[] mandatoryParams = new String []{'signature', 'first_name', 'last_name', 'email', 'street', 'city', 'zip', 'country_code'};
String errorMsg = '';
List<String> result = new List<String>();
//return result;
for(String category : requestData.KeySet())
{
Map<String, Object> requestDataObj = (Map<String, Object>)requestData.get(String.valueOf(category));
for(Object categoryKey : requestDataObj.KeySet())
{
if(categoryKey == 'address')
{
Map<String, Object> subCategory = (Map<String, Object>) requestDataObj.get(String.valueOf(categoryKey));
for(Object subCategoryKey : subCategory.KeySet()) {
Map<String, Object> subCategoryParam = (Map<String, Object>) requestDataObj.get(String.valueOf(categoryKey));
string paramValue = String.valueOf(subCategoryParam.get(String.valueOf(subCategoryKey)));
if(paramValue == '' || paramValue == null)
{
if(mandatoryParams.contains(String.valueOf(subCategoryKey)))
{
errorMsg = 'Required parameter - ' + subCategoryKey + ' in the category ' + categoryKey + ' not received. ' +'\n';
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
subCategory.remove(String.valueOf(subCategoryKey));
}
requestDataObj.put(String.valueOf(categoryKey), subCategory);
}
}
else
{
string paramValue = String.valueOf(requestDataObj.get(String.valueOf(categoryKey)));
if(paramValue == '' || paramValue == null)
{
if(mandatoryParams.contains(String.valueOf(categoryKey)))
{
errorMsg = 'Required parameter - ' + categoryKey + ' in the category ' + category + ' not received. ' +'\n';
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
requestDataObj.remove(String.valueOf(categoryKey));
}
}
}
requestData.put(category, requestDataObj);
}
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
}
Test Class:
@isTest
private class AccountTriggerTest
{
@isTest
static void AccountTrigger()
{
Account acc = new Account(Name = 'Max', RecordTypeId = '0125g000000AMDLAA4',BillingStreet = 'Musterstr', BillingCity = 'Jaipur', BillingState = 'Raj', BillingPostalCode = '12345', BillingCountry = 'DE', Phone = '+49 089 123456', Fax = '+49 089 123456', Website = 'info@nova.com', Email__c = 'test@nova.com', IBAN__c = 'DE24300225090024114523523761956');
Insert acc;
acc = [select Id, Name,BillingStreet,BillingCity,Email__c,IBAN__c from Account where Id = :acc.Id];
String requestData = '{"merchant":{"signature":"7ibc7ob5|tu3454363345345674JEH3gNbeWJfIHah||567856|doU3HJVoyfsggm7MQ44qf7cpn7pc"},"customer":{"lang":"EN"},"affiliate":{"vat_id":"DE123453456","tel":"98744564563210","reference":"affiliateXXX","password":"Nova123123","mobile":"9874563210","login":"Nova","last_name":"Sample Acc","iban":null,"gender":"Female","first_name":"Sample Acc","fax":"+41054879","email":"test@nova.com","company_email":"info@nova.com","address":{"zip":"DE","street":"Musterstr","house_no":"2","country_code":"DE","company":"ABC GmbH","city":"Musterhausen"},"account_holder":"Sample Acc"}}';
String PaymentAccesskey = 'YTg3ZmY2NzlhMmYzZTcxZDkxODFhfgsdg4retget34trtrfdgdNjdiNzU0MjEyMmM=';
Account account = new Account( Name = 'Max' );
ServerCallouts.getCalloutData(requestData, PaymentAccesskey);
System.assertEquals(account.Name, 'Max');
}
}
- Poorna Priya 16
- August 15, 2021
- Like
- 0
Error in Test class while fetch data from flow
Hi Everyone,
MyClass:
public with sharing class AffiliateCreation
{
@InvocableMethod(callout=true label='accountCreates' description='Get Craft account data when it creates')
public static void getAccount(getAccountdata[] requests)
{
String jsonString;
String accountID = requests[0].recId;
String Payment_key;
String language = UserInfo.getLanguage();
Account acc = new Account();
List <Account> Req_accounts = [SELECT Id,Name,RecordType.Name,BillingCity,BillingStreet,BillingCountry,BillingState,BillingPostalCode,Email__c,Fax,Phone,Website,IBAN__c FROM Account WHERE Id = :accountID];
// List <Account> Req_accounts = [SELECT Id,Name,RecordType.Name,BillingCity,BillingStreet,BillingCountry,BillingState,BillingPostalCode,Email__c,Fax,Phone,Website,IBAN__c FROM Account WHERE Id = :accountID];
System.debug('List Account::: '+Req_accounts);
Merchant merch = new Merchant();
Custom cu = new Custom();
Affiliate aff = new Affiliate();
RootObject objJSONRoot = new RootObject();
Address address = new Address();
if(Req_accounts.isEmpty() == false )
{
System.debug('List Account::: '+Req_accounts);
Account account = Req_accounts[0];
String jsonBody = JSON.serialize(account,true);
String AccRecType = account.RecordType.Name;
system.debug('AccRecType' + AccRecType);
//Get selected picklist value from NN Config object
Schema.DescribeFieldResult getSelectvalue = Global_Configuration__c.Account_Record_Type__c.getDescribe();
List<Schema.PicklistEntry> selectedValue = getSelectvalue.getPicklistValues();
List<Schema.PicklistEntry> activeEntries = new List<Schema.PicklistEntry>();
for (Schema.PicklistEntry entry : selectedValue)
{
if (entry.getValue() == 'Craft')
{
String NNval = entry.getValue();
system.debug('Selected pick value:::: ' + AccRecType);
if(AccRecType == NNval)
{
System.debug('Both Account Record Types are same::::');
List<Global_Configuration__c> NNGconfig = [Select Id,Product_Activation_Key__c,Payment_Access_Key__c from Global_Configuration__c where Account_Record_Type__c =: AccRecType];
if (NNGconfig.isEmpty() == false)
{
Global_Configuration__c NNcon = NNGconfig[0];
String Pro_key = NNcon.Product_Activation_Key__c;
System.debug('Product key from Config object ::::: '+Pro_key);
//Merchant merch = new Merchant();
merch.signature = NNcon.Product_Activation_Key__c;
Payment_key = NNcon.Payment_Access_Key__c;
cu.lang = language;
aff.first_name = account.Name;
aff.last_name = account.Name;
aff.email = account.Email__c;
aff.company_email =account.Website;
aff.tel = account.Phone;
aff.mobile = account.Phone;
aff.fax = account.Fax;
aff.account_holder = account.Name;
aff.iban = account.IBAN__c;
address.house_no = account.BillingStreet;
address.street =account.BillingStreet;
address.city = account.BillingCity;
address.zip = account.BillingPostalCode;
address.country_code = account.BillingCountry;
objJSONRoot.merchant = merch;
objJSONRoot.affiliate = aff;
objJSONRoot.affiliate.address = address;
objJSONRoot.customer = cu;
jsonString = JSON.Serialize(objJSONRoot,true);
System.debug(jsonString);
}
}
}
}
}
String mandatoryParameters = '{"merchant":["signature"], "affiliate":["first_name", "last_name", "email"], "address":["street","city","zip","country_code"]}';
Map<String, Object> mapOfmandatoryParameters = (Map<String, Object>) JSON.deserializeUntyped(mandatoryParameters);
Map<String, Object> requestData = (Map<String, Object>) JSON.deserializeUntyped(jsonString);
for (String category : mapOfmandatoryParameters.KeySet()) {
if(category != 'address')
{
if(!requestData.KeySet().contains(category))
{
system.debug('Required parameter category(' + category + ') not received');
//acc.addError('error:::: Required parameter category(' + category + ') not received');
}
}
String subCategory = category;
if(category == 'address') {
category = 'affiliate';
subCategory = 'address';
}
Map<String, Object> mapOfjsonResponse = (Map<String, Object>) (requestData.get(category));
List<Object> mapOfmandatoryParamObject = (List<Object>) mapOfmandatoryParameters.get(subCategory);
for(Object parameters:mapOfmandatoryParamObject)
{
String parameter = parameters.toString();
if(subCategory == 'address')
{
Map<String, Object> subCategoryMapResponse = (Map<String, Object>) mapOfjsonResponse.get(subCategory);
Object parameterValue = subCategoryMapResponse.get(parameter);
if(parameterValue == null || parameterValue == '')
{
system.debug('Required parameter (' + parameter + ') in the category (' + category + ') not received');
// acc.addError('Required parameter (' + parameter + ') in the category (' + category + ') not received');
}
}
else
{
Object parameterValue1 = mapOfjsonResponse.get(parameter);
if(parameterValue1 == null || parameterValue1 == '')
{
system.debug('Required parameter (' + parameter + ') in the category (' + category + ') not received');
}
}
}
}
System.enqueueJob(new ServerCallouts(accountID,jsonString,Payment_key));
}
public class RootObject
{
public Merchant merchant { get; set;}
public Affiliate affiliate {get;set;}
public Custom customer {get;set;}
}
public class Merchant {
public String signature {get;set;}
}
public class Address {
public String company {get;set;}
public String house_no {get;set;}
public String street {get;set;}
public String city {get;set;}
public String zip {get;set;}
public String country_code {get;set;}
}
public class Custom {
public String lang {get;set;}
}
public class Affiliate
{
public String login {get;set;}
public String password {get;set;}
public String reference {get;set;}
public String gender {get;set;}
public String first_name {get;set;}
public String last_name {get;set;}
public String email {get;set;}
public String company_email {get;set;}
public Address address {get;set;}
public String tel {get;set;}
public String mobile {get;set;}
public String fax {get;set;}
public String vat_id {get;set;}
public String account_holder {get;set;}
public String iban {get;set;}
}
public class getAccountdata
{
@InvocableVariable(required=true)
public String recId;
}
}
MyTestClass:
@isTest
private class AffiliateCreationTest{
@testSetup
static void setupTestData(){
test.startTest();
Account account_Obj = new Account(Name = 'Name643', BillingStreet = 'PratapNagar', BillingCity = 'Jaipur', BillingState = 'Raj', BillingPostalCode = '302022', BillingCountry = 'India', Phone = '54343-16298', Fax = '54343-42493', Website = 'http://test29.com', novalnetpayment__Email__c = 'Email68@test.com', novalnetpayment__IBAN__c = 'noval383');
Insert account_Obj;
test.stopTest();
}
static testMethod void test_getAccount_UseCase1(){
List<Account> account_Obj = [SELECT Id,Name,BillingStreet,BillingCity,BillingState,BillingPostalCode,BillingCountry,Phone,Fax,Website,Email__c,IBAN__c from Account];
System.assertEquals(true,account_Obj.size()>0);
AffiliateCreation obj01 = new AffiliateCreation();
AffiliateCreation.getAccount(new List<getAccountdata>());
}
static testMethod void test_getAccount_UseCase2(){
List<Account> account_Obj = [SELECT Id,Name,BillingStreet,BillingCity,BillingState,BillingPostalCode,BillingCountry,Phone,Fax,Website,Email__c,IBAN__c from Account];
System.assertEquals(true,account_Obj.size()>0);
AffiliateCreation obj01 = new AffiliateCreation();
AffiliateCreation.RootObject obj21 = new AffiliateCreation.RootObject();
obj21.merchant = new AffiliateCreation.Merchant();
obj21.affiliate = new AffiliateCreation.Affiliate();
obj21.customer = new AffiliateCreation.Custom();
AffiliateCreation.Merchant obj61 = new AffiliateCreation.Merchant();
obj61.signature = 'test data';
AffiliateCreation.Address obj81 = new AffiliateCreation.Address();
obj81.company = 'test data';
obj81.house_no = 'test data';
obj81.street = 'test data';
obj81.city = 'test data';
obj81.zip = 'test data';
obj81.country_code = 'test data';
AffiliateCreation.Custom obj151 = new AffiliateCreation.Custom();
obj151.lang = 'test data';
AffiliateCreation.Affiliate obj171 = new AffiliateCreation.Affiliate();
obj171.login = 'test data';
obj171.password = 'test data';
obj171.reference = 'test data';
obj171.gender = 'test data';
obj171.first_name = 'test data';
obj171.last_name = 'test data';
obj171.email = 'test data';
obj171.company_email = 'test data';
obj171.address = new AffiliateCreation.Address();
obj171.tel = 'test data';
obj171.mobile = 'test data';
obj171.fax = 'test data';
obj171.vat_id = 'test data';
obj171.account_holder = 'test data';
Affiliate.getAccount();
}
static testMethod void test_getAccount_UseCase3(){
List<Account> account_Obj = [SELECT Id,Name,BillingStreet,BillingCity,BillingState,BillingPostalCode,BillingCountry,Phone,Fax,Website,Email__c,IBAN__c from Account];
System.assertEquals(true,account_Obj.size()>0);
AffiliateCreation obj01 = new AffiliateCreation();
AffiliateCreation.RootObject obj21 = new AffiliateCreation.RootObject();
obj21.merchant = new AffiliateCreation.Merchant();
obj21.affiliate = new AffiliateCreation.Affiliate();
obj21.customer = new AffiliateCreation.Custom();
AffiliateCreation.Merchant obj61 = new AffiliateCreation.Merchant();
obj61.signature = 'test data';
AffiliateCreation.Address obj81 = new AffiliateCreation.Address();
obj81.company = 'test data';
obj81.house_no = 'test data';
obj81.street = 'test data';
obj81.city = 'test data';
obj81.zip = 'test data';
obj81.country_code = 'test data';
AffiliateCreation.Custom obj151 = new AffiliateCreation.Custom();
obj151.lang = 'test data';
AffiliateCreation.Affiliate obj171 = new AffiliateCreation.Affiliate();
obj171.login = 'test data';
obj171.password = 'test data';
obj171.reference = 'test data';
obj171.gender = 'test data';
obj171.first_name = 'test data';
obj171.last_name = 'test data';
obj171.email = 'test data';
obj171.company_email = 'test data';
obj171.address = new AffiliateCreation.Address();
obj171.tel = 'test data';
obj171.mobile = 'test data';
obj171.fax = 'test data';
obj171.vat_id = 'test data';
obj171.account_holder = 'test data';
AffiliateCreation.getAccountdata obj341 = new AffiliateCreation.getAccountdata();
getAccountdata.getAccount();
}
}
Error:
Thanks in Advance.
MyClass:
public with sharing class AffiliateCreation
{
@InvocableMethod(callout=true label='accountCreates' description='Get Craft account data when it creates')
public static void getAccount(getAccountdata[] requests)
{
String jsonString;
String accountID = requests[0].recId;
String Payment_key;
String language = UserInfo.getLanguage();
Account acc = new Account();
List <Account> Req_accounts = [SELECT Id,Name,RecordType.Name,BillingCity,BillingStreet,BillingCountry,BillingState,BillingPostalCode,Email__c,Fax,Phone,Website,IBAN__c FROM Account WHERE Id = :accountID];
// List <Account> Req_accounts = [SELECT Id,Name,RecordType.Name,BillingCity,BillingStreet,BillingCountry,BillingState,BillingPostalCode,Email__c,Fax,Phone,Website,IBAN__c FROM Account WHERE Id = :accountID];
System.debug('List Account::: '+Req_accounts);
Merchant merch = new Merchant();
Custom cu = new Custom();
Affiliate aff = new Affiliate();
RootObject objJSONRoot = new RootObject();
Address address = new Address();
if(Req_accounts.isEmpty() == false )
{
System.debug('List Account::: '+Req_accounts);
Account account = Req_accounts[0];
String jsonBody = JSON.serialize(account,true);
String AccRecType = account.RecordType.Name;
system.debug('AccRecType' + AccRecType);
//Get selected picklist value from NN Config object
Schema.DescribeFieldResult getSelectvalue = Global_Configuration__c.Account_Record_Type__c.getDescribe();
List<Schema.PicklistEntry> selectedValue = getSelectvalue.getPicklistValues();
List<Schema.PicklistEntry> activeEntries = new List<Schema.PicklistEntry>();
for (Schema.PicklistEntry entry : selectedValue)
{
if (entry.getValue() == 'Craft')
{
String NNval = entry.getValue();
system.debug('Selected pick value:::: ' + AccRecType);
if(AccRecType == NNval)
{
System.debug('Both Account Record Types are same::::');
List<Global_Configuration__c> NNGconfig = [Select Id,Product_Activation_Key__c,Payment_Access_Key__c from Global_Configuration__c where Account_Record_Type__c =: AccRecType];
if (NNGconfig.isEmpty() == false)
{
Global_Configuration__c NNcon = NNGconfig[0];
String Pro_key = NNcon.Product_Activation_Key__c;
System.debug('Product key from Config object ::::: '+Pro_key);
//Merchant merch = new Merchant();
merch.signature = NNcon.Product_Activation_Key__c;
Payment_key = NNcon.Payment_Access_Key__c;
cu.lang = language;
aff.first_name = account.Name;
aff.last_name = account.Name;
aff.email = account.Email__c;
aff.company_email =account.Website;
aff.tel = account.Phone;
aff.mobile = account.Phone;
aff.fax = account.Fax;
aff.account_holder = account.Name;
aff.iban = account.IBAN__c;
address.house_no = account.BillingStreet;
address.street =account.BillingStreet;
address.city = account.BillingCity;
address.zip = account.BillingPostalCode;
address.country_code = account.BillingCountry;
objJSONRoot.merchant = merch;
objJSONRoot.affiliate = aff;
objJSONRoot.affiliate.address = address;
objJSONRoot.customer = cu;
jsonString = JSON.Serialize(objJSONRoot,true);
System.debug(jsonString);
}
}
}
}
}
String mandatoryParameters = '{"merchant":["signature"], "affiliate":["first_name", "last_name", "email"], "address":["street","city","zip","country_code"]}';
Map<String, Object> mapOfmandatoryParameters = (Map<String, Object>) JSON.deserializeUntyped(mandatoryParameters);
Map<String, Object> requestData = (Map<String, Object>) JSON.deserializeUntyped(jsonString);
for (String category : mapOfmandatoryParameters.KeySet()) {
if(category != 'address')
{
if(!requestData.KeySet().contains(category))
{
system.debug('Required parameter category(' + category + ') not received');
//acc.addError('error:::: Required parameter category(' + category + ') not received');
}
}
String subCategory = category;
if(category == 'address') {
category = 'affiliate';
subCategory = 'address';
}
Map<String, Object> mapOfjsonResponse = (Map<String, Object>) (requestData.get(category));
List<Object> mapOfmandatoryParamObject = (List<Object>) mapOfmandatoryParameters.get(subCategory);
for(Object parameters:mapOfmandatoryParamObject)
{
String parameter = parameters.toString();
if(subCategory == 'address')
{
Map<String, Object> subCategoryMapResponse = (Map<String, Object>) mapOfjsonResponse.get(subCategory);
Object parameterValue = subCategoryMapResponse.get(parameter);
if(parameterValue == null || parameterValue == '')
{
system.debug('Required parameter (' + parameter + ') in the category (' + category + ') not received');
// acc.addError('Required parameter (' + parameter + ') in the category (' + category + ') not received');
}
}
else
{
Object parameterValue1 = mapOfjsonResponse.get(parameter);
if(parameterValue1 == null || parameterValue1 == '')
{
system.debug('Required parameter (' + parameter + ') in the category (' + category + ') not received');
}
}
}
}
System.enqueueJob(new ServerCallouts(accountID,jsonString,Payment_key));
}
public class RootObject
{
public Merchant merchant { get; set;}
public Affiliate affiliate {get;set;}
public Custom customer {get;set;}
}
public class Merchant {
public String signature {get;set;}
}
public class Address {
public String company {get;set;}
public String house_no {get;set;}
public String street {get;set;}
public String city {get;set;}
public String zip {get;set;}
public String country_code {get;set;}
}
public class Custom {
public String lang {get;set;}
}
public class Affiliate
{
public String login {get;set;}
public String password {get;set;}
public String reference {get;set;}
public String gender {get;set;}
public String first_name {get;set;}
public String last_name {get;set;}
public String email {get;set;}
public String company_email {get;set;}
public Address address {get;set;}
public String tel {get;set;}
public String mobile {get;set;}
public String fax {get;set;}
public String vat_id {get;set;}
public String account_holder {get;set;}
public String iban {get;set;}
}
public class getAccountdata
{
@InvocableVariable(required=true)
public String recId;
}
}
MyTestClass:
@isTest
private class AffiliateCreationTest{
@testSetup
static void setupTestData(){
test.startTest();
Account account_Obj = new Account(Name = 'Name643', BillingStreet = 'PratapNagar', BillingCity = 'Jaipur', BillingState = 'Raj', BillingPostalCode = '302022', BillingCountry = 'India', Phone = '54343-16298', Fax = '54343-42493', Website = 'http://test29.com', novalnetpayment__Email__c = 'Email68@test.com', novalnetpayment__IBAN__c = 'noval383');
Insert account_Obj;
test.stopTest();
}
static testMethod void test_getAccount_UseCase1(){
List<Account> account_Obj = [SELECT Id,Name,BillingStreet,BillingCity,BillingState,BillingPostalCode,BillingCountry,Phone,Fax,Website,Email__c,IBAN__c from Account];
System.assertEquals(true,account_Obj.size()>0);
AffiliateCreation obj01 = new AffiliateCreation();
AffiliateCreation.getAccount(new List<getAccountdata>());
}
static testMethod void test_getAccount_UseCase2(){
List<Account> account_Obj = [SELECT Id,Name,BillingStreet,BillingCity,BillingState,BillingPostalCode,BillingCountry,Phone,Fax,Website,Email__c,IBAN__c from Account];
System.assertEquals(true,account_Obj.size()>0);
AffiliateCreation obj01 = new AffiliateCreation();
AffiliateCreation.RootObject obj21 = new AffiliateCreation.RootObject();
obj21.merchant = new AffiliateCreation.Merchant();
obj21.affiliate = new AffiliateCreation.Affiliate();
obj21.customer = new AffiliateCreation.Custom();
AffiliateCreation.Merchant obj61 = new AffiliateCreation.Merchant();
obj61.signature = 'test data';
AffiliateCreation.Address obj81 = new AffiliateCreation.Address();
obj81.company = 'test data';
obj81.house_no = 'test data';
obj81.street = 'test data';
obj81.city = 'test data';
obj81.zip = 'test data';
obj81.country_code = 'test data';
AffiliateCreation.Custom obj151 = new AffiliateCreation.Custom();
obj151.lang = 'test data';
AffiliateCreation.Affiliate obj171 = new AffiliateCreation.Affiliate();
obj171.login = 'test data';
obj171.password = 'test data';
obj171.reference = 'test data';
obj171.gender = 'test data';
obj171.first_name = 'test data';
obj171.last_name = 'test data';
obj171.email = 'test data';
obj171.company_email = 'test data';
obj171.address = new AffiliateCreation.Address();
obj171.tel = 'test data';
obj171.mobile = 'test data';
obj171.fax = 'test data';
obj171.vat_id = 'test data';
obj171.account_holder = 'test data';
Affiliate.getAccount();
}
static testMethod void test_getAccount_UseCase3(){
List<Account> account_Obj = [SELECT Id,Name,BillingStreet,BillingCity,BillingState,BillingPostalCode,BillingCountry,Phone,Fax,Website,Email__c,IBAN__c from Account];
System.assertEquals(true,account_Obj.size()>0);
AffiliateCreation obj01 = new AffiliateCreation();
AffiliateCreation.RootObject obj21 = new AffiliateCreation.RootObject();
obj21.merchant = new AffiliateCreation.Merchant();
obj21.affiliate = new AffiliateCreation.Affiliate();
obj21.customer = new AffiliateCreation.Custom();
AffiliateCreation.Merchant obj61 = new AffiliateCreation.Merchant();
obj61.signature = 'test data';
AffiliateCreation.Address obj81 = new AffiliateCreation.Address();
obj81.company = 'test data';
obj81.house_no = 'test data';
obj81.street = 'test data';
obj81.city = 'test data';
obj81.zip = 'test data';
obj81.country_code = 'test data';
AffiliateCreation.Custom obj151 = new AffiliateCreation.Custom();
obj151.lang = 'test data';
AffiliateCreation.Affiliate obj171 = new AffiliateCreation.Affiliate();
obj171.login = 'test data';
obj171.password = 'test data';
obj171.reference = 'test data';
obj171.gender = 'test data';
obj171.first_name = 'test data';
obj171.last_name = 'test data';
obj171.email = 'test data';
obj171.company_email = 'test data';
obj171.address = new AffiliateCreation.Address();
obj171.tel = 'test data';
obj171.mobile = 'test data';
obj171.fax = 'test data';
obj171.vat_id = 'test data';
obj171.account_holder = 'test data';
AffiliateCreation.getAccountdata obj341 = new AffiliateCreation.getAccountdata();
getAccountdata.getAccount();
}
}
Error:
Thanks in Advance.
- Poorna Priya 16
- August 11, 2021
- Like
- 0
Trigger to Fields Auto populate
I have Custom object named Team__c and Fields are like, Category__c(Picklist), Close_Date__c(Date), Stage__c(Picklist) also have Standard Opportunity object. The Team__c object and Opportunity has look-up relationship with Category__c(Picklist), Close_Date__c(Date), Stage__c(Picklist) fields . In opportunity I have custom field named Type__c(Picklist), whenever the Type__c from Opportunity is equal to 'New Team' (Type__c == 'New Team') the Category__c, Close_Date__c, Stage__c fields should populate in Team__c record while it create. Can anyone help on this? Thanks in advance. I have try with following trigger,
if(trigger.isAfter && trigger.isInsert) { List<Team__c> tt = new List<Team__c>(); Opportunity opp = new Opportunity(); if(opp.Type__c == 'New Team') { for(Opportunity oppty : trigger.new) { Team__c team = new Team__c(); team.Category__c = oppty.Category__c; team.Close_Date__c = oppty.Close_Date__c; team.Stage__c = oppty.Stage__c; tt.add(team); } } }
- Poorna Priya 16
- October 27, 2022
- Like
- 0
Need test class with 75% code coverage
Trigger:
trigger GenerateAffiliate on Account (before insert)
{
for(Account account: Trigger.new)
{
if(Trigger.isInsert)
{
String jsonString,paymentAccessKey;
if (account != null)
{
String[] allowedAccountType = new String[] { 'Craftsman' };
String selectedRecType = account.RecordType.Name;
if (allowedAccountType.contains(selectedRecType) == true)
{
List<Novalnet_Global_Configuration__c> novalnetConfigList = [Select Id,Product_Activation_Key__c,Payment_Access_Key__c from Novalnet_Global_Configuration__c where Account_Record_Type__c =: selectedRecType];
if (novalnetConfigList.isEmpty() == false)
{
Novalnet_Global_Configuration__c novalnetConfig = novalnetConfigList[0];
paymentAccessKey = novalnetConfig.Payment_Access_Key__c;
Map<String, Object> merchant = new Map<String, Object>();
merchant.put('signature', novalnetConfig.Product_Activation_Key__c);
Map<String, Object> address = new Map<String, Object>();
address.put('street', account.BillingStreet);
address.put('city', account.BillingCity);
address.put('zip', account.BillingPostalCode);
address.put('country_code', account.BillingCountry);
Map<String, Object> affiliate = new Map<String, Object>();
affiliate.put('first_name', account.Name);
affiliate.put('last_name', account.Name);
affiliate.put('email', account.Email__c);
affiliate.put('customer_no', account.Website);
affiliate.put('tel', account.Phone);
affiliate.put('account_holder', account.Name);
affiliate.put('iban', account.IBAN__c);
affiliate.put('address', address);
String language = UserInfo.getLanguage();
String[] languageAry = language.split('_');
Map<String, Object> custom = new Map<String, Object>();
custom.put('lang', languageAry[0].toUppercase());
Map<String, Object> requestData = new Map<String, Object>();
requestData.put('merchant', merchant);
requestData.put('affiliate', affiliate);
requestData.put('custom', custom);
List <String> result = getValidatedRequest(requestData);
jsonString = result[0];
System.debug('Result List 0:: '+result[0]);
System.debug('Result List 1::' +result[1]);
if(result[1] == '')
{
if(Trigger.isInsert) //Testclass
{
// ServerCallouts.getCalloutData(jsonString, paymentAccessKey);
}
//Servercallouts.getCalloutData(jsonString, paymentAccessKey);
System.debug('Server Callout');
}
else
{
account.addError('ErrorMessage ::: '+result[1]);
}
}
}
}
}
}
public static List<String> getValidatedRequest(Map<String, Object> requestData)
{
String[] mandatoryParams = new String []{'signature', 'first_name', 'last_name', 'email', 'street', 'city', 'zip', 'country_code'};
String errorMsg = '';
List<String> result = new List<String>();
//return result;
for(String category : requestData.KeySet())
{
Map<String, Object> requestDataObj = (Map<String, Object>)requestData.get(String.valueOf(category));
for(Object categoryKey : requestDataObj.KeySet())
{
if(categoryKey == 'address')
{
Map<String, Object> subCategory = (Map<String, Object>) requestDataObj.get(String.valueOf(categoryKey));
for(Object subCategoryKey : subCategory.KeySet()) {
Map<String, Object> subCategoryParam = (Map<String, Object>) requestDataObj.get(String.valueOf(categoryKey));
string paramValue = String.valueOf(subCategoryParam.get(String.valueOf(subCategoryKey)));
if(paramValue == '' || paramValue == null)
{
if(mandatoryParams.contains(String.valueOf(subCategoryKey)))
{
errorMsg = 'Required parameter - ' + subCategoryKey + ' in the category ' + categoryKey + ' not received. ' +'\n';
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
subCategory.remove(String.valueOf(subCategoryKey));
}
requestDataObj.put(String.valueOf(categoryKey), subCategory);
}
}
else
{
string paramValue = String.valueOf(requestDataObj.get(String.valueOf(categoryKey)));
if(paramValue == '' || paramValue == null)
{
if(mandatoryParams.contains(String.valueOf(categoryKey)))
{
errorMsg = 'Required parameter - ' + categoryKey + ' in the category ' + category + ' not received. ' +'\n';
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
requestDataObj.remove(String.valueOf(categoryKey));
}
}
}
requestData.put(category, requestDataObj);
}
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
}
Test Class:
@isTest
private class AccountTriggerTest
{
@isTest
static void AccountTrigger()
{
Account acc = new Account(Name = 'Max', RecordTypeId = '0125g000000AMDLAA4',BillingStreet = 'Musterstr', BillingCity = 'Jaipur', BillingState = 'Raj', BillingPostalCode = '12345', BillingCountry = 'DE', Phone = '+49 089 123456', Fax = '+49 089 123456', Website = 'info@nova.com', Email__c = 'test@nova.com', IBAN__c = 'DE24300225090024114523523761956');
Insert acc;
acc = [select Id, Name,BillingStreet,BillingCity,Email__c,IBAN__c from Account where Id = :acc.Id];
String requestData = '{"merchant":{"signature":"7ibc7ob5|tu3454363345345674JEH3gNbeWJfIHah||567856|doU3HJVoyfsggm7MQ44qf7cpn7pc"},"customer":{"lang":"EN"},"affiliate":{"vat_id":"DE123453456","tel":"98744564563210","reference":"affiliateXXX","password":"Nova123123","mobile":"9874563210","login":"Nova","last_name":"Sample Acc","iban":null,"gender":"Female","first_name":"Sample Acc","fax":"+41054879","email":"test@nova.com","company_email":"info@nova.com","address":{"zip":"DE","street":"Musterstr","house_no":"2","country_code":"DE","company":"ABC GmbH","city":"Musterhausen"},"account_holder":"Sample Acc"}}';
String PaymentAccesskey = 'YTg3ZmY2NzlhMmYzZTcxZDkxODFhfgsdg4retget34trtrfdgdNjdiNzU0MjEyMmM=';
Account account = new Account( Name = 'Max' );
ServerCallouts.getCalloutData(requestData, PaymentAccesskey);
System.assertEquals(account.Name, 'Max');
}
}
trigger GenerateAffiliate on Account (before insert)
{
for(Account account: Trigger.new)
{
if(Trigger.isInsert)
{
String jsonString,paymentAccessKey;
if (account != null)
{
String[] allowedAccountType = new String[] { 'Craftsman' };
String selectedRecType = account.RecordType.Name;
if (allowedAccountType.contains(selectedRecType) == true)
{
List<Novalnet_Global_Configuration__c> novalnetConfigList = [Select Id,Product_Activation_Key__c,Payment_Access_Key__c from Novalnet_Global_Configuration__c where Account_Record_Type__c =: selectedRecType];
if (novalnetConfigList.isEmpty() == false)
{
Novalnet_Global_Configuration__c novalnetConfig = novalnetConfigList[0];
paymentAccessKey = novalnetConfig.Payment_Access_Key__c;
Map<String, Object> merchant = new Map<String, Object>();
merchant.put('signature', novalnetConfig.Product_Activation_Key__c);
Map<String, Object> address = new Map<String, Object>();
address.put('street', account.BillingStreet);
address.put('city', account.BillingCity);
address.put('zip', account.BillingPostalCode);
address.put('country_code', account.BillingCountry);
Map<String, Object> affiliate = new Map<String, Object>();
affiliate.put('first_name', account.Name);
affiliate.put('last_name', account.Name);
affiliate.put('email', account.Email__c);
affiliate.put('customer_no', account.Website);
affiliate.put('tel', account.Phone);
affiliate.put('account_holder', account.Name);
affiliate.put('iban', account.IBAN__c);
affiliate.put('address', address);
String language = UserInfo.getLanguage();
String[] languageAry = language.split('_');
Map<String, Object> custom = new Map<String, Object>();
custom.put('lang', languageAry[0].toUppercase());
Map<String, Object> requestData = new Map<String, Object>();
requestData.put('merchant', merchant);
requestData.put('affiliate', affiliate);
requestData.put('custom', custom);
List <String> result = getValidatedRequest(requestData);
jsonString = result[0];
System.debug('Result List 0:: '+result[0]);
System.debug('Result List 1::' +result[1]);
if(result[1] == '')
{
if(Trigger.isInsert) //Testclass
{
// ServerCallouts.getCalloutData(jsonString, paymentAccessKey);
}
//Servercallouts.getCalloutData(jsonString, paymentAccessKey);
System.debug('Server Callout');
}
else
{
account.addError('ErrorMessage ::: '+result[1]);
}
}
}
}
}
}
public static List<String> getValidatedRequest(Map<String, Object> requestData)
{
String[] mandatoryParams = new String []{'signature', 'first_name', 'last_name', 'email', 'street', 'city', 'zip', 'country_code'};
String errorMsg = '';
List<String> result = new List<String>();
//return result;
for(String category : requestData.KeySet())
{
Map<String, Object> requestDataObj = (Map<String, Object>)requestData.get(String.valueOf(category));
for(Object categoryKey : requestDataObj.KeySet())
{
if(categoryKey == 'address')
{
Map<String, Object> subCategory = (Map<String, Object>) requestDataObj.get(String.valueOf(categoryKey));
for(Object subCategoryKey : subCategory.KeySet()) {
Map<String, Object> subCategoryParam = (Map<String, Object>) requestDataObj.get(String.valueOf(categoryKey));
string paramValue = String.valueOf(subCategoryParam.get(String.valueOf(subCategoryKey)));
if(paramValue == '' || paramValue == null)
{
if(mandatoryParams.contains(String.valueOf(subCategoryKey)))
{
errorMsg = 'Required parameter - ' + subCategoryKey + ' in the category ' + categoryKey + ' not received. ' +'\n';
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
subCategory.remove(String.valueOf(subCategoryKey));
}
requestDataObj.put(String.valueOf(categoryKey), subCategory);
}
}
else
{
string paramValue = String.valueOf(requestDataObj.get(String.valueOf(categoryKey)));
if(paramValue == '' || paramValue == null)
{
if(mandatoryParams.contains(String.valueOf(categoryKey)))
{
errorMsg = 'Required parameter - ' + categoryKey + ' in the category ' + category + ' not received. ' +'\n';
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
requestDataObj.remove(String.valueOf(categoryKey));
}
}
}
requestData.put(category, requestDataObj);
}
result.add(JSON.Serialize(requestData,true));
result.add(errorMsg);
return result;
}
}
Test Class:
@isTest
private class AccountTriggerTest
{
@isTest
static void AccountTrigger()
{
Account acc = new Account(Name = 'Max', RecordTypeId = '0125g000000AMDLAA4',BillingStreet = 'Musterstr', BillingCity = 'Jaipur', BillingState = 'Raj', BillingPostalCode = '12345', BillingCountry = 'DE', Phone = '+49 089 123456', Fax = '+49 089 123456', Website = 'info@nova.com', Email__c = 'test@nova.com', IBAN__c = 'DE24300225090024114523523761956');
Insert acc;
acc = [select Id, Name,BillingStreet,BillingCity,Email__c,IBAN__c from Account where Id = :acc.Id];
String requestData = '{"merchant":{"signature":"7ibc7ob5|tu3454363345345674JEH3gNbeWJfIHah||567856|doU3HJVoyfsggm7MQ44qf7cpn7pc"},"customer":{"lang":"EN"},"affiliate":{"vat_id":"DE123453456","tel":"98744564563210","reference":"affiliateXXX","password":"Nova123123","mobile":"9874563210","login":"Nova","last_name":"Sample Acc","iban":null,"gender":"Female","first_name":"Sample Acc","fax":"+41054879","email":"test@nova.com","company_email":"info@nova.com","address":{"zip":"DE","street":"Musterstr","house_no":"2","country_code":"DE","company":"ABC GmbH","city":"Musterhausen"},"account_holder":"Sample Acc"}}';
String PaymentAccesskey = 'YTg3ZmY2NzlhMmYzZTcxZDkxODFhfgsdg4retget34trtrfdgdNjdiNzU0MjEyMmM=';
Account account = new Account( Name = 'Max' );
ServerCallouts.getCalloutData(requestData, PaymentAccesskey);
System.assertEquals(account.Name, 'Max');
}
}
- Poorna Priya 16
- August 15, 2021
- Like
- 0