You need to sign in to do that
Don't have an account?
Visithra
Am in DML Topic..i need to insert a record in employee__c object, if name is new it shoud insert if not it should display message as aleready exist
my code is
public class Emp {
public boolean ifExists=false;
public void insertEmp(string empName)
{
List<Employee__c> empl=[SELECT
Id, Name
FROM Employee__c];
for(Employee__c E: empl){
if(empl.Name!=empName){
insert empl;
}
}if(ifExists==true){
system.debug('Record already exists with the same employee name!..Create Another Name.!');
}
}
}
here it is allowing me to insert everytime with same name..
public class Emp {
public boolean ifExists=false;
public void insertEmp(string empName)
{
List<Employee__c> empl=[SELECT
Id, Name
FROM Employee__c];
for(Employee__c E: empl){
if(empl.Name!=empName){
insert empl;
}
}if(ifExists==true){
system.debug('Record already exists with the same employee name!..Create Another Name.!');
}
}
}
here it is allowing me to insert everytime with same name..
There are some issues with your code ,
Please try with below :
If it helps please mark this as Best answer.
Thank you.
All Answers
There are some issues with your code ,
Please try with below :
If it helps please mark this as Best answer.
Thank you.