• Anuja Joshi 16
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hello
        On click command button on parent window new popup window is opened.from popup window access csv file.when click on OK button from popup window i want to refresh pageblock table in parent table.please tell how to do it.your help is most appreciated.Thanks in advance.
code for popup window is given below:

<apex:page sidebar="false" showHeader="false" StandardController="Account" extensions="UploadCSVFileController">
    <apex:sectionHeader title="-{!Account.name}" subtitle="{!cp.Month_Year__c}"/>
        <apex:form >
            <script>
                function closeuploadpage()
                {
                    window.close();
                }
            </script>
            function closeandrefresh()
            {  
               
                window.opener.location.href='/apex/monthlydeductionspage?id={!account.id}';
                window.close();
            }
            <apex:pageBlock >
                <apex:pageBlocksection >
                    <apex:pageBlockSectionItem >              
                        <apex:inputFile value="{!CsvFileBody}" fileName="{!csvfile}"/>
                    </apex:pageBlockSectionItem>    
                </apex:pageBlocksection>
                <apex:actionRegion>
                    <apex:commandButton action="{!importcsvfile}" value="OK" oncomplete="closeandrefresh();"/>
                </apex:actionRegion>
                <apex:commandButton value="Cancel" onclick="closeuploadpage();"/>
                </apex:pageBlock>
        </apex:form>    
</apex:page>
Hello
         I am new in SF. I have create a window using that window I want to upload csv file in "Upload Data" Custom object.The all fields have different data type like Number,Text and Currency.Problem is occured when values assigned to Number and currency field.for PF wages and ESI Wages field i took currency data Type.here pf wages value is assigned without error but for esiwages error occoured i.e.invalid decimal(at time of assign convert it into Decimal ).And Days Worked field took Number Datatype at time of assign convert it into Integer .
Invalid integer: 22
Error is in expression '{!importcsvfile}' in component <apex:commandButton> in page uploadcsvfilepage: Class.UploadCSVFileController.importcsvfile: line 50, column 1


.Below my code is given.Please help.



VF page
<apex:page sidebar="false" showHeader="false" StandardController="Account" extensions="UploadCSVFileController">
    <apex:sectionHeader title="-{!Account.name}" subtitle="{!cp.Month_Year__c}"/>
        <apex:form >    
            <apex:pageBlock >
                <apex:pageBlocksection >               
                    <apex:inputFile value="{!CsvFileBody}" fileName="{!csvfile}"/>
                </apex:pageBlocksection>
                <apex:pageBlocksection >            
                    <apex:commandButton value="OK" action="{!importcsvfile}"/>
                    <apex:commandButton value="Cancel" onclick="window.close()"/>
                </apex:pageBlocksection>
            </apex:pageBlock>
        </apex:form>    
</apex:page>



Controller is:

public class UploadCSVFileController
{
    private final Account acct;
    public id accountid{get;set;}
    public string Mon{get;set;}
    public string Yrs{get;set;}
    Public final Period__c cp{get;set;}
    Public String Monthinname;
    Public String MonthWithZero;
    public Blob CsvFileBody{get;set;}
    public String csvfile{get;set;}
    public String[] csvFileLines{get;set;}
    public list<Upload_Data__c> Uploadfilelist{get;set;}
    public UploadCSVFileController(apexpages.standardcontroller stdcontroller)
    {
        system.debug('Inside Constructor');
        csvfileLines=new String[]{};
        //csvFileLines = new String[]{};
        Uploadfilelist=new list<Upload_Data__c>();
        acct=(Account)stdcontroller.getrecord();
        accountid=acct.id;
        System.debug('The account id'+accountid);
        Mon = ApexPages.currentPage().getParameters().get('mm');
        Yrs = ApexPages.currentPage().getParameters().get('yyyy');
        System.debug('The current month is:'+Mon);
        System.debug('The current year is:'+Yrs);   
        MonthWithZero=Mon.leftpad(2,'0');
        string monthyear=MonthWithZero+'-'+yrs;
        cp=[select id,name,Month_Year__c from Period__c WHERE name=:monthyear];
        system.debug(cp);
        System.debug(cp.Month_Year__c);
    }
    public void importcsvfile()
    {
        csvfile=CsvFileBody.ToString();
        csvFileLines=csvfile.split('\n');
        
            for(Integer i=1;i<csvFileLines.size();i++)
            {
                Upload_Data__c UD=new Upload_Data__c() ;
                string[] csvRecordData = csvFileLines[i].split(',');
                UD.Employee_PF_No__c = csvRecordData[0] ;             
                UD.Employee_ESI_No__c = csvRecordData[1];
                UD.First_Name__c = csvRecordData[2];
                UD.Middle_Name__c = csvRecordData[3];   
                UD.Last_Name__c = csvRecordData[4];
                UD.PF_Wages__c=decimal.valueOf(csvRecordData[5]);
                //error is here for following 2 fields
                UD.ESI_Wages__c=decimal.valueOf(csvRecordData[6]);
                UD.Days_Worked__c=Integer.valueOf(csvRecordData[7]);                                                                             
                Uploadfilelist.add(UD);
            }
            try
            {
                insert Uploadfilelist;
            }
            catch(Exception e)
            {
                System.debug(e);
            }       
    }
    
}
Hello
        I am new in Salesforce .I created VF page controller class.In that I got the month year and want to convert month which is in Number format into string so for this I wrote the method Getmonth() but having error.Please help.
public class UploadCSVFileController
{
    private final Account acct;
    public id accountid{get;set;}
    public string Mon{get;set;}
    public string Yrs{get;set;}
    Public Period__c cp;
    Public String Monthinletter;
    Public String MonthWithZero;
    public UploadCSVFileController(apexpages.standardcontroller stdcontroller)
    {
        system.debug('Inside Constructor');
        acct=(Account)stdcontroller.getrecord();
        accountid=acct.id;
        System.debug('The account id'+accountid);
        Mon = ApexPages.currentPage().getParameters().get('mm');
        Yrs = ApexPages.currentPage().getParameters().get('yyyy');
        System.debug('The current month is:'+Mon);
        System.debug('The current year is:'+Yrs);   
        MonthWithZero=Mon.leftpad(2,'0');
        string monthyear=MonthWithZero+'-'+yrs;
        cp=[select id,name,Month_Year__c from Period__c WHERE name=:monthyear];
        system.debug(cp);
    }
    public String GetMonth(MonthWithZero)
    {
        if(MonthWithZero=='01')
        {
            Monthinletter='January';
            return Monthinletter;    
        }    
    }
}
Hello
        I am new in Salesforce .I created VF page controller class.In that I got the month year and want to convert month which is in Number format into string so for this I wrote the method Getmonth() but having error.Please help.
public class UploadCSVFileController
{
    private final Account acct;
    public id accountid{get;set;}
    public string Mon{get;set;}
    public string Yrs{get;set;}
    Public Period__c cp;
    Public String Monthinletter;
    Public String MonthWithZero;
    public UploadCSVFileController(apexpages.standardcontroller stdcontroller)
    {
        system.debug('Inside Constructor');
        acct=(Account)stdcontroller.getrecord();
        accountid=acct.id;
        System.debug('The account id'+accountid);
        Mon = ApexPages.currentPage().getParameters().get('mm');
        Yrs = ApexPages.currentPage().getParameters().get('yyyy');
        System.debug('The current month is:'+Mon);
        System.debug('The current year is:'+Yrs);   
        MonthWithZero=Mon.leftpad(2,'0');
        string monthyear=MonthWithZero+'-'+yrs;
        cp=[select id,name,Month_Year__c from Period__c WHERE name=:monthyear];
        system.debug(cp);
    }
    public String GetMonth(MonthWithZero)
    {
        if(MonthWithZero=='01')
        {
            Monthinletter='January';
            return Monthinletter;    
        }    
    }
}