+ Start a Discussion
Fahad Khan 2Fahad Khan 2 

common.exception.SfdcSqlException: Invalid column index

I have a custom object and using dataloader records get loaded. on create i have a trigger that does some processing and creates/update product2 records. Most of the times trigger runs successfully but sometimes i get the following error:
RawAircraftTrigger: execution of AfterInsert

caused by: System.UnexpectedException: common.exception.SfdcSqlException: Invalid column index

Class.RawAircraftsTriggerHandler.loadCrafts: line 58, column 1
Trigger.RawAircraftTrigger: line 3, column 1

My line 58 starts as follows
for(Account a : [Select id, Name, Account_Name_2__c from Account where Name in :accountKeys OR
                         Account_Name_2__c in :accountKeys])
{
    existingaccounts.put(a.Name, a);
    existingaccounts.put(a.Account_Name_2__c, a);
}

I am clueless what could be the main issue here.
Ahmad J. KoubeissyAhmad J. Koubeissy
can you post the whole code please
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Fahad Khan,

May I suggest you please refer the below link for reference. Hope it will be helpful.

Please mark it as best answer if the information is informative.

Thanks
Rahul
 
Fahad Khan 2Fahad Khan 2
@Ahmad J. Koubeissy​
Here is my code. and it fails sometimes on line 58.
public class RawAircraftsTriggerHandler {
    
    
    
    public static void loadCrafts(List<Raw_Aircraft__c> rawAircrafts)
    {
        System.debug(rawAircrafts[0]);
        
        String errStr='';
        boolean error=false;
        
        Set<String> productKeys = new Set<String>();
        Set<String> AccountKeys = new Set<String>();
        Set<String> contactfirstNameKeys = new Set<String>();
        Set<String> contactmiddleNameKeys = new Set<String>();
        Set<String> contactlastNameKeys = new Set<String>();
        
        Map<String,Product2> existingAircrafts = new Map<String, Product2>();
        Map<String,Aircraft_Relation__c> existingAircraftRelations = new Map<String, Aircraft_Relation__c>();
        Map<String,Account> existingAccounts = new Map<String, Account>();
        Map<String,Contact> existingContacts = new Map<String, Contact>();
        
        for(Raw_Aircraft__c rec : rawAircrafts)
        {
            productKeys.add((String)rec.get('MANUF_MAKE_MODEL_SN__c'));
            AccountKeys.add((String)rec.get('COMP1NAME__c'));
            AccountKeys.add((String)rec.get('COMP2NAME__c'));
            AccountKeys.add((String)rec.get('CHPILOTCOMPNAME__c'));
            AccountKeys.add((String)rec.get('EXCBROKERCOMPNAME__c'));
            
            contactfirstNameKeys.add((String)rec.get('CONTACT1FIRSTNAME__c'));
            contactmiddleNameKeys.add((String)rec.get('CONTACT1MIDDLE__c'));
            contactlastNameKeys.add((String)rec.get('CONTACT1LASTNAME__c'));
            
            contactfirstNameKeys.add((String)rec.get('CONTACT2FIRSTNAME__c'));
            contactmiddleNameKeys.add((String)rec.get('CONTACT2MIDDLE__c'));
            contactlastNameKeys.add((String)rec.get('CONTACT2LASTNAME__c'));
            
            contactfirstNameKeys.add((String)rec.get('CHPILOTFIRSTNAME__c'));
            contactmiddleNameKeys.add((String)rec.get('CHPILOTMIDDLE__c'));
            contactlastNameKeys.add((String)rec.get('CHPILOTLASTNAME__c'));
            
            contactfirstNameKeys.add((String)rec.get('EXCBROKERFIRSTNAME__c'));
            contactmiddleNameKeys.add((String)rec.get('EXCBROKERMIDDLE__c'));
            contactlastNameKeys.add((String)rec.get('EXCBROKERLASTNAME__c'));
            
        }
        for(Product2 p : [Select id, Name,
                          (Select id, Account__c, Contact__c, Relationship__c, Aircraft__c from Aircraft_Relations__r)
                          from Product2 where Name in :productKeys])
        {
            existingAircrafts.put(p.Name, p);
            for(Aircraft_Relation__c ar : p.aircraft_Relations__r)
            {
                existingAircraftRelations.put(''+ar.Aircraft__c+ar.Account__c+ar.Contact__c+ar.Relationship__c, ar);
            }
        }
        for(Account a : [Select id, Name, Account_Name_2__c from Account where Name in :accountKeys OR
                         Account_Name_2__c in :accountKeys])
        {
            existingaccounts.put(a.Name, a);
            existingaccounts.put(a.Account_Name_2__c, a);
        }
        for(Contact c : [Select id, salutation, firstname, middlename, lastname,
                         suffix, title, email, phone, fax, mobilephone, AccountId
                         from Contact 
                         where firstName in :contactfirstNameKeys AND
                         Lastname in :contactlastNameKeys])
        {
            existingContacts.put((c.firstname == null ? '' : c.firstname)+c.lastname, c);
        } 						 
        List<Product2> updatables = new List<Product2>();
        List<Product2> insertables = new List<Product2>();
        
        List<Account> insertableAccounts = new List<Account>();
        List<Account> updatableAccounts = new List<Account>();
        
        List<Contact> insertableContacts = new List<Contact>();
        List<Contact> updatableContacts = new List<Contact>();
        
        List<Aircraft_Relation__c> insertableRelations = new List<Aircraft_Relation__c>();
        
        Set<String> aircraftsDone = new Set<String>();
        Set<String> AccountsDone = new Set<String>();
        Set<String> contactsDone = new Set<String>();
        
        for(Raw_Aircraft__c rec: rawAircrafts)
        {
            //aircrafts
            String aircraftName = (String)rec.get('MANUF_MAKE_MODEL_SN__c');
            if(aircraftName != null && aircraftName != '' && !aircraftsDone.contains(aircraftName))
            {
                aircraftsDone.add(aircraftName);
                
                Product2 craft = existingAircrafts.get(aircraftName);
                if(craft == null)
                {
                    craft = new Product2();
                    craft.Name = aircraftName;
                    craft.IsActive = true;
                    insertables.add(craft);
                }
                else
                {
                    updatables.add(craft);
                }
                //remove comment
                
                craft.Make_Type__c = rec.MAKETYPE__c;
                craft.Make_Model__c = rec.MAKE_MODEL__c;
                craft.Manufacturer__c = rec.MANUFACTURER__c;
                craft.Model__c = rec.MODEL__c;
                craft.Serial_No__c = rec.SERNBR__c;
                craft.Registration__c = rec.REGNBR__c;
                craft.Status_Jetnet__c = rec.STATUS__c;
                if(rec.ASKINGAMT__c != null)	craft.Dealers_Asking_Price__c = Double.valueOf(rec.ASKINGAMT__c.replaceAll('\\$','').replaceAll(',',''));
                if(rec.DATEPURCHASED__c != null)	craft.Date_Purchased__c = Date.parse(rec.DATEPURCHASED__c.split('/')[1]+'/'+rec.DATEPURCHASED__c.split('/')[0]+'/'+rec.DATEPURCHASED__c.split('/')[2]);
                craft.Year_Of_Manufacturer__c = rec.YEARMFG__c;
                craft.Year_of_Delivery__c = rec.YEARDLV__c;
                craft.Airport_IATA_Code__c = rec.BASEIATA__c;
                craft.ICAO_Code__c = rec.BASEICAO__c;
                craft.Airport_Name__c = rec.BASENAME__c;
                craft.Airport_City__c = rec.BASECITY__c;
                craft.Airport_State__c = rec.BASESTATE__c;
                craft.Airport_Country__c = rec.BASECOUNTRY__c;
                craft.Aircraft_Airframe_Program__c = rec.MXPROG__c;
                craft.Engine_Model_Type__c = rec.ENGMODEL__c;
                craft.X1st_Engine_SN__c = rec.ENGSERNBR1__c;
                craft.X2nd_Eng_SN__c = rec.ENGSERNBR2__c;
                craft.X3rd_Engine_SN__c = rec.ENGSERNBR3__c;
                craft.X4th_Engine_SN__c = rec.ENGSERNBR4__c;
                if(rec.AFTT__c != null)	craft.Airframe_Total_Time_hrs__c = Double.valueOf(rec.AFTT__c);
                if(rec.LANDINGS__c != null)	craft.Airframe_Cycles__c = Double.valueOf(rec.LANDINGS__c);
                if(rec.PASSGR__c != null)	craft.Total_No_Of_Seat_Jetnet__c = Double.valueOf(rec.PASSGR__c);
                if(rec.ENGTT1__c != null)	craft.X1st_Engine_Total_Time_Since_New_hrs__c = Double.valueOf(rec.ENGTT1__c);
                if(rec.ENGTT2__c != null)	craft.X2nd_Engine_Total_Time_Since_New_hrs__c = Double.valueOf(rec.ENGTT2__c);
                if(rec.ENGTT3__c != null)	craft.X3rd_Engine_Total_Time_Since_New_hrs__c = Double.valueOf(rec.ENGTT3__c);
                if(rec.ENGTT4__c != null)	craft.X4th_Engine_Total_Time_Since_New_hrs__c = Double.valueOf(rec.ENGTT4__c);
                if(rec.SMOH1__c != null)	craft.X1st_Engine_Hours_Since_Overhaul_hrs__c = Double.valueOf(rec.SMOH1__c);
                if(rec.SMOH2__c != null)	craft.X2nd_Engine_Hours_Since_Overhaul_hrs__c = Double.valueOf(rec.SMOH2__c);
                if(rec.SMOH3__c != null)	craft.X3rd_Engine_Hours_Since_Overhaul_hrs__c = Double.valueOf(rec.SMOH3__c);
                if(rec.SMOH4__c != null)	craft.X4th_Engine_Hours_Since_Overhaul_hrs__c = Double.valueOf(rec.SMOH4__c);
                if(rec.SHOT1__c != null)	craft.X1st_Engine_Total_Cycles_Since_Hot_cycl__c = Double.valueOf(rec.SHOT1__c);
                if(rec.SHOT2__c != null)	craft.X2nd_Engine_Total_Cycle_Since_Hot_cycle__c = Double.valueOf(rec.SHOT2__c);
                if(rec.SHOT3__c != null)	craft.X3rd_Engine_Tot_Cycles_Since_Hot_cycle__c = Double.valueOf(rec.SHOT3__c);
                if(rec.SHOT4__c != null)	craft.X4th_Engine_Tot_Cycles_Since_Hot_cycle__c = Double.valueOf(rec.SHOT4__c);
                if(rec.TBO1__c != null)	craft.X1st_Engine_Overhaul_Due__c = Double.valueOf(rec.TBO1__c);
                if(rec.TBO2__c != null)	craft.X2nd_Engine_Overhaul_Due__c = Double.valueOf(rec.TBO2__c);
                if(rec.TBO3__c != null)	craft.X3rd_Engine_Overhaul_Due__c = Double.valueOf(rec.TBO3__c);
                if(rec.TBO4__c != null)	craft.X4th_Engine_Overhaul_Due__c = Double.valueOf(rec.TBO4__c);
                craft.Avionics_Package_Jetnet__c = rec.AVNCS__c;
                craft.FDR_Flight_Data_Recorder_Jetnet__c = rec.FDIR__c;
                craft.A_P_Auto_Pilot_Jetnet__c = rec.AP__c;
                craft.AFIS_Jetnet__c = rec.AFIS__c;
                craft.FMS_Flight_Management_System_Jetnet__c = rec.FMS__c;
                craft.GPS_Global_Positiong_System_Jetnet__c = rec.GPS__c;
                craft.INS_Jetnet__c = rec.INS__c;
                craft.Long_Range_NAV_IRS_Inertia_Ref_Jetnet__c = rec.IRS__c;
                craft.Certification__c = rec.MAINTAINED__c;
                if(rec.IFC1YN__c != null)	craft.DAM_Damage_History__c = Boolean.ValueOf(rec.IFC1YN__c);
                if(rec.IFC3YN__c != null)	craft.RVSM__c = Boolean.ValueOf(rec.IFC3YN__c);
                craft.Engine_Program__c = rec.EMP__c;
                try
                {
                    if(rec.TCDATE__c != null)	craft.Spec_Current_Date__c = Date.parse(rec.TCDATE__c.split('/')[1]+'/'+rec.TCDATE__c.split('/')[0]+'/'+rec.TCDATE__c.split('/')[2]);
                }
                catch(Exception ex) { }
                craft.Date_Refurbished__c = rec.EXTYR__c;
                craft.Last_Refubished_Date_Jetnet__c = rec.INTYR__c;
                craft.Lifecycle_Status__c = rec.LIFECYCLE__c;
                
            }  
            matchAccount('COMP1', 
                         rec,
                         AccountsDone,
                         existingAccounts,
                         insertableAccounts,
                         updatableAccounts);
            matchAccount('COMP2', 
                         rec,
                         AccountsDone,
                         existingAccounts,
                         insertableAccounts,
                         updatableAccounts);
            matchAccount('CHPILOTCOMP', 
                         rec,
                         AccountsDone,
                         existingAccounts,
                         insertableAccounts,
                         updatableAccounts);
            matchAccount('EXCBROKERCOMP', 
                         rec,
                         AccountsDone,
                         existingAccounts,
                         insertableAccounts,
                         updatableAccounts);
        }
        if(!updatableAccounts.isEmpty())
        {
            update updatableAccounts;
        }
        if(!insertableAccounts.isEmpty())
        {
            System.debug('FM: insertableAccounts: '+insertableAccounts);
            List<Database.SaveResult> res = Database.insert(insertableAccounts, false);
            Integer i = 0;
            for(Database.SaveResult r : res)
            {
                if(!r.isSuccess() )
                {
                    errStr+=r.getErrors()[0].getMessage()+insertableAccounts[i];
                }
                i++;
            }
        }
        
        for(Raw_Aircraft__c rec : rawAircrafts)
        {
            //Contacts
            matchContact('CONTACT1', 
                         rec,
                         ContactsDone,
                         existingContacts,
                         insertableContacts,
                         updatableContacts,
                         existingAccounts);
            matchContact('CONTACT2', 
                         rec,
                         ContactsDone,
                         existingContacts,
                         insertableContacts,
                         updatableContacts,
                         existingAccounts);
            matchContact('CHPILOT', 
                         rec,
                         ContactsDone,
                         existingContacts,
                         insertableContacts,
                         updatableContacts,
                         existingAccounts);
            matchContact('EXCBROKER', 
                         rec,
                         ContactsDone,
                         existingContacts,
                         insertableContacts,
                         updatableContacts,
                         existingAccounts);
        }
        if(!updatableContacts.isEmpty())
        {
            update updatableContacts;
        }
        if(!insertableContacts.isEmpty())
        {
            insert insertableContacts;/*
            System.debug('FM: insertableContacts: '+insertableContacts);
            List<Database.SaveResult> results = Database.insert(insertableContacts, false);
            Integer i = 0;
            for(Database.SaveResult r : results)
            {
                if(!r.isSuccess())
                {
                    addErrorMessage(r.getErrors()[0].getMessage()+insertableContacts[i]);
                }
                i++;
            }*/
            
        }
        
        if(!updatables.isEmpty())
        {
            update updatables;
        }
        if(!insertables.isEmpty())
        {
            insert insertables;
            List<PriceBook2> pb = [Select id from Pricebook2 where isStandard = true ];
            List<PricebookEntry> entries = new List<PricebookEntry>();
            for(Product2 p : insertables)
            {
                entries.add(new PricebookEntry(Product2Id = p.Id,
                                               Unitprice = 1,
                                               isActive = true,
                                               Pricebook2Id = Test.isRunningTest() ? Test.getStandardPricebookId() : pb[0].Id));
            }
            if(!entries.isEmpty())
            {
                insert entries;
            }
        }
        for(Raw_Aircraft__c rec : rawAircrafts)
        {
            //Relations
            matchRelation('CONTACT1', 
                          rec, 
                          insertableRelations, 
                          existingAircraftRelations, 
                          existingAircrafts, 
                          existingAccounts, 
                          existingContacts);
            
            matchRelation('CONTACT2', 
                          rec,
                          insertableRelations, 
                          existingAircraftRelations, 
                          existingAircrafts, 
                          existingAccounts, 
                          existingContacts);
            matchRelation('CHPILOT', 
                          rec,
                          insertableRelations, 
                          existingAircraftRelations, 
                          existingAircrafts, 
                          existingAccounts, 
                          existingContacts);
            matchRelation('EXCBROKER', 
                          rec,
                          insertableRelations, 
                          existingAircraftRelations, 
                          existingAircrafts, 
                          existingAccounts, 
                          existingContacts);
        }
        if(!insertableRelations.isEmpty())
        {
            insert insertableRelations;
        }
        deleteCrafts(new Map<Id,Raw_Aircraft__c>( rawAircrafts ).keySet(),errStr);
    }
    
    private static void matchRelation(String prefix, 
                                      Raw_Aircraft__c rec,
                                      List<Aircraft_Relation__c> insertableRelations,
                                      Map<String, Aircraft_Relation__c> existingAircraftRelations,
                                      Map<String, Product2> existingAircrafts,
                                      Map<String, Account> existingAccounts,
                                      Map<String, Contact> existingContacts
                                     )
    {
        String accountPrefix = conPrefixToAccPrefix(prefix);
        String productKey = (String)rec.get('MANUF_MAKE_MODEL_SN__c');
        String accountKey = (String)rec.get(accountPrefix+'NAME__c');
        String contactKey = (String)rec.get(prefix+'FIRSTNAME__c')+(String)rec.get(prefix+'LASTNAME__c');
        String relation = (String)rec.get(accountPrefix+'RELATION__c');
        String key = (existingAircrafts.containsKey(productKey) ? existingAircrafts.get(productKey).Id+'' : 'null') +
            (existingAccounts.containsKey(accountKey) ? existingAccounts.get(accountKey).Id+'' : 'null')+
            (existingContacts.containsKey(contactKey) ? existingContacts.get(contactKey).Id+'' : 'null')+
            relation;
        if(!existingAircraftRelations.containsKey(key) && relation!='' && relation!=null)
        {
            Aircraft_Relation__c ar = new Aircraft_Relation__c(Aircraft__c = existingAircrafts.containsKey(productKey) ? existingAircrafts.get(productKey).Id : null,
                                                               Account__c = existingAccounts.containsKey(accountKey) ? existingAccounts.get(accountKey).Id : null,
                                                               Contact__c = existingContacts.containsKey(contactKey) ? existingContacts.get(contactKey).Id : null,
                                                               Relationship__c = relation);
            if(ar.Aircraft__c != null && ar.Account__c != null)
            {
                insertableRelations.add(ar);
                existingAircraftRelations.put(key, ar);
            }
            
        }
    }
    
    
    private static void matchContact(String prefix, 
                                     Raw_Aircraft__c rec,
                                     Set<String> contactsDone,
                                     Map<String, Contact> existingContacts,
                                     List<Contact> insertableContacts,
                                     List<Contact> updatableContacts,
                                     Map<String, Account> existingAccounts
                                    )
    {
        String contactName = (String)rec.get(prefix+'FIRSTNAME__c')+(String)rec.get(prefix+'LASTNAME__c');
        if(rec.get(prefix+'LASTNAME__c') != null && contactName != '' && !contactsDone.contains(contactName))
        {
            contactsDone.add(contactName);
            Contact con = existingContacts.get(contactName);
            if(con == null)
            {
                con = new Contact();
                con.FirstName = (String)rec.get(prefix+'FIRSTNAME__c');
                con.LastName = (String)rec.get(prefix+'LASTNAME__c');
                insertableContacts.add(con);
                existingContacts.put(contactName, con);
            }
            else
            {
                updatableContacts.add(con);
            }
            try{
                con.Salutation = (String)rec.get(prefix+'SALUTATION__c') != ''? (String)rec.get(prefix+'SALUTATION__c') :
                con.Salutation;
            }catch(Exception e){}
            
            con.MiddleName = (String)rec.get(prefix+'MIDDLE__c') != ''? (String)rec.get(prefix+'MIDDLE__c') :
            con.MiddleName;
            
            try{
                con.Suffix = (String)rec.get(prefix+'SUFFIX__c') != ''? (String)rec.get(prefix+'SUFFIX__c') :
                con.Suffix;
            }catch(Exception e){}
            
            try{    
                con.title = (String)rec.get(prefix+'TITLE__c') != ''? (String)rec.get(prefix+'TITLE__c') :
                con.title;
            }catch(Exception e){}
            
            try{
                con.email = (String)rec.get(prefix+'EMAIL__c') != ''? (String)rec.get(prefix+'EMAIL__c') :
                con.email;
            }catch(Exception e){}
            
            try{
                con.Phone = (String)rec.get(prefix+'OFFICE__c') != ''? (String)rec.get(prefix+'OFFICE__c') :
                con.Phone;
            }catch(Exception e){}
            
            try{
                con.fax = (String)rec.get(prefix+'FAX__c') != ''? (String)rec.get(prefix+'FAX__c') :
                con.fax;
            }catch(Exception e){}
            
            try{
                con.MobilePhone = (String)rec.get(prefix+'MOBILE__c') != ''? (String)rec.get(prefix+'MOBILE__c') :
                con.MobilePhone;
            }catch(Exception e){}
            
            try{
                String accountPrefix = conPrefixToAccPrefix(prefix);
                con.AccountId = (String)rec.get(accountPrefix+'NAME__c') != ''? existingAccounts.get( (String)rec.get(accountPrefix+'NAME__c') ).Id:
                con.AccountId;
            }catch(Exception e){}
            
        }
    }
    
    private static void matchAccount(String prefix, 
                                     Raw_Aircraft__c rec,
                                     Set<String> AccountsDone,
                                     Map<String, Account> existingAccounts,
                                     List<Account> insertableAccounts,
                                     List<Account> updatableAccounts
                                    )
    {
        String AccountName = (String)rec.get(prefix+'NAME__c');
        if(AccountName != null && AccountName != '' && !AccountsDone.contains(AccountName))
        {
            AccountsDone.add(AccountName);
            
            Account con = existingAccounts.get(AccountName);
            if(con == null)
            {
                con = new Account();
                con.Name = AccountName;
                insertableAccounts.add(con);
                existingAccounts.put(con.Name, con);
            }
            else
            {
                updatableAccounts.add(con);
            }
            try{
                con.Account_Name_2__c = (String)rec.get(prefix+'NAME__c') != ''? (String)rec.get(prefix+'NAME__c') :
                con.Account_Name_2__c;
            }catch(Exception e){}
            
            try{
                con.Main_office_Email__c = (String)rec.get(prefix+'EMAIL__c') != ''? (String)rec.get(prefix+'EMAIL__c'):
                con.Main_office_Email__c;
            }catch(Exception e){}
            
            try{
                con.Website = (String)rec.get(prefix+'WEBADDRESS__c') != ''? (String)rec.get(prefix+'WEBADDRESS__c') :
                con.Website;
            }catch(Exception e){}
            
            try{
                String street = (String)rec.get(prefix+'ADDRESS1__c')+' | '+
                    (String)rec.get(prefix+'ADDRESS2__c');
                con.BillingStreet = street != ''? street :
                con.BillingStreet;
            }catch(Exception e){}
            
            try{
                con.BillingCity = (String)rec.get(prefix+'CITY__c') != ''? (String)rec.get(prefix+'CITY__c') :
                con.BillingCity;
            }catch(Exception e){}
            
            try{
                con.BillingState = (String)rec.get(prefix+'STATE__c') != ''? (String)rec.get(prefix+'STATE__c') :
                con.BillingState;
            }catch(Exception e){}
            
            try{
                con.BillingPostalCode = (String)rec.get(prefix+'ZIPCODE__c') != ''? (String)rec.get(prefix+'ZIPCODE__c') :
                con.BillingPostalCode;
            }catch(Exception e){}
            
            try{
                con.Phone = (String)rec.get(prefix+'OFFICE__c') != ''? (String)rec.get(prefix+'OFFICE__c') :
                con.Phone;
            }catch(Exception e){}
            
            try{
                con.fax = (String)rec.get(prefix+'FAX__c') != ''? (String)rec.get(prefix+'FAX__c') :
                con.fax;
            }catch(Exception e){}
            
            try{
                con.Main_office_Phone2__c = (String)rec.get(prefix+'MOBILE__c') != ''? (String)rec.get(prefix+'MOBILE__c') :
                con.Main_office_Phone2__c;
            }catch(Exception e){}
        }
    }
    
    private static String conPrefixToAccPrefix(String prefix)
    {
        String accountPrefix = prefix == 'CONTACT1' ? 'COMP1' :
        prefix == 'CONTACT2' ? 'COMP2' :
        prefix == 'CHPILOT' ? 'CHPILOTCOMP' : 'EXCBROKERCOMP';
        return accountPrefix;
    }    
    
    public static void addErrorMessage(String msg)
    {
        ApexPages.addMessage(new ApexPages.Message (ApexPages.Severity.ERROR,msg));
    }
    public static void addSuccessMessage(String msg)
    {
        ApexPages.addMessage(new ApexPages.Message (ApexPages.Severity.CONFIRM,msg));
    }
    @Future
    public static void deleteCrafts(Set<Id> crafts, String str)
    {
        delete [Select id from Raw_Aircraft__c where id in :crafts];
        System.debug('FM: err: '+str);
    }
}

 
Fahad Khan 2Fahad Khan 2
@Rahul Kumar  
Thanks a lot for the suggestion Rahul, you are totally correct about the issue being similar to the one that you share a link to, but the cause of this problem totally doesn't match, his issue was resolved by removing "!= null" from where clause, and I don't have that in place. I am still clueless. and Salesforce support won't allow me to raise a development related issue by logging a case.