• Tamojita Guhasarkar
  • NEWBIE
  • 70 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 8
    Replies
Hello Guys, 

I'm into a situation with a Test class , please help me to resolve it .

My Apex Code : -
public class Acc_dtls_nw 
{
    public String s;
    public integer i =0;
       
    public string acc_type_check(String Type_value)
    {
       string qry ='select count() from account where type=:Type_value';       
        i= database.countQuery(qry);
        if (i>0)
        {
           s='Total no of account Types are: '+i; 
        }
        else
        {
            s='Invalid type :';
        } 
              
          return s;     
         
    }}

I'm not able to get a 100% code coverage for this class. below part is not included under code coverage
 
 s='Total no of account Types are: '+i; 

Now the test class I wrote is below 
@istest
public class test_acc_dtls_nw 
{
     static testMethod void test_trucond()
    {
        Acc_dtls_nw ac= new Acc_dtls_nw();
        string tst_true = ac.acc_type_check('Prospect');
       // System.AssertEquals(ac.i,2);
        string p ='prospect';
       // System.AssertEquals(ac.s,p);      
    }
    
    static testMethod void test_flscond()
    {
        Acc_dtls_nw ac= new Acc_dtls_nw();
        string tst_flse = ac.acc_type_check('xyz');
       // System.AssertEquals(ac.i,0);        
    }
}

So why that part is getting missed under code coverage? is it because S is not doing anything and used just for strong some text value? please help me to get this clarified. 
Hello All , 
For my Organization , for an Object the OWD is set to Public Read Only.I have total 2000 users.Now I want for only 10 users to be able to see only their own records , but others should be able to view each other records. Can it be achieved w/o changing the OWD ? Please help.

Thanks,
Tanoy
Hello Folks,

I'm trying to add next/previous/first/last - the pageinitiations on a Custom Controller page. But while clicing the button, I'm getting below error 

System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!last}' in component <apex:commandButton> in page cus_message: Class.cus_message.last: line 31, column 1
Class.cus_message.last: line 31, column 1


Can someone please help to resolve the same.

Controller Code 

public class cus_message 
{
    List<Account> acts =new List<account>();
   
   public ApexPages.StandardSetController con {
        get;
        set;
    }
   
    public List<Account> getHigh_revenue_List()
    {
        acts =[select name,phone,industry,type,AnnualRevenue from Account where AnnualRevenue>50000];
        system.debug('inside high revenue');
        return acts;
    }
    
    Public List<Account> getLow_revenue_List()
    {
       
        acts =[select name,phone,industry,type,AnnualRevenue from Account where AnnualRevenue = NULL];
        system.debug('inside low revenue');
        return acts;
    }
    
    public void first() {
        this.con.first();
    }

    // returns the last page of records
    public void last() {
        this.con.last();        
    }

    // returns the previous page of records
    public void previous() { 
        this.con.previous();
    }

    // returns the next page of records
    public void next() {
        this.con.next();
    }
   
}

Visualforce Page 

<apex:page controller="cus_message">
<apex:form >
    <apex:pageBlock id="block_ID">
    <apex:pageblockButtons >
        <apex:commandButton value="Next Page" action="{!next}"/>
        <apex:commandButton value="Last Page" action="{!last}"/>
    </apex:pageblockButtons>
    
        <apex:tabPanel >
            <apex:tab label="High Revenue">
                <apex:pageblockTable value="{!High_revenue_List}" var="var1">
                    <apex:column value="{!var1.name}"/>
                    <apex:column value="{!var1.industry}"/>
                    <apex:column value="{!var1.type}"/>
                     <apex:column value="{!var1.AnnualRevenue}"/>
                </apex:pageblockTable>
            </apex:tab>
            <apex:tab label="Zero Revenue">
                <apex:pageblockTable value="{!Low_revenue_List}" var="var2">
                     <apex:column value="{!var2.name}"/>
                    <apex:column value="{!var2.industry}"/>
                    <apex:column value="{!var2.type}"/>
                     <apex:column value="{!var2.AnnualRevenue}"/>
                </apex:pageblockTable>         
                
         
            </apex:tab>
        </apex:tabPanel>
    </apex:pageBlock>
 </apex:form>
</apex:page>
Hello Folks ,

Please help me to clear few bacis doubts related to Governor limit - bulkfy DML 

Case 1: My code is like below

List<Account> act = [ some query and it retrns 5000 records ];
for ( account a : act)
{
a.description =' updated by script';
}
update act;

Case 2: My code is like below
List<Account> act = [ some query and it retrns 5000 records ];
List<Account> new_act = new List<Account>();

for ( account a: act)
{
a.description =' updated by script ';
new_act.add(a);
}

update new_act;

================================

Ok so my question is as my quesry is retriving 5000 records and I want to update these records ,so I needto Bultyfly my dml so it will not breach the govornor limit . so in to achive this , as per my understading , both of these approches should do the same work , i.e , as I worte the Update outside the loop, hence it will execute only once ( though the for loop goes for 5000 times ) and update all these 5000 records. 

So is this correct ? can someone clafiry please .

Thanks,
Tanoy
Hello All , 

I'hv a basic question on Updating fileds using APEX Code - rather I want to clear my concepts . The requirement is very simple. For Account Object , Update all Countries to United States of America where country is like US or USA . Now, I'm able to do it by writing below code

Public Class Acc_Country_Name_Change
{
     
   Public Pagereference Name_update()
   {
     
      List<Account> Act = [SELECT name,BillingCountry FROM Account where BillingCountry in ( 'US','USA')];
 
      for(Account a : act)
          {
      a.BillingCountry ='united states of america';
          } 
  update act;
     
      return null;
 
  }
 
 }

Now , I'hv two questions on this . Please help me to clear my concept. 

1> in the For loop , its like FOR ( sObject : List ) - so why both are not List ? is it because in FOR Loop , only one row get processed at a time ? Or something else?

2> Inside the FOR loop , we are writing a.BillingCountry ='united states of america'  , but in update its like Update act . Why so? 

Can someone please help me to clarify my doubts? I know they are very basic , But I'm kind of confused.

Thanks,
Tanoy