How to fetch the RecordTypeName Dynamically from the schema - apex

Can anyone share the solution that 'How to fetch the RecordTypeName Dynamically from the schema' to store into custom object.

You can use below syntax to fetch RecordTypeName dynamically from schema by giving custom ObjectName from which you want to fetch the recordTypeNames.
Further you can save this recordTypeNames in a custom field of your custom object.
Schema.DescribeSObjectResult objDesc = ObjectName.SObjectType.getDescribe();
List<Schema.RecordTypeInfo> objRTList = objDesc.getRecordTypeInfos();
for(Schema.RecordTypeInfo recType : objRTList) {
system.debug(recType.getName());
}
If you find it helpful, Please mark it as best answer.
Thanks

Related

Access related model fields from ModelAdmin actions for exporting to excel

I am desperately waiting for someone attention to get my question answered.... please help..
ModelAdmin model has to export to Excel action method.
I need to access related model fields in action method. That means I can not pass any arguments therefore I tried relatedmodel_set but ModelAdmin action method shows memory location and fails when I try to access values through attributes:
<django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager..RelatedManager object at 0x7f8eea904ac0>
model.py
class EnrolStudent(models.Model):
def get_trn_activity(self):
return self.studenttraininactivities_set
class StudentTraininActivities(models.Model):
trainin_activities = models.ForeignKey(EnrolStudent,
on_delete=CASCADE, null=True )
<other fields...>
admin.py
#admin.register(EnrolStudent)
class EnrolAdmin(admin.ModelAdmin):
form = CityInlineForm
inlines = [CohortTraininActivitiesInline]
...
actions = [export_as_txt_action_0120("File NAT00120 data Export"
, fields=['information_no', 'get_trn_activity',
'student_enrol__student_code'])]
I need to access related model fields to export to excel.
I can not pass parameter to get_trn_activity as you have noticed.
Therefore selected rows only data from Django admin change_list page will only need bit of work using its queryset in actions method used in separate actions.py file that I can do!
Please help me with this issue. I am new to Python / Django.
I also tried property decorator in related model then access in a method in main model then call it inside action but same problem with memory address not the direct value and then how to get data of memory location here .... I don't know.
If I can access the related fields then I can do it no issue.
Another question:
I had same situation with model/related model before, but they were connected through OneToOneField relationship and I was able to use dundor to access related model fields but in this case of ForiegnKey relationship I can not see related model in queryset.
In other case this is what I can do easily; here cohortdetails is related model and when I debug I saw it was listed in queryset that was great.
actions = [export_as_txt_action_0080("File NAT00080 txt Export",
fields=['rto_student_code', 'first_name', 'family_name'
,'cohortdetails__highest_school__highestschool_levelcode',
'cohortdetails__cohort_gender'
, 'cohortdetails__student_dob' ])]

How to turn OFF Schema Validations dynamically using MongoDB-JAVA APIs

I have created a collection with schema validation as below,
ValidationOptions collOptions = new ValidationOptions();
collOptions.validator(sdoc);
collOptions.validationLevel(ValidationLevel.MODERATE);
collOptions.validationAction(ValidationAction.WARN);
srdmDatabase.createCollection(collectionName,new CreateCollectionOptions().validationOptions(collOptions));
My collection is created successfully with schema validation.
In some cases, I want to turn OFF the validation check dynamically.
I found that there is an option to turn OFF the validation(ValidationLevel.OFF) in monogdb-java-driver, but I have no idea about how to use this option.
Please help me some one how to turn off the validation check programmatically.
We are using MongoDB-4.0 and mongo-java-driver-3.10.2.
Thanks in advance.
You can try using the following code to bypass the validation.
For updates
collection.updateOne(
Filters.eq("_id", 1),
Updates.set("name", "Fresh Breads and Tulips"),
new UpdateOptions().upsert(true).bypassDocumentValidation(true));
Similarly for inserts, you can use InsertOptions.bypassDocumentValidation(true)
Refer this link for more info https://docs.mongodb.com/manual/core/schema-validation/#bypass-document-validation

Dynamic sqlWorkflowInstanceStore

I have created an application using this
http://msdn.microsoft.com/en-us/magazine/ff646977.aspx
What i need to do is callWorkflow instances store dynamically
i.e before
string message = "";
string result = client.EvaluateMortgage();
I should be able to specify the sqlworkflowinstancestore i.e where the workflow data is
Any help will be appreciated.
I think you can do like this,
SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(connectionString);
More info
Here you can find several ways of configuring /using it

how to show metadata associate with a custom document

I would like to view the custom metadata that I associated with the my custom document, that I created with the document library, anyone know how to due with velocity variable?
Thanks in advance
Sabrina
You can get some meta-data articles properties with
$reserved-article-id.data
$reserved-article-title.data
full list you can find here
Also you can check this post, it has example how to get journal's categories at velocity template.
UPD. For getting document metadata you can use smth like this:
#set($dlFileUtil = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileE‌​ntryLocalService"))
#set ($groupId = $getterUtil.getLong($groupId))
#set($fileEntry = $dlFileEntryUtil.getFileEntryByUuidAndGroupId($uuid,$longGroupId))
#set($metadataUtil=$serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileE‌​ntryMetadataLocalService"))
You can use getFileEntryMetadata(ddmStructureId, fileVersionId) from $metadataUtil
More detailed code you can check this.
BR,
Paul Butenko

Get object in i18n form

Inside embedded i18n form i need to get object.
In this example i got ArtistImageTranslation object, but i need ArtistImage.
Can somebody help me, how to get this?
class ArtistImageTranslationForm extends BaseArtistImageTranslationForm
{
public function configure()
{
$this->getObject();
....
}
}
Have you tried the following?
$artistimage = $this->getObject()->getArtistImage();
I spent half of day today on the same problem and looks like I finally found something ;)
First, if you need to access the fields which are in the "Translation" part of the table you can access them directly from the Object contained in the form. Just access the properties without using the getter (I know it's not the nice way but it works). So you can use something like:
$this->getObject()->id;
$this->getObject()->translated_name;
etc.
If you really need the original object you can access it like this:
$this->getObject()->getTable()->getRelation('ArtistImage')
->fetchRelatedFor($this->getObject());
Hope this helps.
Try :
$artistimage = $this->getObject()->artistImage;
or
$artistimage = $this->getObject()->artist_image;