Method does not exist or incorrect signature - salesforce

I am trying to implement a simple change for an apex class in production. I have the proper class and proper test class. The test class runs successfully in sandbox without errors, but apparently the error is coming from the TestHelper default test class in Salesforce. When trying to deploy in production it throws the error "Method does not exist or incorrect signature: void createUser(Id, String, String, Date, Integer) from the type TestHelper"
I've tried the usual of changing the method it references to public static void, but to no avail, it throws errors in code
This is my test class:
#isTest
private class OppLineItemInvntryBO_AType_OppStge_Test {
#testSetup public static void setup() {
Profile p = [SELECT Id FROM Profile
WHERE Name = 'profile1' LIMIT 1];
Date myDate = Date.newinstance(2019,07,01);
User testUser = TestHelper.createUser(p.Id,
'company1','legalentity1',myDate,327001);
And this is my TestHelper class:
public with sharing class TestHelper {
public static User createUser(Id profileId, String company) {
Integer rnd = getRandomNumber(10000);
User user = new User(
Username = 'john.doe#acme.com' + String.valueOf(rnd),
Email = 'john.doe' + String.valueOf(rnd) + '#acme.com',
LastName = 'Doe',
FirstName = 'John',
Alias = 'JD' + String.valueOf(rnd),
ProfileId = profileId,
LocaleSidKey = 'en_US',
LanguageLocaleKey = 'en_US',
TimeZoneSidKey = 'America/Los_Angeles',
EmailEncodingKey='UTF-8',
CompanyName = company);
insert user;
return user;
}
public static Integer getRandomNumber(Integer size){
Double d = math.random() * size;
return d.intValue();
}
}
The full error is this:
API Name - OppLineItemInvntryBO_AType_OppStge_Test
Type - Apex Class
Line - 14
Column - 36
Error Message - Method does not exist or incorrect signature: void createUser(Id, String, String, Date, Integer) from the type TestHelper

You are invoking the createUser method with 5 parameters in OppLineItemInvntryBO_AType_OppStge_Test class where as in the TestHelper class , the createUser method accepts only 2 parameters. Thats why you are getting this error. Try to invoke the method with correct parameters.

Related

How do you parse multi data sets through yaml file?

Here's the yaml file :
---
email:
- John#gmail.com
- Adam#gmail.com
password:
- Test#1234
- Abcd#1234
I want my script to run two times, one with each user email and password.
Code i have tried is :
#DataProvider
public Object[][] getData() {
Object[][] data = new Object[2][2];
data[0][0] = YamlReader.getYamlValue("email");
data[0][1] = YamlReader.getYamlValue("password");
data[1][0] = YamlReader.getYamlValue("email");
data[1][1] = YamlReader.getYamlValue("password");
return data;
}
#Test(dataProvider="getData")
public void Test_Login_with_multiple_data_sets(String username, String password) {
element("input_username").sendKeys(username);
element("input_password").sendKeys(password);
element("button_signIn").click();
}
It fails because i don't know the way to pass exact value based on the index for email and password.

Flutter floor database Future bool action in DAO file?

While using floor database can we set an action which will turn as a boolean like below example?
Future<bool> isItAdded(in user_id) async{
var = dbClient = await db;
List<Map> list = await dbClient.rawQuery{SELECT * FROM Users WHERE user_id}, [user_id]}
return list.lenght > 0 ? true : false
}
You may write DAO object:
#dao
abstract class UsersDao {
#Query('SELECT * FROM users WHERE user_id = :userId')
Future<List<User>> findUsers(Int userId);
}
Before that you neeed to create entity:
#Entity(tableName: 'users')
class User{
#PrimaryKey(autoGenerate: true)
final int id;
#ColumnInfo(name: 'user_id')
final int userId;
}
Also you need to create database access object:
part 'database.g.dart'; // the generated code will be there
#Database(version: 1, entities: [User])
abstract class AppDatabase extends FloorDatabase {
UsersDao get usersDao;
}
Then generate additional code by command:
flutter packages pub run build_runner build
And then write check function inside database access object:
Future<bool> isItAdded(in user_id) async {
List<User> list = await usersDao.findUsers(user_id);
return list.lenght > 0;
}
The best solution is not to add user_id column and use only unique id column.

Testing with Community User, getNetworkId return null

#isTest
public static void TestEmptySearchQuery() {
User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
System.runAs ( thisUser ) { // running as thisUser to Avoid Error: MIXED_DML_OPERATION
setupData(); // inside setupData, community is created successfully
generateUser(); // List of user assigned with some profile, as required for project.
list<PermissionSetAssignment> PSA = new list<PermissionSetAssignment> ();
PermissionSet ps = [SELECT Id, name FROM PermissionSet where name='Some_Access'];
system.debug('PermissionSet ' + ps);
for(user u:userList)
PSA.add(new PermissionSetAssignment(AssigneeId = u.id, PermissionSetId = ps.Id)); // all the user assgined with some_access based on requirement of project
insert PSA;
}
Test.startTest();
User usr = [select Id from User where Id = :userList[0].id];
System.runAs(usr) {
system.debug('Network ommunityId ****' + Network.getNetworkId()); //getting null
SomeClass obj = new SomeClass();
Id Nid=obj.fetchNetworkId(); // return null;
system.debug('network id ' + Nid); // null
}
Test.stopTest();
}
class SomeClass {
//some code
public id fetchNetworkId() {
system.debug('network id ' + Network.getNetworkId()); // network id null;
return Network.getNetworkId(); // return null
}
// some code
}
While running normally page, controller returns proper network id,
when try to write a test class for this, community network id always return null.
the user you use for the runAs needs to be part of a community, so you need to basically create an account, create a contact and then a user for that contact. That makes the runAS user to be part of a community

Unsupported Media Type Spring ReST resource

I have a simple method defined in my Rest Resource as below:
#RequestMapping(value = "/{studyId}/cases/{caseId}/exportlocation/{exportLocation}", method = RequestMethod.PUT)
#Timed
public void exportCase(#PathVariable Long studyId, #PathVariable Long caseId, #PathVariable String exportLocation,
#RequestBody Case acase) throws Exception {
log.debug("REST request to export Case {} for Study : {}", acase, studyId);
String exportFileName = exportService.exportCase(acase, "test");
// if (exportFileName == null) {
// response.sendError(HttpServletResponse.SC_NOT_FOUND, "Can't Export");
// }
// return exportFileName;
}
When I make a call on the page, I can see the URL as being /app/rest/studies/1/cases/1/exportlocation/test
I have the Request Mapping defined as
#RequestMapping(value = StudyResource.REQUEST_MAPPING, produces = MediaType.APPLICATION_JSON_VALUE)
#Secured(AuthoritiesConstants.USER)
public class StudyResource {
private final Logger log = LoggerFactory.getLogger(StudyResource.class);
public static final String REQUEST_MAPPING = "/app/rest/studies";
But keep getting a 415 Unsupported Media type. Can someone please look at the lines of code and tell me what is wrong. I highly appreciate your time and help.
My JS layer from where the calls are made on the page are as shown"
$scope.exportCase = function(studyId, caseId, exportLocation){
StudyService.updatecase.get({studyId:studyId,caseId:caseId}).$promise.then(function(acase){
$scope.acase = acase;
console.log(acase);
});
StudyService.exportcase.exportc({studyId: studyId,caseId:caseId,exportLocation:exportLocation},$scope.acase,
function () {
AND JS Service part below
exportcase : $resource('app/rest/studies/:studyId/cases/:caseId/exportlocation/:exportLocation', {}, {
'exportc' : {
method : 'PUT',
params : {
studyId : '#studyId',
caseId : '#caseId',
exportLocation : '#exportLocation'
}
},
})

EasyMock - expectation of mocked object

I am fairly new to EasyMock. I am trying to write a EasyMock test for my Spring WS Endpoint and keep running to a issue. Details are listed below:
Endpoint:
#PayloadRoot(namespace = NAMESPACE_URI, localPart = "UserCreate")<BR>
public void handleUserCreationRequest(#RequestPayload Element userCreate) throws JDOMException {
String userName = userNameExp.valueOf(userCreate);
String loginName = userLoginNameExp.valueOf(userCreate);
String eMail = eMailExp.valueOf(userCreate);
String region = regionExp.valueOf(userCreate);
String department = departmentExp.valueOf(userCreate);
String businessUnit = businessUnitExp.valueOf(userCreate);
userManagementService.userCreate(userName, loginName, eMail,
region, department, businessUnit);
}
Test:
#Before<BR>
public void setUp() throws JDOMException {<BR>
xPath = createNiceMock(XPath.class);<BR>
payload = createNiceMock(Element.class);<BR>
managementService = createStrictMock(UserManagementService.class);<BR>
serviceEndpoint = new UserManagementServiceEndpoint(managementService);
}
#Test
public void testUserCreationHandler() throws JDOMException {
expect(xPath.valueOf(payload)).andReturn("userName");
expect(xPath.valueOf(payload)).andReturn("loginName");
expect(xPath.valueOf(payload)).andReturn("eMail");
expect(xPath.valueOf(payload)).andReturn("region");
expect(xPath.valueOf(payload)).andReturn("department");
expect(xPath.valueOf(payload)).andReturn("businessUnit");
managementService.userCreate("userName", "loginName", "eMail",
"region", "department", "businessUnit");
expectLastCall();
replayAll();
serviceEndpoint.handleUserCreationRequest(payload);
verifyAll();
}
Error Message:
Failed tests:
testUserCreationHandler(com.xxx.usermanagement.endpoint.UserManagementServiceEndpoint
Test):
Expectation failure on verify:
valueOf(EasyMock for class org.jdom.Element): expected: 6, actual: 0
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0<BR><BR>
I would appreciate if anyone can help me on this. Thanks in advance.
The problem you have here is that your XPath mock object is not set to your UserManagementServiceEndpoint object.
You should either modify the constructor to accept an XPath parameter or create a setter for it.

Resources