0

I want to delete multiple records of an object...How should I do it.

public class del_acc { public List<String> sel_id{get;set;} set<id> sid = new set<id>(); List<Account> accIdList = new List<Account>(); public void deleteacc() { if(sel_id != '') { List<Account> acc = new List<Account>(id=sel_id); delete acc; } } } 
12
  • Are you facing any issue? Commented Jan 18, 2016 at 12:50
  • yeah i am passing id in Account but its for only 1 record... Commented Jan 18, 2016 at 12:51
  • 1
    then pass multiple id or you don't know how to pass multiple Ids. In case use wrapper class. Commented Jan 18, 2016 at 12:52
  • 1
    @Anzar can't add answer due to question being on hold. Firstly convert sel_id into a set of string as "Set<String> sel_idSet = new Set<String>(); sel_idSet.addAll(sel_id );". This is because we don't want repeated IDs while deleting stuff. Commented Jan 20, 2016 at 9:24
  • 1
    Then convert the set of string to set of IDs as " Set<ID> IDsToDelete = (Set<ID>)JSON.deserialize(JSON.serialize(sel_idSet), Set<ID>.class); ". Then query out all the accounts "WHERE id IN :IDsToDelete ". Delete the list of accounts returned in the query. An answer would have looked much better on the yes, sorry. Commented Jan 20, 2016 at 9:26

1 Answer 1

1

@Anzar to pass multiple ids in apex search about for each loop.

for (Account o : send your set of id's) { /* Code for account omitted */ } 
2
  • 3
    Telling someone to Google a search term isn't exactly what I think of as answering their question. Also, please visit Help center to better learn how our Forum operates. Asking to have your answer marked as "best" isn't necessary. Commented Jan 18, 2016 at 18:01
  • 3
    Thanks from now onward's i will follow guidelines how to post comments @crmprogdev Commented Jan 18, 2016 at 18:42

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.