• Aneesh Alumalla
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi ,
I have created one Apex class and its VF page.
I have 2 fields in VF page, CITY and Phone.
Target: To update the Phone of the Account whose City is given City with the given phone number.

I have created everything and update is working perfectly.
But I wanted to add a message if the update is failed. and also if the update is success.

Here is my code:
Apex Class:
public class D2 {
    public String city{get;set;}
    public String phn{get;set;}
    public boolean show{get;set;}
    public D2(){
       
    }
    public void updatePhoneNum(){
        List<account> ac = new List<account>();
        List<account> ac1 = new List<account>();
        ac =[Select name, phone, Status__c, Gender__c, BillingCity from Account where BillingCity =:city];        
        for(Account a : ac){
               a.phone =phn;
            a.Status__c = 'In Progress';
            a.Gender__c = 'Male';       
        }
        update ac1; 
    }
}

Vf Page:

<apex:page controller="D2" >
    <apex:form>
        <apex:pageBlock title=" To Update the phone number of Accounts whose City is provided">
            <apex:pageMessages />
            <apex:pageBlockSection title="Provide the details" columns="1">
                <div align = "center">
                <apex:inputText  label="City" value ="{!city}" />
                <apex:inputText  label="Phone Number" value ="{!phn}" />
                    </div>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection >
                <div align = "center">
                <apex:commandButton  style ="float:centre" value ="Update" action ="{!updatePhoneNum}"/>
                </div>
            </apex:pageBlockSection>
                
        </apex:pageBlock>
    </apex:form>
</apex:page>

Please assist
Hi ,
I have created one Apex class and its VF page.
I have 2 fields in VF page, CITY and Phone.
Target: To update the Phone of the Account whose City is given City with the given phone number.

I have created everything and update is working perfectly.
But I wanted to add a message if the update is failed. and also if the update is success.

Here is my code:
Apex Class:
public class D2 {
    public String city{get;set;}
    public String phn{get;set;}
    public boolean show{get;set;}
    public D2(){
       
    }
    public void updatePhoneNum(){
        List<account> ac = new List<account>();
        List<account> ac1 = new List<account>();
        ac =[Select name, phone, Status__c, Gender__c, BillingCity from Account where BillingCity =:city];        
        for(Account a : ac){
               a.phone =phn;
            a.Status__c = 'In Progress';
            a.Gender__c = 'Male';       
        }
        update ac1; 
    }
}

Vf Page:

<apex:page controller="D2" >
    <apex:form>
        <apex:pageBlock title=" To Update the phone number of Accounts whose City is provided">
            <apex:pageMessages />
            <apex:pageBlockSection title="Provide the details" columns="1">
                <div align = "center">
                <apex:inputText  label="City" value ="{!city}" />
                <apex:inputText  label="Phone Number" value ="{!phn}" />
                    </div>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection >
                <div align = "center">
                <apex:commandButton  style ="float:centre" value ="Update" action ="{!updatePhoneNum}"/>
                </div>
            </apex:pageBlockSection>
                
        </apex:pageBlock>
    </apex:form>
</apex:page>

Please assist