You need to sign in to do that
Don't have an account?
sumit d
Malformed JSON: Expected '[' at the beginning of List/Set in test class
Hi All,
I have created a test class which is giving me following error:-Malformed JSON: Expected '[' at the beginning of List/Set
How to resolve it ?
My class and test class is given below:-
public with sharing class ParticipationController {
@AuraEnabled
public static string updateParticipations(Object data) {
List<bre__BR_Participation__c> ParticipationsForUpdate = (List<bre__BR_Participation__c>) JSON.deserialize(
JSON.serialize(data),
List<bre__BR_Participation__c>.class
);
try {
update ParticipationsForUpdate;
return 'Success: Participation updated successfully';
}
catch (Exception e) {
return 'The following exception has occurred: ' + e.getMessage();
}
}
}
My test class is given below:-
@istest
public with sharing class ParticipationControllerTest {
static testmethod void updateParticipationTest() {
bre__BR_Event__c ev = new bre__BR_Event__c();
ev.bre__Start_Date__c = System.today();
insert ev;
bre__BR_Participation__c data = new bre__BR_Participation__c();
data.bre__BR_Event__c = ev.id;
insert data;
test.startTest();
data.Participated__c = true;
update data;
ParticipationController.updateParticipations(data);
test.stopTest();
}
}
I have created a test class which is giving me following error:-Malformed JSON: Expected '[' at the beginning of List/Set
How to resolve it ?
My class and test class is given below:-
public with sharing class ParticipationController {
@AuraEnabled
public static string updateParticipations(Object data) {
List<bre__BR_Participation__c> ParticipationsForUpdate = (List<bre__BR_Participation__c>) JSON.deserialize(
JSON.serialize(data),
List<bre__BR_Participation__c>.class
);
try {
update ParticipationsForUpdate;
return 'Success: Participation updated successfully';
}
catch (Exception e) {
return 'The following exception has occurred: ' + e.getMessage();
}
}
}
My test class is given below:-
@istest
public with sharing class ParticipationControllerTest {
static testmethod void updateParticipationTest() {
bre__BR_Event__c ev = new bre__BR_Event__c();
ev.bre__Start_Date__c = System.today();
insert ev;
bre__BR_Participation__c data = new bre__BR_Participation__c();
data.bre__BR_Event__c = ev.id;
insert data;
test.startTest();
data.Participated__c = true;
update data;
ParticipationController.updateParticipations(data);
test.stopTest();
}
}
Data is already a string you no need to change this and try to remove below line and see.
Thanks,