function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Priya RavichandranPriya Ravichandran 

apex class developement

Hi, 
 I want to create a apex class with the below input an output.. am new to SF please help.



Input 
===== 
Field1|Field2 
AAA|1,2 
BBB|1,2,3 
CCC|1,2,3,4 
DDD|1,2,3,4,5 


Output 
====== 
AAA|1 
AAA|2 
BBB|1 
BBB|2 
BBB|3 
CCC|1 
CCC|2 
CCC|3 
CCC|4 
DDD|1 
DDD|2 
DDD|3 
DDD|4 
DDD|5 
Yuvaraj mayilsamy 9Yuvaraj mayilsamy 9
Hi Priya,

 Below is the code. I understood your requirement as if we enter AAA in field 1 and 3 in field 2 the result should be AAA1, AAA2, AAA3. Marks this as the best answer if it helps.

Create an apex class like this 
public class sampleclass {
    public static void samplemethod(string field1, integer field2){
            for(integer i=1;i <= field2; i++){
            system.debug(field1 +i);
        }
    }
}

Run this in Anonymous window
sampleclass.samplemethod('AAA', 4);

The result will be like below.

Result in debug log
Priya RavichandranPriya Ravichandran
Hi Yuvaraj,

I have an custom object  with the fields  as column A, columnB , Column C, Column D  and their values are  A, B,Product1, product 2 in the format as below.

Input :
Column A       Column B       Column  C         Column D
A                        B                Product1          Product2
C                        D                Product3


Output wil be

Column A             Column B        Column C

A                          B                Product1
A                          B               Product2
C                          D               Product3


I have to create an Apex class with the custom objects and fields like this.  Please adivse. 
 
Yuvaraj mayilsamy 9Yuvaraj mayilsamy 9
Hi  Priya,

So, in a custom object you have record like ColumnA - A Columnb - b columnc- product1 columnd- product2. If it is like this then you wanted to removed the columnd’s Value and create a new record by putting the values in columnc with same value as columna and  columnb. Is t right?

Yuvaraj
Priya RavichandranPriya Ravichandran
Hi, 
 I have created a small Apex class. 
 

Public class Products

{
LIST <API__c>lst;
LIST <API__c> test1;
LIST <API__c> test2;
LIST <API__c> test3;
List<SObject> CombinedItems=new List<SObject>();

Public   LIST <API__c> getAccount()
{
try
{
lst=[SELECT Name__c, Phone__c, Product_1__c,Product_2__c from API__c  limit 10];                                 
for(API__c ValueFile : lst)
{
if(ValueFile.Product_1__c!=null)
{
test1=[SELECT Name__c, Phone__c, Product_1__c from API__c  limit 10];  
}
if(ValueFile.Product_2__c!=null)
{
test2=[SELECT Name__c, Phone__c, Product_2__c from API__c WHERE Product_2__c != '" "' AND Product_2__c != null LIMIT 5];
}
}
CombinedItems.addAll(test1);
CombinedItems.addAll(test2);
return CombinedItems;

}
catch(Exception ex)
{
System.debug('Error'+ex.getMessage());
}
return CombinedItems;
}
}

 how to display the final value which is in  "CombinedItems" List into the VF page into the column name as  Name, Phone  & Product.  Appreciate your help.