• Wahib_Idris
  • NEWBIE
  • 0 Points
  • Member since 2013

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

Error: 554 System.SObjectException: Invalid field FirstName  for Account  Class.myHandler.handleInboundEmail

 

I am parsing CSV in email service. My CSV has four columns 

 

FirstName  LastName Type AnnualRevenue Test  AccountWaa GPO 1000

 

Below is my code snippet 

 

global class myHandler implements Messaging.InboundEmailHandler {
    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
    
    System.Debug('Debug :: Mail Checking' + email);
    Messaging.InboundEmail.TextAttachment[] tAttachments = email.textAttachments;
    
    list<Account> lstAccount = new List<Account>(); // list of accounts.
    
    String csvbody='';
    
    List<List<String>> allFields = new List<List<String>>(); // list of rows in csv
    List<String> lines = new List<String>(); // Rows of csv
    list<String> headers = new List<String>();    // field names   
    List<String> fields = new List<String>(); // list of fields 
    
    if(tAttachments !=null){
        for(Messaging.InboundEmail.TextAttachment btt :tAttachments){
            if(btt.filename.endsWith('.csv')){
                csvbody = btt.body;
                // process csv body here
                System.Debug('Debug ::: CSV as a string' + csvbody);
                try {
                    lines = csvbody.split('\n');
                    System.Debug('Debug ::: Split csv ' + lines);
                    System.Debug('Debug ::: Split csv size' + lines.size());
                } catch (System.ListException e) {
                    System.debug('Limits exceeded?' + e.getMessage());
                }
            }
        
        }
        
        integer rowNumber = 0;
        
       
        for(String line : lines) {
        // check for blank CSV lines (only commas) 
            if (line.replaceAll(',','').trim().length() == 0) break;
            
            fields = line.split(',', -1);
       
            
            
            System.Debug('Debug ::: line after replace :: ' + line);
            System.Debug('Debug ::: fields csv ' + fields );
            System.Debug('Debug ::: fields csv size' + fields.size() );
            
            allFields.add(fields);
            if(rowNumber == 0)
            {
                // for getting the field names. 
                for(list<String> rows : allFields){    
                    for(String header : rows){
                        headers.add(header);
                    }
                 break;
                }
               
                rowNumber++;
                continue;
            }
        
        }
        
        System.Debug('Debug ::: before removing all fields ' + allFields);
        System.Debug('Debug ::: after removing all fields ' + allFields);
        System.Debug('Debug ::: all fields size' + allFields.size());
        
        
        
        System.Debug('Debug :: Check account' + headers);
        System.Debug('Debug :: Check account' + lstAccount);
       
        
        for(Integer i = 1 ; i < lines.size() ; i++){
            Account a = new Account();
            
            System.Debug('Debug :: first header value ' + headers.get(0));
            
            System.debug('Debug :: Field Name ::' + headers[0]);
            System.debug('Debug :: Field Value ::' + allFields[i][0]);
            //Schema.Account.Name
            
            a.put(headers[0] , allFields[i][0]);
            a.put(headers[1] , allFields[i][1]);
            a.put(headers[2] , allFields[i][2]);
            a.put(headers[3] , allFields[i][3]);
            
            lstAccount.add(a);
        }
            
       
        System.Debug('Debug :: Check account' + lstAccount);
        insert lstAccount;
        
    }
    
    return result;
      }
  }

 

 a.put(headers[0] , allFields[i][0]); // I am getting invalid field 'FirstName' error on this line of code  although debug log is showing correct value.
 

a.put('FirstName', all Fields[i][0]); // this is working perfect

I want to customize my standard conversion page by URL hacking I am able to check the opportunity checkbox but can't find this issue .

Requirement :
 
My requirement is that I have accounts present in system and the lead is always converted with existing account. I don't want to allow user to create new account in salesforce so there is no need of that create new picklist value.

 There is a picklist of Account in lead conversion page what I exactly want is :

1) I want to show only one picklist value that is 'Attach to Existing: BigLife Inc.'
2) Ability to associate it with that account.
2) Make that field read-only so that user can't able to change it.

 

Below is my script

 

window.location.href="/lead/leadconvert.jsp?nooppti=1&id={!Lead.Id}&RetURL=/{!Lead.Id}";

Error: 554 System.SObjectException: Invalid field FirstName  for Account  Class.myHandler.handleInboundEmail

 

I am parsing CSV in email service. My CSV has four columns 

 

FirstName  LastName Type AnnualRevenue Test  AccountWaa GPO 1000

 

Below is my code snippet 

 

global class myHandler implements Messaging.InboundEmailHandler {
    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
    
    System.Debug('Debug :: Mail Checking' + email);
    Messaging.InboundEmail.TextAttachment[] tAttachments = email.textAttachments;
    
    list<Account> lstAccount = new List<Account>(); // list of accounts.
    
    String csvbody='';
    
    List<List<String>> allFields = new List<List<String>>(); // list of rows in csv
    List<String> lines = new List<String>(); // Rows of csv
    list<String> headers = new List<String>();    // field names   
    List<String> fields = new List<String>(); // list of fields 
    
    if(tAttachments !=null){
        for(Messaging.InboundEmail.TextAttachment btt :tAttachments){
            if(btt.filename.endsWith('.csv')){
                csvbody = btt.body;
                // process csv body here
                System.Debug('Debug ::: CSV as a string' + csvbody);
                try {
                    lines = csvbody.split('\n');
                    System.Debug('Debug ::: Split csv ' + lines);
                    System.Debug('Debug ::: Split csv size' + lines.size());
                } catch (System.ListException e) {
                    System.debug('Limits exceeded?' + e.getMessage());
                }
            }
        
        }
        
        integer rowNumber = 0;
        
       
        for(String line : lines) {
        // check for blank CSV lines (only commas) 
            if (line.replaceAll(',','').trim().length() == 0) break;
            
            fields = line.split(',', -1);
       
            
            
            System.Debug('Debug ::: line after replace :: ' + line);
            System.Debug('Debug ::: fields csv ' + fields );
            System.Debug('Debug ::: fields csv size' + fields.size() );
            
            allFields.add(fields);
            if(rowNumber == 0)
            {
                // for getting the field names. 
                for(list<String> rows : allFields){    
                    for(String header : rows){
                        headers.add(header);
                    }
                 break;
                }
               
                rowNumber++;
                continue;
            }
        
        }
        
        System.Debug('Debug ::: before removing all fields ' + allFields);
        System.Debug('Debug ::: after removing all fields ' + allFields);
        System.Debug('Debug ::: all fields size' + allFields.size());
        
        
        
        System.Debug('Debug :: Check account' + headers);
        System.Debug('Debug :: Check account' + lstAccount);
       
        
        for(Integer i = 1 ; i < lines.size() ; i++){
            Account a = new Account();
            
            System.Debug('Debug :: first header value ' + headers.get(0));
            
            System.debug('Debug :: Field Name ::' + headers[0]);
            System.debug('Debug :: Field Value ::' + allFields[i][0]);
            //Schema.Account.Name
            
            a.put(headers[0] , allFields[i][0]);
            a.put(headers[1] , allFields[i][1]);
            a.put(headers[2] , allFields[i][2]);
            a.put(headers[3] , allFields[i][3]);
            
            lstAccount.add(a);
        }
            
       
        System.Debug('Debug :: Check account' + lstAccount);
        insert lstAccount;
        
    }
    
    return result;
      }
  }

 

 a.put(headers[0] , allFields[i][0]); // I am getting invalid field 'FirstName' error on this line of code  although debug log is showing correct value.
 

a.put('FirstName', all Fields[i][0]); // this is working perfect

I want to customize my standard conversion page by URL hacking I am able to check the opportunity checkbox but can't find this issue .

Requirement :
 
My requirement is that I have accounts present in system and the lead is always converted with existing account. I don't want to allow user to create new account in salesforce so there is no need of that create new picklist value.

 There is a picklist of Account in lead conversion page what I exactly want is :

1) I want to show only one picklist value that is 'Attach to Existing: BigLife Inc.'
2) Ability to associate it with that account.
2) Make that field read-only so that user can't able to change it.

 

Below is my script

 

window.location.href="/lead/leadconvert.jsp?nooppti=1&id={!Lead.Id}&RetURL=/{!Lead.Id}";