+ Start a Discussion
VedPrakash PatelVedPrakash Patel 

Unable to delete records from custom objects

Hello All,
I am trying to delete more then one record from custom object and trying to pass a collection as an parementer to query.  I can delete individual record with hard coded value however if i pass a paramenter for single value or collection its not deleteing and not returing any records from query.  below is the code for your reference.  your early help will be appreciated.

Set<String> demNames = new Set<String>();
        String strVal;             
        for (Integer i=1;i<filelines.size();i++)
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');         
            //display dats from set string
            String str1 = String.join(new List<String>(demNames),'--');

            ApexPages.addMessage( new ApexPages.Message(ApexPages.severity.ERROR,Str1));

     TempDems__c[] d = [SELECT Name FROM TempDems__c WHERE Name IN :demNames] ;          
            ApexPages.addMessage( new ApexPages.Message(ApexPages.severity.ERROR,string.valueof(d.size())));
            delete d;

// Below code is working if i hard code the value
     //TempDems__c a =[SELECT Name FROM TempDems__c WHERE Name ='D-1234569'];
            //delete a;
        catch (Exception e)
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured. Please check the template or try again later');

Please let me know if you find any issues in above code.

Vishant ShahVishant Shah
can you tell what the value of filelines is please? 
VedPrakash PatelVedPrakash Patel
Filelines will contain string values. i was uploading the csv file with column value which need to be deleted.  i have almost 3000+ records which need to be deleted and we have a list of column values to delete.  In object this is a string field and has unique value ( Name text(10)).
Sample values are 'D-1234569], 'D-432344' etc.

Thanks for your help.