You need to sign in to do that
Don't have an account?
Visithra
hi, i need to get my max salary from the custom object(employye__c)from give passing parameter called position__c if any postion given in parameter a max salary should be get.
public static void maxSalaryOFPositions(string position){
List<Employee__c> existingEmployees = [SELECT Id, Name, Position__c, Salary__c FROM Employee__c];
integer MaxSalary= existingEmployees[0].Salary__c;
for(Employee__c emp:existingEmployees){
if((emp.Position__c==position)&&(emp[1].Salary__c>MaxSalary)){
MaxSalary=emp[1].Salary__c;
}
}system.debug('The max salary of'+position+ 'and its salary is'+MaxSalary);
}
pls help me with my code and here is my code. am getting 2 errors as illegal assignemnt from Decimal to integer and Expression must be list type:Employee__c
List<Employee__c> existingEmployees = [SELECT Id, Name, Position__c, Salary__c FROM Employee__c];
integer MaxSalary= existingEmployees[0].Salary__c;
for(Employee__c emp:existingEmployees){
if((emp.Position__c==position)&&(emp[1].Salary__c>MaxSalary)){
MaxSalary=emp[1].Salary__c;
}
}system.debug('The max salary of'+position+ 'and its salary is'+MaxSalary);
}
pls help me with my code and here is my code. am getting 2 errors as illegal assignemnt from Decimal to integer and Expression must be list type:Employee__c
This should run solve your errors. The illegal assignment from decimal to integer is because the Salary__c is a decimal and you are setting it to the MaxSalary value which you instantiated as an Integer. The record is because you treat the "emp" variable as a List when it is a single record. You would not want to use 1 either since that would always be the second element in the list. If you need to access a certain index in the loop you should use syntax like