You need to sign in to do that
Don't have an account?

creating a new list from the existing list
Hi ,
i have a list called List<test__c> lsttest = Database.query(sQueryForUniqueId);. It has a field name unique code with value "1234;456".
I want to create a new list which will have two records one with unique code 1234 and another with 456. Can anyone help with a sample code snippet?
Thanks
i have a list called List<test__c> lsttest = Database.query(sQueryForUniqueId);. It has a field name unique code with value "1234;456".
I want to create a new list which will have two records one with unique code 1234 and another with 456. Can anyone help with a sample code snippet?
Thanks
List<test__c> List1 = new List<test__c>();
List<test__c> List2 = new List<test__c>();
For(test__c test : lsttest){
if(test.testfield__c == test.name){
test__c test1 = new test__c ();
test1 = test.clone();
List1.add(test1);
}
else{
test__c test1 = new test__c ();
test1 = test.clone();
List2.add(test1);
test__c test2 = new test__c ();
test2= test.clone();
test2.testfield__c = test.name
List2.add(test2);
}
}
All Answers
Use something like :-
List<string> List1 = new List<string>();
List<string> List2 = new List<string>();
List<string> fieldvalueList = new List<string>();
For(test__c test : lsttest){
fieldvalueList = test.field.split(";");
List1.add(fieldvalueList[0]);
List2.add(fieldvalueList[1]);
}
Its the basic one and might need some changes according to the requirements/complexity.
If this solves your problem, mark it as solved.
Sample record -
name - test
testfield - testsecondrecord.
So it should create a new list with two records;
first record will have just name - test and testfield - blank. second will have name - test and testfield - testsecondrecord.
Can you please help?
So i have a list List<test__c> lsttest = Database.query(sQueryForUniqueId).
testfield__c and name are the two fields in this database.query.
I want to create a new list lsttest1 which will seperate the records on the below mentioned condition,
If testfield__c = name create one record in the list.
if testfield__c != name , create two records in the list. one with testfield__c = name and another with testfield__c != name.
Thanks
List<test__c> List1 = new List<test__c>();
List<test__c> List2 = new List<test__c>();
For(test__c test : lsttest){
if(test.testfield__c == test.name){
test__c test1 = new test__c ();
test1 = test.clone();
List1.add(test1);
}
else{
test__c test1 = new test__c ();
test1 = test.clone();
List2.add(test1);
test__c test2 = new test__c ();
test2= test.clone();
test2.testfield__c = test.name
List2.add(test2);
}
}