You need to sign in to do that
Don't have an account?
Sachin Kumar
System.AuraHandledException: Script-thrown exception
Hi All,
I am new to Salesforce. I am getting below exception on my test class.
Can you please suggest me here ?
@isTest
static void test_releaseInitiative()
{
init();
Test.startTest();
String errorRelease = ViewInitiativesController.releaseInitiative(testInitiative.Id);
Initiative__c testInitiativeCheck = [SELECT Status__c, Initiative_Released__c FROM Initiative__c WHERE Id = :testInitiative.Id];
System.assertEquals(true, testInitiativeCheck.Initiative_Released__c, 'Wrong Initiative_Released__c: ' + errorRelease);
Test.stopTest();
}
Error is -- System.AuraHandledException: Script-thrown exception
Any help is really appriacted.
Thanks in advance.
I am new to Salesforce. I am getting below exception on my test class.
Can you please suggest me here ?
@isTest
static void test_releaseInitiative()
{
init();
Test.startTest();
String errorRelease = ViewInitiativesController.releaseInitiative(testInitiative.Id);
Initiative__c testInitiativeCheck = [SELECT Status__c, Initiative_Released__c FROM Initiative__c WHERE Id = :testInitiative.Id];
System.assertEquals(true, testInitiativeCheck.Initiative_Released__c, 'Wrong Initiative_Released__c: ' + errorRelease);
Test.stopTest();
}
Error is -- System.AuraHandledException: Script-thrown exception
Any help is really appriacted.
Thanks in advance.
In your apex class which method you have used the throw new AuraHandledException(ex.getMessage()); ?
So for that method calling in your test class use the try catch block like below that will clear this error.
For Example : in your ViewInitiativesController apex class if your are using the throw new AuraHandledException(ex.getMessage()); at releaseInitiative method then in the test class use like below:
@isTest
static void test_releaseInitiative()
{
init();
// Am not seeing any test data insertion in your method if needed do that.
Initiative__c testInitiative = new Initiative__c(Status__c = ' enter you picklist data' , Initiative_Released__c = ' Enter your proper value');
insert testInitiative;
Test.startTest();
try
{
String errorRelease = ViewInitiativesController.releaseInitiative(testInitiative.Id);
}
catch(exception e)
{
}
Test.stopTest();
}
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,
Maharajan.C
All Answers
@isTest
static void test_getFormAndUpsertInitiative()
{
init();
Test.startTest();
ViewInitiativesController.FieldSetForm fsForm = ViewInitiativesController.getForm(testInitiative.Id, 'MI_', false);
System.assert(!fsForm.fsNamesToFields.isEmpty(), 'Fields were not retrieved');
ViewInitiativesController.fetchUserInfo();
testInitiative.Overall_status__c = 'Creative Services';
ViewInitiativesController.upsertInitiative(testInitiative);
testInitiative = [SELECT Overall_status__c FROM Initiative__c WHERE Id = :testInitiative.Id];
System.assertEquals('Creative Services', testInitiative.Overall_status__c, 'Overall Status was not upated: ' + testInitiative.Overall_status__c);
Test.stopTest();
//System.assertEquals('Creative Services', initiativeCtrl.initiativeHistories[0].NewValue, 'Field tracking history was not retrived');
}
In your apex class which method you have used the throw new AuraHandledException(ex.getMessage()); ?
So for that method calling in your test class use the try catch block like below that will clear this error.
For Example : in your ViewInitiativesController apex class if your are using the throw new AuraHandledException(ex.getMessage()); at releaseInitiative method then in the test class use like below:
@isTest
static void test_releaseInitiative()
{
init();
// Am not seeing any test data insertion in your method if needed do that.
Initiative__c testInitiative = new Initiative__c(Status__c = ' enter you picklist data' , Initiative_Released__c = ' Enter your proper value');
insert testInitiative;
Test.startTest();
try
{
String errorRelease = ViewInitiativesController.releaseInitiative(testInitiative.Id);
}
catch(exception e)
{
}
Test.stopTest();
}
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,
Maharajan.C
It worked as per your suggestion.
Thanks a lot.
With Best Regards,
Sachin
@istest
public class SanctionIntimationDealerLetter_sls_Test {
@isTest static void SanctionLetterforDealer_sls(){
set<Id> setIdLead = new set<Id>();
Id leadRecTypeId = Schema.SObjectType.Lead__c.getRecordTypeInfosByName().get('Individual').getRecordTypeId();
Lead__c lead = new Lead__c(Constitution__c ='Individual', Subconstitution__c ='Individual',Stage__c='Credit Appraisal', FirstName__c='TestFirstName',
LastName__c='TestLastName', MiddleName__c ='TestMiddle', SuiteCRMId__c='Test12311',IsKYCDocumentsCollected__c =false,
recordtypeId = leadRecTypeId, QueryStatus__c = 'Raised',QueryRaisedDateTime__c=system.now()-20,
FTNRNonFTNRCase__c = 'FTNR',CustomerType__c='Prime');
Insert lead;
setIdLead.add(lead.Id);
Id dealerRecTypeId = Schema.Sobjecttype.Account.getRecordTypeInfosByName().get('Dealer').getRecordTypeId();
Account dealer = New Account(Name='Test Dealer', RecordTypeId=dealerRecTypeId,LeadSourcedTillDate__c = 5,OwnerId=UserInfo.getuserid());
Insert dealer;
System.assertEquals(dealer.Name, 'Test Dealer');
AssetDetail__c ast = new AssetDetail__c(Exshowroomprice__c = 50000, Loan_Details__c = lead.Id,TypeOfAsset__c='NEW',Usage__c='Personal',
Dealer__c=Dealer.Id);
Insert ast;
Loan__c loanRecord = new Loan__c();
loanRecord.LoanAmount__c = 5000;
loanRecord.AssetDetail__c = ast.Id;
loanRecord.Lead__c = lead.Id;
loanRecord.EMIAmount__c=500;
loanRecord.EMIPattern__c='Monthly';
loanRecord.EMIStartDate__c=Date.newInstance(2021, 05, 20);
loanRecord.EMIEndDate__c=Date.newInstance(2025, 10, 21);
loanRecord.RequestIdLMS__c='100000011';
loanRecord.Tenure__c = 12;
loanRecord.PushedToLMS__c = FALSE;
loanRecord.EMIType__c='Advance';
loanRecord.RepaymentMode__c='PDC';
insert loanRecord;
ApexPages.currentPage().getParameters().put('id', lead.Id);
SanctionIntimationDealerLetter_sls sancDeal = New SanctionIntimationDealerLetter_sls();
sancDeal.getilead();
sancDeal.getlstast();
SanctionIntimationDealerLetter_sls.createPdf(setIdLead);
lead.Stage__c='Hands Off';
update lead;
}
}
Can anybody please help me to find the solution?
@isTest
private class BookMeetingForExistingContact_CC_Test {
@isTest
static void testIsThisLinkUsed() {
// Create test data
URL__c urlObj = new URL__c(
Encrypted_Id__c = 'test-encrypted-id==',
Decrypted_Id__c = 'test-decrypted-id',
Key__c = 'test-key',
ExpirationDurationInMinutes__c = 60,
is_Invitation_Accpted__c = false
);
insert urlObj;
// Call the method being tested
Boolean result = BookMeetingForExistingContactController.isThisLinkUsed('test-encrypted-id');
// Verify the result
System.assertEquals(false, result);
}
@isTest
static void testDecryptHostUserData() {
// Create test data
/*User host = new User(
FirstName = 'Test',
LastName = 'User',
Email = 'testuser@test.com'
);
insert host;*/
User host = [SELECT FirstName, LastName,Email from User Where Id=:UserInfo.getUserId()];
URL__c urlObj = new URL__c(
Encrypted_Id__c = 'test-encrypted-id==',
Decrypted_Id__c = 'test-decrypted-id',
Key__c = EncodingUtil.base64Encode(Blob.valueOf('test-key')),
ParticipantAsUser__c = host.Id,ExpirationDurationInMinutes__c=30
);
insert urlObj;
// Call the method being tested
User result = BookMeetingForExistingContactController.decryptHostUserData('test-decrypted-id==');
// Verify the result
System.assertEquals(host.Id, result.Id);
System.assertEquals(host.Email, result.Email);
}
@isTest
static void testDecryptParticipantsUserData() {
// Create test data
Account account = new Account(
Name = 'Test Account'
);
insert account;
Contact contact = new Contact(
FirstName = 'Test',
LastName = 'Contact',
Email = 'testcontact@test.com',
AccountId = account.Id
);
insert contact;
URL__c urlObj = new URL__c(
Encrypted_Id__c = 'test-encrypted-id==',
Decrypted_Id__c = 'test-decrypted-id',
Key__c = EncodingUtil.base64Encode(Blob.valueOf('test-key')),
ParticipantAsContact__c = contact.Id,ExpirationDurationInMinutes__c=30
);
insert urlObj;
// Call the method being tested
Map<String, String> result = BookMeetingForExistingContactController.decryptParticipantsUserData('test-encrypted-id==');
// Verify the result
System.assertEquals(contact.Id, result.get('Id'));
System.assertEquals(contact.Email, result.get('Email'));
System.assertEquals(contact.Account.Name, result.get('Company'));
}
@isTest
static void testCreateNewMeetingForExistingUser() {
// Create test data
/*User host = new User(
FirstName = 'Test',
LastName = 'User',
Email = 'testuser@test.com'
);
insert host;*/
User host = [SELECT FirstName, LastName,Email from User Where Id=:UserInfo.getUserId()];
Account account = new Account(
Name = 'Test Account'
);
insert account;
Contact contact = new Contact(
FirstName = 'Test',
LastName = 'Contact',
Email = 'testcontact@test.com',
AccountId = account.Id
);
insert contact;
}
}