• randheer practise
  • NEWBIE
  • 29 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 6
    Replies
vf page:
<apex:page controller="radiobox_Class">
 <apex:form>
  <apex:pageBlock>
   <apex:pageBlockSection >
    <apex:selectRadio label="Select Hobby" borderVisible="true" immediate="true" disabled="false" value="{!SelectGame}">
           <apex:selectOption itemlabel="FootBall" itemvalue="FB"/>
           <apex:selectOption  itemlabel="Tennis" itemvalue="TN"/>
           <apex:selectOption  itemlabel="Hockey" itemvalue="HOC"/>
           <apex:selectOption  itemlabel="CoCo" itemvalue="Co"/>
           <apex:selectOption  itemlabel="Cricket" itemvalue="Cric"/>
    </apex:selectRadio>   
       <apex:commandButton value="Show Selected game" action="{!Display}"/>
       <apex:outputLabel>your selected game code is....{!output }</apex:outputLabel>
   </apex:pageBlockSection>   
  </apex:pageBlock>   
 </apex:form>
</apex:page>

class:
public class radiobox_class {
    public string output{get;set;}
    public string SelectGame{get;set;}
    public void Display(){
        if(SelectGame=='FootBall'){
            output='FB';
        }else if(SelectGame=='Tennis'){
            output='TN';
        }else if(SelectGame=='Hockey'){
            output='HOC';
        }else if(SelectGame=='Cricket'){
            output='CIC';
        }else if(SelectGame=='CoCo'){
            output='Co';
        }else{
            output='sorry some thing went wrong';
        }
    }
}
i want through method only
THanks in Advance
As per documentation iam cleared but how to do in practical to a basic Apex class and its Testclass using test.loaddata method
Its urgent please helpme anyone


Thanks in Advance
i have written a class,but both users are executing the class,but only user2 should insert the record what mistake is there in my class can annyone tell me.

class
public class inserting {
    public  void insertingrecords(string nm,decimal dd){
        Account a = new Account();
        a.name=nm;
        insert a;
    }
   
}

testclass using system.runas():
@isTest
private class TestRunAs {
   public static testMethod void testRunAs() {
      // Setup test data
      // This code runs as the system user
      Profile p = [SELECT Id,name FROM Profile WHERE Name='System Administrator']; 
               system.debug('values in p==='+'p.Name is '+p.name+'p.id is '+p.Id);
       
      /*User u = new User(Alias ='rprac', Email='sharath.kanukuntla1@gmail.com', 
      EmailEncodingKey='UTF-8', LastName='practise1', LanguageLocaleKey='en_US', 
      LocaleSidKey='en_US', ProfileId = p.Id, 
      TimeZoneSidKey='America/Los_Angeles', UserName='randheer.practise1@gmail.com');
      system.debug('user details are====== '+'email is '+u.Email+'Alias is '+u.Alias+'Profile id is '+u.ProfileId);
      
       System.runAs(u) {
         // The following code runs as user 'u' 
         System.debug('Current User: ' + UserInfo.getUserName());
         System.debug('Current Profile: ' + UserInfo.getProfileId()); 
      }*/
       User u3 = [SELECT Id FROM User WHERE UserName='randheer.practise1@gmail.com'];
         System.runAs(u3) {
             inserting obj = new inserting();
             obj.insertingrecords('sresht',12.22);
             System.debug('Current User: ' + UserInfo.getUserName());
             System.debug('Current Profile: ' + UserInfo.getProfileId()); 
             
         }
   }
}
 
public class UpsertDml {
    public list<Account> acc{get;set;}
    //default constructor1
    public UpsertDml(){
        acc=new list<Account>();
    }
    public void upsertAccount()
    {
        Account a = new Account(Name='krishna');
        try{
             insert a;
        }catch(Exception e){
             system.debug('Record '+a.Name +' inserted successfully');
        }
        List<Account> accounts=[SELECT id,name FROM Account WHERE name='kanusupdated'];
        If(accounts.size() > 0){
            try{
             for(Account a1:accounts)
                {
                if(a1.name=='kanusupdated')
                {
                    Account a2=new Account();
                    a2.id=a1.id;
                    a2.name='kanus updated';
                    acc.add(a2);
                }
             }
                    update acc;
                system.debug('records were updated successfully===='+acc);     
            }catch(DMLException e){
                system.debug('records were not updated====='+e);
            }
     
       }
   }
}

testclass.
@isTest
public class upsertDml_Test {
    //to cover first Exception
    public static testMethod void main1Method(){
        Account a = new Account();
        a.Name='krihna';
        a.BillingCity='khhgkg';
        insert a;
        upsertDml sc = new upsertDml();
        sc.upsertAccount();
    }
    public static testmethod list<Account> recordCreation(){      
        List<Account> ac = new List<Account>();
        Account a = new Account();
        a.Name = 'kanusupdated'; 
        ac.add(a);
        return ac;      
    } 
    public static testmethod void P_main(){
        Test.startTest();
        list<Account> acc1 = recordCreation();
        insert acc1;   
        upsertDml sc = new upsertDml();
        sc.acc = recordCreation();
        system.debug('values in sc.acc ============='+sc.acc);
        sc.upsertAccount();
        Test.stopTest();
    }
    
}

public class UndeleteDml {
    public static void undeleteAccount()
    {
        List<Account> accounts=[SELECT id,Name FROM Account WHERE name like 'siri rao' all rows];
        system.debug('No of undeleted records are============'+accounts.size());
        try{
            undelete accounts;
            system.debug('No of records in Account============'+accounts);
            system.debug('records were undeleted from recyle bin successfully');
           }catch(Exception e){
                system.debug('sorry records were not undeleted');
               }
    }
}
thanks in advance
apex class
public class UpsertDml {
    public list<Account> acc{get;set;}
    //default constructor1
    public UpsertDml(){
        acc=new list<Account>();
    }
    public void upsertAccount()
    {
        Account a = new Account(Name='k');
        try{
             insert a;
        }catch(Exception e){
             system.debug('Recor '+a.Name +' inserted successfully');
        }
        List<Account> accounts=[SELECT id,name FROM Account WHERE name='kanusupdated'];
        If(accounts.size() > 0){
            try{
             for(Account a1:accounts)
                {
                if(a1.name=='kanusupdated')
                {
                    Account a2=new Account();
                    a2.id=a1.id;
                    a2.name='kanus updated';
                    acc.add(a2);
                }
             }
                    update acc;
            system.debug('records were updated successfully===='+acc);     
            }catch(DMLException e){
                system.debug('records were not updated====='+e);
            }
     
       }
   }
}
============testclass
@isTest
public class upsertDml_Test {
    public static testmethod list<Account> recordCreation(){      
        List<Account> ac = new List<Account>();
        Account a = new Account();
        a.Name = 'kanusupdated';
        ac.add(a);
        return ac;      
    }
    
    public static testmethod void P_main(){
        Test.startTest();
        Account a = new Account(name='kanusupdated');
        list<Account> acc1 = recordCreation();
        insert acc1;     
        upsertDml sc = new upsertDml();
        sc.acc = recordCreation();
        system.debug('values in sc.acc ============='+sc.acc);
        sc.upsertAccount();
        Test.stopTest();
    }    
}

thanks in advance..just cover the code at catch block while iam inserting record with name 'k'..thanks in advance
it should cover both try aswell as catch also
public class UndeleteDml {
    public static void undeleteAccount()
    {
        List<Account> accounts=[SELECT id,Name FROM Account WHERE name like 'siri rao' all rows];
        system.debug('No of undeleted records are============'+accounts.size());
        try{
            undelete accounts;
            system.debug('No of records in Account============'+accounts);
            system.debug('records were undeleted from recyle bin successfully');
           }catch(Exception e){
                system.debug('sorry records were not undeleted');
               }
    }
}
thanks in advance
DeleteDMl class
public class DeleteDml {
    public void accountInserting(){
        //fetching old records with name kanus
        List<Account> accounts =[SELECT id,name from Account WHERE name='kanus'];
        try{
        delete accounts;
        }catch(Exception e){
            system.debug('records are not deleted');
            
        }
    }
}

testclass
@istest
public class DeleteDML_test {
    public static testMethod Account insertingAccount(){
        test.startTest();
        Account a = new Account();
        a.Name='kanus';
        insert a;
        DeleteDml d = new DeleteDml();
        d.accountInserting();
        Test.stopTest();
        return a;
       
    }
    public static testMethod void Method2(){
      Test.startTest();
        Account a1=insertingAccount();
        Account a2=[SELECT id,name FROM Account WHERE name='kanus123'];
        try{
            delete a2;
        }catch(Exception e){
            system.debug('no record with name kanus123');
        }
        
        test.stopTest();
         DeleteDml d1 = new DeleteDml();
        d1.accountInserting();
    }
}
Am inserting 1000 records to Task object, as per the trigger functionality it splits in 200 and inserts/updates the records. During this insertion 5 batches splits up and running concurrently this is causing some failures in batches. So i need to create list of 1000 records during insert in the trigger and call the batch apex for single time kindly help me very urgent
Why to use (SeeAllData == true) in Test class?
DeleteDMl class
public class DeleteDml {
    public void accountInserting(){
        //fetching old records with name kanus
        List<Account> accounts =[SELECT id,name from Account WHERE name='kanus'];
        try{
        delete accounts;
        }catch(Exception e){
            system.debug('records are not deleted');
            
        }
    }
}

testclass
@istest
public class DeleteDML_test {
    public static testMethod Account insertingAccount(){
        test.startTest();
        Account a = new Account();
        a.Name='kanus';
        insert a;
        DeleteDml d = new DeleteDml();
        d.accountInserting();
        Test.stopTest();
        return a;
       
    }
    public static testMethod void Method2(){
      Test.startTest();
        Account a1=insertingAccount();
        Account a2=[SELECT id,name FROM Account WHERE name='kanus123'];
        try{
            delete a2;
        }catch(Exception e){
            system.debug('no record with name kanus123');
        }
        
        test.stopTest();
         DeleteDml d1 = new DeleteDml();
        d1.accountInserting();
    }
}