• Aradhika Chawla 3
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Iam getting error while updating record.
<apex:page showHeader="false" controller="ap_SOQl">
     <apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection title="Account Page">
            
        <apex:outputText value="Enter Name :"> </apex:outputText>
            <apex:inputText value="{!aname}" />
            
          <apex:outputText value="Enter Phone No :"></apex:outputText>
        <apex:inputText value="{!aphone}"/>
            
            <apex:outputText value="Enter City"></apex:outputText>
            <apex:inputText value="{!acity}" />  
            
        </apex:pageBlockSection>
        
        <apex:pageBlockSection title="Actions">
            
        <apex:commandButton value="Insert.." action="{!mi}"/>
            <apex:commandButton value="Delete .." action="{!md}"/>           
           <apex:commandButton value="Update..." action="{!mu}"/>
            <apex:commandButton value="Retrieve .." action="{!ms}"/>
           <apex:commandButton value="Upsert..." action="{!mups}"/>
        </apex:pageBlockSection>
      <apex:pageBlockSection title="aaccount Records">
        <apex:pageBlockTable value="{!arecs}" var="items" title="Records" >
            
            <apex:column value="{!items.name}"/>
            
                <apex:column value="{!items.phone}"/>
            
            <apex:column value="{!items.billingcity}"/>   
            
        </apex:pageBlockTable>
          </apex:pageBlockSection>
        <apex:pageMessages ></apex:pageMessages>
        
        </apex:pageBlock>
         
    </apex:form>
</apex:page>
Controller
public class ap_SOQl{
    
    public string aname{set;get;}
    public string aphone{set;get;}
    public string acity{set;get;}
    public list<account>arecs{set;get;}
    
    public void mi()
    {
        integer i=[select count() from account where name=:aname];
        if(i==0)
        {
        account ac=new account();
        ac.Name=aname;
        ac.Phone=aphone;
        ac.BillingCity=acity;
        
        insert ac;
        apexpages.Message msg=new apexpages.Message(apexpages.Severity.CONFIRM , i+'Record(s) inserted Sucessfully');
        apexpages.addMessage(msg);
        }
        else
        {
             apexpages.Message msg2=new apexpages.Message(apexpages.Severity.ERROR,i+'Record(s) Already Exist');
            apexpages.addMessage(msg2);
            
        }
        arecs=[select name,phone,billingcity from account where name=:aname];
    }
    public void md()
    {
        list<account>ls=[select name,phone,billingcity from account where name=:aname];
        delete ls;
        apexpages.Message msg=new apexpages.Message(apexpages.Severity.WARNING , ls.size() + 'RecordC(s) Deleted Succesfully');
        apexpages.addMessage(msg);
        arecs=[select name,phone,billingcity from account where name=:aname];
     }
    
    public void mu()
    {
        list<account>ls=new list<account>();
        ls=[select name from account where name=:aname];
        for(account ac:ls)
        {
           ac.Name=aname;
            ac.Phone=aphone;
            ac.BillingCity=acity;
            ls.add(ac);
        }
        update ls;
        apexpages.Message msg=new apexpages.Message(apexpages.Severity.INFO , ls.size() + 'Record(s) Updates Succesfully');
        apexpages.addMessage(msg);
        arecs=[select name,phone,billingcity from account where name=:aname];
    }
    public void ms()
    {
        arecs=[select name,phone,billingcity from account where name=:aname];
    }
    public void mups()
    {
        list<account> ls = new list<account>();
        ls =    [select id,name from account where name = :aname];   
        integer n = ls.size();
        if( n== 0){
            account a = new account();
                    a.name = aname;
                    a.Phone = aphone;
                    a.BillingCity = acity;
                    upsert a;       // insert Record
                    n = 1;
                }
            else{
            
            for(account ac : ls){
                ac.name = aname;
                ac.Phone = aphone;
                ac.BillingCity=acity;
                upsert ac;      // Updates Record
            }
        }
            apexpages.Message mes1 = new  apexpages.Message(apexpages.Severity.CONFIRM, n + ' Record UPSERTED (Insert/Update) Successfully');          
            apexpages.addMessage(mes1);           
            arecs = [select id,name,phone,billingcity from account where name =: aname];        
    }
 
    
}

Can someone explain me 

Hi,

I am accessing custom setting values in my apex code and its working fine. When I am calling it through test class then No values gets in from Custom Setting. It always blank in test class. Can somebody help me to understand why custom settings values are not accessible in test class.

 

Thanks,

Vinod Kumar