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
HAZLITT VASUDEVANHAZLITT VASUDEVAN 

How to get email body information into custom object field in apex

User-added imageLaptop Warranty is my custom object 


User-added imagenow this code only sends the info to the given mail but I want the content to go into a separate custom object field as email body.
Best Answer chosen by HAZLITT VASUDEVAN
Oshin AgrawalOshin Agrawal
Hi,

As per the requirement I assume you just need the email body to be saved in a field.That could be pretty easy:
Get the record id of the custom object where you want the body to be saved ,( could you SOQL to fetch that)
and by using id, you can go for something like- 
list<laptop_warranty__c> lstobj = new list<laptop_warranty__c>();
for(laptop_warranty__c obj : [Select id,email_body__c from laptop_warranty__c ] // use the condition as required
{
obj.email_body__c = txtbody; // populating the field with the value of text body that you created
lstobj.add(obj);
}
if(lstobj.size>0)
update lstobj;


Thanks 

All Answers

ShivankurShivankur (Salesforce Developers) 
Hi Vasudevan,

Please check out the code implementation from this thread:
https://developer.salesforce.com/forums/?id=906F00000008oD2IAI

You can try to implement the similar logic to get the email body into your custom objects fields.

Hope above information helps. Please mark as Best Answer so that it can help others in future.

​​​​​​​Thanks.
Oshin AgrawalOshin Agrawal
Hi,

As per the requirement I assume you just need the email body to be saved in a field.That could be pretty easy:
Get the record id of the custom object where you want the body to be saved ,( could you SOQL to fetch that)
and by using id, you can go for something like- 
list<laptop_warranty__c> lstobj = new list<laptop_warranty__c>();
for(laptop_warranty__c obj : [Select id,email_body__c from laptop_warranty__c ] // use the condition as required
{
obj.email_body__c = txtbody; // populating the field with the value of text body that you created
lstobj.add(obj);
}
if(lstobj.size>0)
update lstobj;


Thanks 
This was selected as the best answer
HAZLITT VASUDEVANHAZLITT VASUDEVAN
Thanks for responding 
@Shivankur  @Oshin Agrawal


User-added image