I am trying to validate data that is if posting country is other than india and selling country is india then users has to compulsorily choose USD as a pricelist.
Have written a logic something like this. Let me know where am i going wrong.
KYCQuote.apxc
@AuraEnabled
Public static Id saveAccount(apttus_proposal_proposal__c qu,String billingAddr,String postingAddr){
Product_PriceList__c pr = [select id,name from Product_PriceList__c where name='USD'];
System.debug('pricelist query--------->'+pr);
System.debug('pricelist query id--------->'+pr.id);
System.debug('Inside createAccount'+qu);
System.debug('Address---->'+billingAddr);
String str = billingAddr;
String str1 = postingAddr;
String PostCountry;
List<String> res = str.split('`');
List<String> res1 = str1.split('`');
System.debug(res);
if(res[0]!=null){
qu.FinalBillingStreet__c = res[0];
}
if(res[1]!=null){
qu.FinalBillingCity__c = res[1];
}
if(res[2]!=null){
qu.FinalBillingCountry__c = res[2];
}
if(res[3]!=null){
qu.FinalBillingState__c = res[3];
}
if(res[4]!=null){
qu.FinalBillingPinCode__c = res[4];
}
//Posting
System.debug(res);
if(res1[0]!=null){
qu.FinalPostingStreet__c = res1[0];
}
if(res1[1]!=null){
qu.FinalPostingCity__c = res1[1];
}
if(res1[2]!=null){
qu.FinalPostingState__c = res1[2];
}
else
qu.FinalPostingState__c = '';
if(res1[3]!=null){
qu.FinalPostingCountry__c = res1[3];
PostCountry = res1[3];
}
if(res1[4]!=null){
qu.FinalPostingPinCode__c = res1[4];
}
System.debug('Post country--------->'+PostCountry);
System.debug('Quotation\'s selling country--------->'+qu.Selling_Country__c);
System.debug('Quotation\'s PriceList--------->'+qu.PriceList__c);
System.debug('PriceList not equal to usd--------->'+qu.PriceList__c!='USD');
System.debug('selling country is equal to india--------->'+qu.Selling_Country__c == 'India');
System.debug('Pricelist is not equal to USD--------->'+qu.PriceList__c!='USD');
System.debug('Pricelist is not equal to USD pricelists ID--------->'+qu.PriceList__c!=pr.id);
System.debug('Pricelist from query--------->'+pr.id);
//To check posting country with selling country
try {
if(PostCountry !='India' && qu.Selling_Country__c == 'India' && qu.PriceList__c!=pr.id){
System.debug('Inside if -- true');
}
else
insert qu;
}
catch (Exception e) {
// "Convert" the exception into an AuraHandledException
throw new AuraHandledException(e.getMessage());
}
System.debug('Final value of quote before save '+qu);
//insert qu;
System.debug('Quote Saved');
return qu.id;
}
KYCQuoteController.js
createAccount : function(component, event,helper) {
var newQuote = component.get("v.quot");
console.log('Value of new quote');
console.log(newQuote);
var valueB = component.get("v.storeRadioValue");
var valueP = component.get("v.storeRadioValuePosting");
console.log('Value of selected value from billing');
console.log(valueB);
var action22 = component.get("c.saveAccount");
action22.setParams({
"qu": newQuote,
"billingAddr": valueB,
"postingAddr": valueP
});
action22.setCallback(this, function(a) {
var state = a.getState();
var qpId = a.getReturnValue();
if (state === "SUCCESS") {
//component.set("v.isModalOpen",false);
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"type" : "Success",
"message": "The record has been created successfully."
});
toastEvent.fire();
window.parent.location = '/' + qpId;
}else if(state = "ERROR"){
var errorMsg = a.getError()[0];
let toastParams = {
title: "Error",
message:" Please choose Pricelist USD if Selling country is India and Account Posting country is not India!!!",
type: "error"
};
let toastEvent = $A.get("e.force:showToast");
toastEvent.setParams(toastParams);
toastEvent.fire();
}
});
$A.enqueueAction(action22);
}