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
AwkwardTacoAwkwardTaco 

SOQL and Trigger newbie

I am trying to build a trigger that would send a message to the following users:

1. CreatedBy (Case)

2. LastModifiedBy(Case)

3. CreatedBy(CaseComment)

 

The query would need to return the following data:

 

1. CaseComment.CommentBody

2. Email address for the users who need to receive the message

3. Subject Line, ID  for the Case

 

Any suggestions on how to build the query, would be greatly appreciated. I am having some issues trying to get those results.

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
Imran MohammedImran Mohammed

Try this query,

 

Case[] cs = [select id, CreatedBy.Email, LastModifiedBy.email, (select CommentBody, CreatedBy.Email from CaseComments) from Case];
system.debug(':::: : :::: : : :: '+cs);
system.debug(':: ::: ::: '+cs[0].CreatedBy.Email);
system.debug('-- --- -'+cs[0].casecomments[0].commentbody);

 

Case[] cs = [select id, CreatedBy.Email, LastModifiedBy.email, (select CommentBody, createdby.email from CaseComments) from Case];

 

This is how you can test it,

 

system.debug('Case is '+cs);

system.debug(' Email id of User who created Case'+cs[0].CreatedBy.Email);

system.debug(' Email body of Case comment'+cs[0].casecomments[0].commentbody);

system.debug('Email id of who created case comment  '+cs[0].casecomments[0].createdby.email);

 

Let me know if it works or if you face any issue.

 

All Answers

Imran MohammedImran Mohammed

Try this query,

 

Case[] cs = [select id, CreatedBy.Email, LastModifiedBy.email, (select CommentBody, CreatedBy.Email from CaseComments) from Case];
system.debug(':::: : :::: : : :: '+cs);
system.debug(':: ::: ::: '+cs[0].CreatedBy.Email);
system.debug('-- --- -'+cs[0].casecomments[0].commentbody);

 

Case[] cs = [select id, CreatedBy.Email, LastModifiedBy.email, (select CommentBody, createdby.email from CaseComments) from Case];

 

This is how you can test it,

 

system.debug('Case is '+cs);

system.debug(' Email id of User who created Case'+cs[0].CreatedBy.Email);

system.debug(' Email body of Case comment'+cs[0].casecomments[0].commentbody);

system.debug('Email id of who created case comment  '+cs[0].casecomments[0].createdby.email);

 

Let me know if it works or if you face any issue.

 

This was selected as the best answer
super developersuper developer

HI Imran,

 

I need some help on Web service. I am now starting webservices now. Give me the How i start.

Imran MohammedImran Mohammed

I hope you might have gone though the below link and access Getting Started.

Apex Webservices

 

Myself or anyone on forums will help you further as and when you require.