• VedPrakash Patel
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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(',');         
         
            demNames.add(inputvalues[0]);
         
        }
        try{
            //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');
            ApexPages.addMessage(errormsg);
        }

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

Thanks,
Ved
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(',');         
         
            demNames.add(inputvalues[0]);
         
        }
        try{
            //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');
            ApexPages.addMessage(errormsg);
        }

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

Thanks,
Ved