Map<String, Schema.SObjectField> fMap = Schema.getGlobalDescribe().get('Account').getDescribe().Fields.getMap();
list<string> selectFields = new list<string>();
string excelHeader = 'ApexName\n';
if (fMap != null){
for (Schema.SObjectField ft : fMap.values()){
Schema.DescribeFieldResult fd = ft.getDescribe();
excelHeader += fd.getName() +'\n';
}
}
Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
blob csvBlob = Blob.valueOf(excelHeader);
string csvname= 'AccountFields.csv';
csvAttc.setFileName(csvname);
csvAttc.setBody(csvBlob);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] toAddresses = new list<string> {'Your Email'};
String subject = 'Account fields CSV';
email.setSubject(subject);
email.setToAddresses(toAddresses);
email.setPlainTextBody('Account Fields');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
Output
Showing posts with label objectName. Show all posts
Showing posts with label objectName. Show all posts
Monday, June 29, 2020
Export Salesforce Object field names into CSV file
Sample Code
Labels:
Apex,
CSV File,
objectName,
Salesforce,
sfdc,
sobject,
sobject details
Tuesday, November 12, 2019
How to get Record Id and Object Name into Lightning Web Component(lwc)
We used the force:hasRecordId interface to a Lightning component to enable the component to be assigned the ID of the current record. The current record ID is useful if the component is used on a Lightning record page.
We used the force:hasSObjectName interface to a Lightning component to enable the component to be assigned the API name of the current record’s sObject type. The sObject name is useful if the component can be used with records of different sObject types.
To get the record id and sObjectName in Lightning web components we can use the public decorate '@api'
@api recordId;
@api objectApiName;
HTML Code
Javascript Controller
Output
We used the force:hasSObjectName interface to a Lightning component to enable the component to be assigned the API name of the current record’s sObject type. The sObject name is useful if the component can be used with records of different sObject types.
To get the record id and sObjectName in Lightning web components we can use the public decorate '@api'
@api recordId;
@api objectApiName;
HTML Code
<template>
<lightning-card>
<div class="slds-text-heading_medium slds-text-align_center">
Record Id : {currenRecordId}
</div>
<div class="slds-text-heading_medium slds-text-align_center">
Object Name : {currenObjectName}
</div>
</lightning-card>
</template>
Javascript Controller
import { LightningElement, api, track } from 'lwc';
export default class LWCDemo extends LightningElement {
@api objectApiName;
@api recordId;
@track currenObjectName;
@track currenRecordId;
connectedCallback() {
this.currenRecordId = this.recordId;
this.currenObjectName = this.objectApiName;
}
}
Configuration File<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="LWCDemo">
<apiVersion>46.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>
Output
Subscribe to:
Posts (Atom)