Skip to main content
Hi All,

I have designed a lightning component to insert products under one of custom object.

I can use same component in any custom objects without changing piece of code, i am storing the parent object fields api names in custom setting,

when inserting products i need to bind parent fields api names from custom settings.

I have searched a lot in google, still i am not able to find solution to achive this.

Thanks.
2 件の回答
  1. 2019年6月16日 3:14
    Hi Narendra,

    I don't think you need custom setting here. You can dynamically get the field API names using  $ObjectType.

    The $ObjectType global variable provides access to a variety of schema information about the objects in your organization. Use it to reference names, labels, and data types of fields on an object, for example.

    $ObjectType is a “deep” global variable, and offers the opportunity to use it in a “double dynamic” reference, like so:

     

    $ObjectType[sObjectName].fields[fieldName].Type

    Eg: This Retrieves all the API names for Product Object.

    List<Schema.SObjectType> objects = new List<Schema.SObjectType>{ Product2.SObjectType};

    for(Schema.SObjectType objType: objects){

    for(Schema.SObjectField fld: objType.getDescribe().fields.getMap().values()){

    System.debug('API Field Name = '+fld.getDescribe().getName());

    }

    }

    Reference : 

    https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_dynamic_vf_globals_objecttype.htm

    Regards,

    Avishek 

     
0/9000