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
Vijay BharghavVijay Bharghav 

All Fileds with values for a specific record

hi

 

Hi I am new to Salesforce, Need help to have all fileds with values in a map for a specific record through apex class.

 

Example :('Name__C','Bharghav');

 

Regards

Vijay Bharghav

 

 

bob_buzzardbob_buzzard

You already have this using dynamic DML.  That allows you to take a record and retrieve the field values using the map syntax.

 

E.g.

 

List<Contact> conts=[select id, Name from contact];

for (Contact cont: conts)
{
  String name=(String) cont.get('Name');
}

 

souvik9086souvik9086

public class YourController{

List<Account> accList = new List<Account>();

public YourController(){

accList = [SELECT name,AccountNumber,Industry FROM Account limit 1];

}

public void YourMethod(){

 

Map<String,String> aMap = new Map<String,String>();

aMap.put('Name','accList.get(0).name);

aMap.put('AccountNumber','accList.get(0).AccountNumber);

aMap.put('Industry','accList.get(0).Industry);

}

}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

vbsvbs
@Vijay - If you are looking at building the fields for an object dynamically then use Schema Describe methods to build a list of fields for a given object dynamically. You can then query the object and use Bob's snippet above to get the field values for the specific fields dynamically.
Vijay BharghavVijay Bharghav

I am looking to get name,AccountNumber to form dyanmically.

 

Lets say i have an email template with MergeFileds . And i am seding mails to say record (0190000007jIZw)

Name:{!name__C}

Age :{!Age__C}

 

i wantt to have a map created with key as (name__C) and value as ('Bharghav'). So that but iterating over the map i can dynamically replce the email template with teh values.

 

Regards

Vijay Bharghav