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
Vladimir BessonovVladimir Bessonov 

object factory

Hi. I create a class and trigger with the purpose to insert list of objects with master - detail relation when after master is created. 

I did it, but I store several lists in this class. it looks ugly. 

How I can separate this several objets with properties from the class? 
Is it possible just to keep them in SF database? is it good idea or it is a wrong direction? 

I was thinking to make object factory, so I might pass only the list of objects I want to create and the factory will return me the list of objects to insert. 
 
ShirishaShirisha (Salesforce Developers) 
Hi Vladimir,

Greetings!

We can't get the list of Sobjects using the SOQL query but you can make the describe call to get the list.

Please find the sample code below:
 
for ( Schema.SObjectType o : Schema.getGlobalDescribe().values() )
{
    Schema.DescribeSObjectResult objResult = o.getDescribe();
    system.debug( 'Sobject: ' + objResult );
    system.debug( 'Sobject API Name: ' + objResult.getName() );
    system.debug( 'Sobject Label Name: ' + objResult.getLabel() );   
}
Run this code in Execute anonymous and check debug. You will get all the sobject name(API Name), label and other properties.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Vladimir BessonovVladimir Bessonov
Frankly. I did not understand the proposed solution. 

Also, I cannot get any clear answer from the Salesforce community how to organize the code.

I need to store some config objects that consist for sake of simplicity several List<String>. 
I build an app. Based on the project selected I wanted to use different configs for automatic record creation. 

I made a map 

public without sharing class ProjectMap {
public ProjectMap() {
// how to make universal use of class?
// how to make generic object type,
CTAPropSet CTAProject = New CTAPropSet();
// PartSet cta = (PartSet) CTAProject;
Projects.put('CTA-CRRC', CTAProject);
}
Map<string, CTAPropSet > Projects = new Map<string, CTAPropSet >();
public Object projectConfig(String ProjectName) {
return Projects.get(ProjectName);
}
}


but as data always saved in classes and classes have names and data is of particular class type. 
I hardcode the class type returned by MAP. I cannot figure out how to cast it 

ProjectMap projectConf = New ProjectMap();
System.debug(ProjectName);
CTAPropSet projectConfLists = projectConf.projectConfig(ProjectName);

instead of CTAPropSet, I wanted to have some generic type that can be used if I enter the different project name.  
Maybe it is possible to cast them to the same class as they will have the same structure. 

Apex is pain. Why Salesforce cannot use just JS or typescript? I cannot find good and short documentation and code guides. 

I work with salesforce for 3 weeks and I hate it already