• prime ki
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
Apex Class:

public class  Employee {
    
    public list<Employee__c> Emp{set;get;} 
    public string Name{set;get;}
    public String EmployeeID{set;get;}
    public date   Birthday{set;get;}
    public String EmployeeCompany{set;get;}
    public String PANNumber{set;get;}
    public String AccountNumber{set;get;}
    public String Address{set;get;}
    public String City{set;get;}
    public String State{set;get;}
    Public String Email{set;get;}
    public String Country{set;get;}
    public String Address1{set;get;}
    public String City1{set;get;}
    public String State1{set;get;}
    public String Country1{set;get;}
    public boolean hide{set;get;}
    public boolean Check{set;get;}
    public boolean AllEmployees{set;get;}
    public String errorMessage {get;set;}
    
    
    boolean error;
    
   
    
    public Employee(ApexPages.StandardController controller){
        hide = true;
       AllEmployees = false;
    }
    
public void validate() {
   
   }
    List<String> L = new List<String>{'Name','Email'};
    public void Save(){
        system.debug('Method Called:');
      
            if(Name == '' || Name == null ){
                if(Email == '' || Email == null){
                ApexPages.addMessage(new ApexPages.message(Apexpages.Severity.ERROR,'Field is required :Name and Email'));
                }else{
                    ApexPages.addMessage(new ApexPages.message(Apexpages.Severity.ERROR,'Field is required :Name'));
                }
            }else if(Email == '' || Email == null){
                ApexPages.addMessage(new ApexPages.message(Apexpages.Severity.ERROR,'Field is required  :Email'));
            }else if(Name != null && email != null){
                Employee__c E = new Employee__c();
                E.Employee_ID__c = EmployeeID;
                E.Name = Name;
                E.Email__c = Email;  
                E.Account_Number__c = AccountNumber;
                E.BirthDay__c = Birthday;
                E.PAN_number__c = PANNumber;
                E.Company__c = EmployeeCompany;
                E.Address__c = Address;
                E.City__c = City;
                E.State__c = State;
                E.Country__c = Country;
                E.Address1__c = Address1;
                E.City1__c = City1;
                E.State1__c = State1;
                E.Country1__c = Country1;
                
             insert E;
                hide = false;
                
                 ApexPages.addMessage(new ApexPages.message(Apexpages.Severity.CONFIRM,'Record Saved Successfully'));
                 Emp = [select Employee_ID__c,Name,Company__c,Address__c from Employee__c];
                AllEmployees = true;
            }
        
        
                
      
    }
    
    public void saveNew(){
           Employee__c E = new Employee__c();
                E.Employee_ID__c = EmployeeID;
                E.Name = Name;
                E.Email__c = Email;  
                E.Account_Number__c = AccountNumber;
                E.BirthDay__c = Birthday;
                E.PAN_number__c = PANNumber;
                E.Company__c = EmployeeCompany;
                E.Address__c = Address;
                E.City__c = City;
                E.State__c = State;
                E.Country__c = Country;
                E.Address1__c = Address1;
                E.City1__c = City1;
                E.State1__c = State1;
                E.Country1__c = Country1;
        insert E;
        EmployeeID = null;
        Name = null;
         Email = null;
        Birthday = null;
        AccountNumber = null;
        PANNumber = null;
       EmployeeCompany = null;
        Address = null;
            City = null;
            State = null;
            Country = null;
            Address1 = null;
            City1 = null;
            State1 = null;
            Country1 = null;
        ApexPages.addMessage(new ApexPages.message(Apexpages.Severity.CONFIRM,'Record Saved Successfully'));
      Emp = [select Employee_ID__c,Name,Company__c,Address__c from Employee__c];
                AllEmployees = true;
    }
    
    public pagereference Cancel(){
        
        Name = null;
         system.debug('Called:'+Name);
        EmployeeID  = null;   
        Birthday = null;      
        EmployeeCompany = null;
        PANNumber = null;     
        AccountNumber  = null;
        Address = null;
        City   = null;        
        State = null;        
        Email = null;         
        Country = null;       
        Address1 = null;      
        City1     = null;
        State1    = null;
        Country1  = null; 
        
  return new pagereference('/apex/BigVisualforcePage');
    }
    
    public void method(){
        system.debug('Method Called:');
          if(Check == true){
            Address1 = Address;
            City1 = City;
            State1 = State;
            Country1 = Country;
        }else{
            Address1 = null;
            City1 = null;
            State1 = null;
            Country1 = null;

        }
    }
    
  
}



Test Class:

@istest
private class EmployeeTest {
    
    static testmethod void Save(){
        
        test.startTest();
       Employee E = new Employee(new ApexPages.StandardController(new Employee__c()));
       E.EmployeeID = '1';
       E.Name = 'Arudra';
        E.Email = 'varudra@primetgi.com';
       
        E.Save();
        E.saveNew();
        E.Cancel();
        E.method();
        E.validate();
        test.stopTest();
    }
    
     
        
    }

i am traying to lock the records using SOQL(FOR UPDATE) Statement but it's not getting locked.In this two ways i am traying to lock the records 

1.Account [] accts = [SELECT Id FROM Account WHERE Name = 'SOQL' LIMIT 2 FOR UPDATE];

2.for (List<Account> Acc : [select id from Account  
   where Name = 'SOQL' for update]) {
    
}