function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
muni kmuni k 

visualforce page and apex controller for new custom object(account_user),the fields are account name,account number,account id,email,phone,fax,country.Please provide the code for this.Here account number is unique.

praveen murugesanpraveen murugesan
Hi Vasu,

Please post the code if you have tried any thing. we can correct that.

Thanks.
muni kmuni k
Hi Praveen,

Thank u for your response....

Please ignore previous object(account_user)...

Now i need a validation for below of the code...It could won't allow the duplicates values of name and account number when we are insert the values of batchfile(CSV file) or individually...plz help me

Custom_Account.vfp:

<apex:page standardController="Account">

    <apex:form >

        <apex:pageBlock title="Edit Account for {!$User.FirstName}">

            <apex:pageMessages />

            <apex:pageBlockButtons >

                <apex:commandButton value="Save" action="{!save}"/>

            </apex:pageBlockButtons>

            <apex:pageBlockSection >

                <apex:inputField value="{!account.name}"/>
                  <apex:inputField value="{!account.accountnumber}"/>
                   <apex:inputField value="{!account.annualrevenue}"/>
                    <apex:inputField value="{!account.industry}"/>
                    <apex:inputField value="{!account.accountsource}"/>
                     <apex:inputField value="{!account.numberofemployees}"/>
                      <apex:inputField value="{!account.naicscode}"/>
                     <apex:inputField value="{!account.phone}"/>
                     <apex:inputField value="{!account.fax}"/>
                      <apex:inputField value="{!account.website}"/>

            </apex:pageBlockSection>

        </apex:pageBlock>

    </apex:form>

</apex:page>

custable.apxc:

public with sharing class custable {

     public string recid{get;set;}

   public string row{ get; set;}
   public list<Account> Acclst{get;set;}
   Public Account A;

   public List<Contact> contacts {get; set;}

   public custable(){

   Acclst = [select Id,Name from Account ];
    }

   public pagereference deleteAccount()
   {
   account ac=[select id,name from account where id=:recid];
   delete ac;


   pagereference ref =new pagereference('/apex/custable');
   ref.setredirect(true);
   return ref;

  }

  public void setupContacts()
  {
     contacts=[select id, FirstName, LastName from Contact where AccountId=:recId];
      }
   }


customVFpage.vfp:
<apex:page controller="custable" sidebar="false">
    <apex:form >
        <apex:pageBlock title="AccountTable">
            <apex:pageBlockTable value="{!Acclst}" var="A">
            <apex:column headerValue="EDIT">
            <apex:outputLink value="/{!A.id}/e" id="edit">Edit</apex:outputLink>
            </apex:column>
            <apex:column headerValue="DELETE">
            <apex:commandLink action="{!deleteAccount}" onclick="if(!confirm('Are you sure?')) return false;">Del
            <apex:param value="{!A.Id}" name="idToDel" assignTo="{!recid}"/>
            </apex:commandLink>
            </apex:column>
            <apex:column headerValue="NAME OF THE ACCOUNT" > 
            <apex:commandLink value="{!A.Name}" action="{!setupContacts}"  rerender="CONT">
              <apex:param value="{!A.Id}" name="idForConts" assignTo="{!recid}"/>
            </apex:commandLink>
            </apex:column>  
            <apex:column value="{!A.Id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
  
    <apex:pageBlock title="Contacts" id="CONT">
      <apex:pageBlockTable value="{!contacts}" var="contact" >
       
        <apex:column value="{!contact.FirstName}"/>
        <apex:column value="{!contact.LastName}"/>

          
      </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
</apex:page>

importDataFromCSVController:

public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvfile2{get;set;}
public String[] csvFileLines{get;set;}
public List<account> acclist{get;set;}
  public importDataFromCSVController(){
    csvFileLines = new String[]{};
    acclist = New List<Account>(); 
  }
  
  public void importCSVFile(){
       try{
           csvfile2 = csvFileBody.toString();
           csvFileLines = csvfile2.split('\n'); 
            
           for(Integer i=1;i<csvFileLines.size();i++){
               Account accObj = new Account() ;
               string[] csvRecordData = csvFileLines[i].split(',');
               accObj.name = csvRecordData[0] ;             
               accObj.accountnumber = csvRecordData[1];
               accObj.Industry = csvRecordData[2]; 
               accObj.accountsource = csvRecordData[3];                                                                             
               accObj.phone = csvRecordData[4];                                                                           

               accObj.fax = csvRecordData[5];  
               accObj.website = csvRecordData[6];  

               acclist.add(accObj);   
           }
        insert acclist;
        }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importin data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
}