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
PavanReddyPavanReddy 

Illegal assignment error?

Hi guys

 

How to handle this type of error?

 

Error: UploadDoc Compile Error: Illegal assignment from String to Decimal at line 47 column 5

kiranmutturukiranmutturu

you are assinging the wrong type to another type.. if you are assigining a string to decimal then you need to do some thing like this

 

String temp = '12.4567';

Decimal myDecimal = decimal.valueOf(temp);
PavanReddyPavanReddy

Thx a lot kiran for ur reply

 

Below  is my sample code. when i was trying to access these  fields i am getting illegal statement error so i commented.

while declaring the fileds i have declared for this datatype as 'Number '.

 

Plz have a look  below code once

 

plz do the needfull

thx in advance...

 

public Pagereference ReadFile()
    {
        nameFile=contentFile.toString();
        filelines = nameFile.split('\n');
        accstoupload = new List<property__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
           
            property__c pt = new property__c();
         
    //pt.property_value__c= inputvalues[1];
    //pt.property_zip__c= inputvalues[2];

 //pt.land_value__c= inputvalues[3];

 

}

 

kiranmutturukiranmutturu

hard to say like this with out code...

PavanReddyPavanReddy
public class UploadDoc
{
Public Document mydoc;
Public Document getmyimage()
    {
        mydoc = new Document();
        return mydoc;
    }
    Public Pagereference Savedoc()
    {
        mydoc.folderid = UserInfo.getUserId(); 
                        insert mydoc;
        return NULL;
    }   

    public String uploadedPropertys { get; set; }




    public PageReference fileAccess() {
        return null;
    }


public UploadDoc(){

}
    public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    String[] filelines = new String[]{};
    List<property__c> accstoupload;
    
    public Pagereference ReadFile()
    {
        nameFile=contentFile.toString();
        filelines = nameFile.split('\n');
        accstoupload = new List<property__c>();
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
            
            property__c pt = new property__c();
         
                          
    //pt.county_accno__c= inputvalues[0];
    //pt.county_acct__c= inputvalues[1];
    //pt.county_filerecieved__c= inputvalues[2];
    pt.county_name__c= inputvalues[3];
    pt.importby__c= inputvalues[4]  ;
    //pt.importtimestamp__c= inputvalues[5];
    //pt.improvement_value__c= inputvalues[6];
    pt.ineligible_reason__c= inputvalues[7];
    //pt.land_value__c= inputvalues[8];
    pt.owner_id__c= inputvalues[9];
    pt.owner_identifier__c= inputvalues[10];
    //pt.property_acres__c= inputvalues[11];
    pt.property_address__c= inputvalues[12];
    //pt.property_calc_total_delinquent__c= inputvalues[13];
    pt.property_city__c= inputvalues[14];
    pt.property_eligibile__c= inputvalues[15];
    pt.property_exemptions__c= inputvalues[16];
    //pt.property_feesinterest__c= inputvalues[17];
    //pt.property_id__c= inputvalues[18];
    //pt.property_LTV__c= inputvalues[19];
    //pt.property_maxdelinquent_year__c= inputvalues[20];
    //pt.property_mindeliquent_year__c= inputvalues[21];
    //pt.property_noofsubdivisions__c= inputvalues[22];
    //pt.property_number__c= inputvalues[23];
    pt.property_part_pay_flag__c= inputvalues[24];
    pt.property_state__c= inputvalues[25];
    pt.property_street__c= inputvalues[26];
    //pt.property_total_delinquent__c= inputvalues[27];
    //pt.property_total_due__c= inputvalues[28];
    //pt.property_total_levydelinquent__c= inputvalues[29];
    //pt.property_value__c= inputvalues[30];
    //pt.property_zip__c= inputvalues[31];
    pt.propertytype__c= inputvalues[32];


            
          

            accstoupload.add(pt);
        }
        try{
        insert accstoupload;
        }
        catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');
            ApexPages.addMessage(errormsg);
        }    
        return null;
    }
    
    public List<property__c> getuploadedAccounts()
    {
        if (accstoupload!= NULL)
            if (accstoupload.size() > 0)
                return accstoupload;
            else
                return null;                    
        else
            return null;
    }
       
    public static testMethod void testReadFile1() {
    
    Document lstDoc = [select id,name,Body from Document where name = 'test'];
         
        // System.Debug('DOC NAME :: '+lstDoc.name);   
         //System.Debug('DOCBODY :: '+lstDoc.Body);  
       UploadDoc file=new UploadDoc();
       Blob content= lstDoc.Body;
     file.nameFile=content.toString();
    }
    
    public static testMethod void testReadFile2() {
        
    }
          
}

 

------VFpage--------

<apex:page controller="UploadDoc">
<apex:form >
  <apex:sectionHeader title="Import DTR"/>
    <apex:pageblock >
  <apex:panelGroup >
  <center>   
Import DTR File   <apex:inputfile value="{!myimage.body}" filename="{!myimage.Name}" /><br></br><P></P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(file formats .txt,.csv,.tsv,.xls)<BR/><BR/>
    

       <apex:commandButton action="{!ReadFile}" value="submit"/>
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;          
       <apex:commandButton action="{cancel}" value="cancel"/>
        </center>

      </apex:panelGroup>
  </apex:pageblock>   
</apex:form> 
</apex:page>

 

PavanReddyPavanReddy

Plz find below  code kiran..

 

thx in advance

kiranmutturukiranmutturu

after u getting the list of values from the split you need to assing the values from list to the some object fileds by respecting their type....so when ever u are  assigining a value please take care about the target field type ....

 

//pt.property_number__c  = integer.valueof(your string value); like this all should satisfy also you should check for whether the list is having values or not.....using list methods....

PavanReddyPavanReddy

thx for ur reply kiran..could u please tel me ur  gmail id?

salonidhuria1.3964283414155535E12salonidhuria1.3964283414155535E12
Amazing to the point brief answer @kiran_mutturu
llisallisa
Hello, 
i am getting
" Error: Compile Error: Illegal assignment from String to Decimal "
Why this is so?
To avoid this error i am using "decimal.valueof(csvRecordData[1]);"
it gives the reverse error " Error: Compile Error: Illegal assignment from Decimal to String ".


public void importCSVFile(){
       try{
           csvAsString = csvFileBody.toString();
           csvFileLines = csvAsString.split('\n'); 
            
           for(Integer i=1;i<csvFileLines.size();i++){
               Distributor_Prior_Sales__c prisale = new Distributor_Prior_Sales__c() ;
               string[] csvRecordData = csvFileLines[i].split(',');
               prisale.SMS_Year__c= csvRecordData[0] ;             
               prisale.SMS_sales_amount__c= csvRecordData[1];
               prisale.Exhibit_A_Customer__c= csvRecordData[2];
               prisale.Calculation_Type__c= csvRecordData[3];                                                                        
               accon.add(prisale);   
           }
        //insert acclist;
        }
        catch (Exception e)
        {
            ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured while importing data Please make sure input csv file is correct');
            ApexPages.addMessage(errorMessage);
        }  
  }
azar khasimazar khasim
Hello Guys,

I have a error in below trigger code.
*********************************************************
trigger AccountNameUpdate on Booking_Link__c (before insert, before update) {
    List<Account> accountList = new List<Account>();
    Decimal CustomNumber;
    for(Booking_Link__c bl : Trigger.new)
    {       
6th       CustomNumber = bl.Customer_Number__c;
    }
8th    accountList = [Select Id, OwnerId, Customer_Number__pc from Account where Customer_Number__pc =:CustomNumber ];
    for(Booking_Link__c bl : Trigger.new)
    {
        for(Account a : accountList)
        {
           if(bl.Customer_Number__c == a.Customer_Number__pc)
            {
                bl.Account__c = a.Id;
                bl.OwnerId = a.OwnerId;
            }
        }
    }  
}
*****************************************************************************
Line 6:  CustomNumber = bl.Customer_Number__c;
Line 8: accountList = [Select Id, OwnerId, Customer_Number__pc from Account where Customer_Number__c =:CustomNumber ];

In Line 8 i have changed the bold one from Customer_Number__c to Customer_Number__pc.
why because we have the Customer Number field API as above because we are using PersonAccount.

Please help me from these errors.

Errors:

Line 6: Illegal assignment from String to Decimal
Line 8: 
Customer_Number__pc from Account where Customer_Number__c =:CustomNumber
                                       ^
ERROR at Row:1:Column:60
No such column 'Customer_Number__c' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.



Guys, Please help me out from this.

Thanks and Regards,
Azar Khasim.