• MaKSingh
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hello Experts,

I'm new to visualforce page and trying to explore things by doing some tests. I'd like to ask for your help on how to I'll be able to edit records from a pageBlockTable in visualforce.

Here's how my page look like to start with.

Add Account Tab : Where I can save account (Shows accounts that are saved below)
User-added image

Account Details Tab: This shows all accounts I created (This is where my question is)

User-added image
 

Right now, I have the Edit and Delete commandLink but doesn't do anything yet. I don't know where to start here.

What I'd like to do is to be able to edit or delete the Account from those commandLinks.

Can I please have the Idea how to achieve that?

Thanks a in advance!

--MY CODES HERE--

=====Page=======
 

<apex:page controller="TheController" sidebar="false">
  <apex:form >
      <apex:pageBlock >
          <apex:tabPanel >
       
              <apex:tab label="Add Account">
                  <apex:pageBlock title="Input Account Details"> <br/>
                      <b>&nbsp;&nbsp;Account Name </b>
                      <br/>*&nbsp;<apex:inputText value="{!newAccount.name}"/>
                      <br/><apex:messages />
                      <p/><br/><b>&nbsp;&nbsp;Industry </b>
                      <br/>&nbsp;&nbsp;<apex:inputField value="{!newAccount.Industry}"/>
                      <p/><br/><b>&nbsp;&nbsp;Type</b><br/>
                      &nbsp;&nbsp;<apex:inputField value="{!newAccount.Type}"/>
                      <p/><br/><b>&nbsp;&nbsp;Phone </b><br/>
                      &nbsp;&nbsp;<apex:inputField value="{!newAccount.Phone}"/>
                      <p/>
                      <apex:commandButton value="Add Account" action="{!addAccount}" reRender="myPage"/>
                      
                  </apex:pageBlock>
                      
                  <apex:pageBlock title="Added Accounts" id="myPage">
                      <apex:pageBlockTable value="{!AddedAccountsList}" var="addedAccounts">
                          <apex:column value="{!addedAccounts.name}"/>
                          <apex:column value="{!addedAccounts.Industry}"/>
                          <apex:column value="{!addedAccounts.Type}"/>
                          <apex:column value="{!addedAccounts.Phone}"/>
                      </apex:pageBlockTable>
                  </apex:pageBlock>
              </apex:tab>
              
              <apex:tab label="Account Details">
                  <apex:pageBlockSection columns="1" >
                      <apex:pageBlockTable value="{!ViewAccounts}" var="acc" >
                          <apex:column ><apex:commandLink action="{!EditAccount}" value="Edit"/></apex:column>
                          <apex:column ><apex:commandLink action="{!DeleteAccount}" value="Delete"/></apex:column>
                          <apex:column value="{!acc.name}" />
                          <apex:column value="{!acc.Industry}"/>
                          <apex:column value="{!acc.Type}"/>
                          <apex:column value="{!acc.Phone}"/>
                      </apex:pageBlockTable>
                  </apex:pageBlockSection>
              </apex:tab>
              
          </apex:tabPanel>
      </apex:pageBlock>
  </apex:form>
</apex:page>
 


=====Controller=======

public class TheController {

    public Account newAccount{get;set;}
    list<Account> addedAccounts;
    
    public TheController(){
        newAccount = new Account();
        addedAccounts = new list<Account>();
    }

    public List<Account> getViewAccounts(){
        List<account> lstAccount = [select id, name, industry, type, phone from account where createdById =:userinfo.getuserId() order By CreatedDate desc];
        return lstAccount;
    }
    
    public void addAccount(){
            
             try {
                 addedAccounts.add(newAccount.clone());
                 insert newAccount.clone();
             } catch (Exception e) {
                 ApexPages.addMessages(e);
             }
             
    }
    
    public List<account> getAddedAccountsList(){
        return addedAccounts;
    }
    
    public void EditAccount(){
    
    }
    public void DeleteAccount(){
    }
}
So we like to have a time dependent email alert, for example 2 weeks before close date. The email need to send to the children records email fields, also different children would see their own data which has a link. I don't think the email template can do it. I need to have a custom apex code, but I don't know how time dependent workflow can call my apex code.