• Anirban Saha 8
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi
I am new in apex coading and currently looking for a help on a particular scenario. I am trying to update an existing record when I am creating a record on that same object.
Example: I have a custom object associated with an account and only one active record can be present in that custom object. Let say there is an active record present in that object already and now I am creating another record in that particular object. On the creation of the new record will automatically deactivate the previous record.

Thanks in advance
Hi
I am new in apex coading and currently looking for a help on a particular scenario. I am trying to update an existing record when I am creating a record on that same object.
Example: I have a custom object associated with an account and only one active record can be present in that custom object. Let say there is an active record present in that object already and now I am creating another record in that particular object. On the creation of the new record will automatically deactivate the previous record.

Thanks in advance
Hi All,

I have imported the list of accounts in CSV formate in visualforce page. i have 2 tasks.
1. I want to upload only 5 account records if it is more than 5 it should show the error message
2. What are the records i got in visual force page should save in account object once i click on save button in visual force page. please suggest.

code is below..

VisualforcePage:
<apex:page controller="importDataFromCSVController">
    <apex:form >
        <apex:pagemessages />
        <apex:pageBlock >
            <apex:pageBlockSection > 
                  <apex:inputFile value="{!csvFileBody}"  filename="{!csvAsString}"/>
                  <apex:commandButton value="Upload" action="{!importCSVFile}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
        <apex:pageBlock >
           <apex:pageblocktable value="{!accList}" var="acc">
              <apex:column value="{!acc.name}" />
              <apex:column value="{!acc.AccountNumber}" />
              <apex:column value="{!acc.Type}" />
              <apex:column value="{!acc.Accountsource}" />
              <apex:column value="{!acc.Industry }" />
        </apex:pageblocktable>
     </apex:pageBlock>
   </apex:form>
</apex:page>

Apex class:
public class importDataFromCSVController {
public Blob csvFileBody{get;set;}
public string csvAsString{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{      
        
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.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.Type = csvRecordData[2];
               accObj.AccountSource = csvRecordData[3];   
               accObj.Industry = csvRecordData[4];                                                                             
               acclist.add(accObj);   
           }
        //insert acclist;
        }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'Please upload the csv format file');
            ApexPages.addMessage(errorMessage);
        }  
  }
}




 
Hi I am looking for a easy way to print or export a large Field Dependency matrix in excel. I am new to saleforce please guide me with complete details.
  • January 30, 2014
  • Like
  • 0