You need to sign in to do that
Don't have an account?

I didnt understand singleemailmessage is a class or method. While Messaging is a class. What about singleemailmessage?



SingleEmailMessage class contains methods for sending emails.
SingleEmailMessage contains methods listed in
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_single.htm#apex_Messaging_SingleEmailMessage_methods
SingleEmailMessage Constructors:
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_single.htm#apex_Messaging_SingleEmailMessage_constructors
If this information helps, please mark the answer as best. Thank you

self test - how to schedule test class in salesforce
how to make this?


global class SelfTest implements Schedulable { global void execute(SchedulableContext ctx){ List<ApexClass> testClasses = [SELECT Id FROM ApexClass WHERE Name = 'NAME_TEST_CLASS']; List<ApexTestQueueItem> queueItems = new List<ApexTestQueueItem>(); for (ApexClass testClass : testClasses) { queueItems.add(new ApexTestQueueItem(ApexClassId=testClass.Id)); } if(!Test.isRunningTest()) insert queueItems; } }
System.schedule('Self Test', cron, new SelfTest());

can anyone help me with the below trigger? Write a trigger to prevent to create duplicate opportunity record based on the name under same account.




Here is the sample code to prevent account record. You can modify, replace Account with Opportunity and implement.
trigger AccountDuplicate on Account (before insert) { Set<String> setName = new Set<String>(); For(Account acc : trigger.new) { setName.add(acc.name); } if(setName.size() > 0 ) { List<Account> lstAccount = [select name ,id from account where name in :setName ]; Map<String ,Account> mapNameWiseAccount = new Map<String,Account>(); For(Account acc: lstAccount) { mapNameWiseAccount.put(acc.name ,acc); } For(Account acc : trigger.new) { if(mapNameWiseAccount.containsKey(acc.name)) { acc.Name.addError('Name already Exist '); } } } }
Kindly mark it as the best answer if it helps.
Thank You,
Priya Ranjan

reports and dashboards in lightening


When you create a Report/Dashboards and then save it it some folder. You need to give access to that folder to the users who will be using those reports. Also, View Dashboards in Public Folders and View Reports in Public Folders these two checks should be enabled on the users profile to make sure users have access for reports & dashboards.
Please mark as Best answer if solve your query and close it

How to include the error info in the test class?
i want to include this error info into my test class now my test class is covring 91% but i need 100% coverage.
for(Database.Error error : errors) {
errorStrings = errorStrings + ' ' + error.getMessage();
}
}
return errorStrings;
}




Hey Shruthi,
In the test class, You have to create a condition that causes the error, such as leaving a required field (name, for example) blank.
Kindly mark it as the best asnwer if it works for you.
Also refer this where similar discussion has done :-
https://developer.salesforce.com/forums/?id=906F0000000kEbrIAE
Thanks & Regards,
Priya Ranjan

Error: Variable Does not exist. Global Non-Static Variable does not exist in the batch finish method.
I am getting an error 'Variable does not exist: varName' when I tried to access my global variable in the finish method of the batch class.
Point to Note:
1. Neither I am using a stateful class, not any static variable. So in any case values will be retained in my variable.
2. According to the salesforce article global variables declared in the batch class are accessible in all 3 methods.
Steps already performed:
1. The variable is initiated in the constructor with the parameter passed to the batch class.
2. The same variable is used in the start method to build my query.
Issues:
When I tries to access in finish method got an error saying the variable does not exist.
Below is the code snippet:
global class clsName implements DataBase.Batchable{
global string var;
public void clsName(string param){
this.var = param;
}
public Database.queryLocator start(....){
return Databse.getQueryLocator('SELECT Id from Account where ID =: 'var');
}
public static void execute(....){
//Some Logic
}
public static void finish(....){
System.debug(var); //Error variable does not exist: var
}
}
Let me know your suggestion or if I am making any mistake.
Thanks in advance.


Define your variable as static then you can access it to the finish method. This way you can resolve your issue.
global class clsName implements DataBase.Batchable<sObject>{ global static string var; public void clsName(string param){ var = param; } public Database.queryLocator start(Database.BatchableContext bc){ return Database.getQueryLocator('SELECT Id from Account where ID =: '+var); } public static void execute(Database.BatchableContext BC, List<SObject> sobjects){ //Some Logic } public static void finish(Database.BatchableContext bc){ System.debug(var); //Error variable does not exist: var } }
Trigger Apex Not working for First Task Action directly calls 2nd Task Action
and the goal here is to prevent a Task from being created for 2 scenarios
- First Task with the Action__c field being ‘airtel account contact Research’ and once user creates a Task with Action__c as "‘airtel account contact Research’"
- then they should only able to create second Task with Action__c as '1st airtel contact'',
Now after these 2 tasks creation is done then user can create any task with any picklist value in Action__c field
Here is Trigger which calls TaskTriggerHandler
TaskTrigger trigger TaskTrigger on Task (before insert) { if(Trigger.isBefore&&Trigger.isInsert){ TaskTriggerHandler.beforeInsert(Trigger.New); } }
Here is TaskTriggerHandler
public class TaskTriggerHandler { public static void beforeInsert(List<Task> tasks){ final string ERTTRECORDTYPENAME = 'ERTT_Task_Record_Type'; // Filter String to get the ERTT Task REcordType Id Id recordTypeId_ERT = [select id, DeveloperName from RecordType where sobjecttype = 'Task' AND developername =: ERTRECORDTYPENAME].Id; List<Task> ERTTasks = new List<Task>(); Set<Id> caseIdset = new Set<Id>(); for(Task taskProcess : tasks){ // Functionality Added to Validate only the ERTT_Task_Record_Type Record type. if(taskProcess.RecordTypeId == recordTypeId_ERT && taskProcess.Action__c != 'airtel account contact Research' ) { ERTTasks.add(taskProcess); if(taskProcess.WhatId != null) { caseIdset.add(taskProcess.WhatId); } } } // Making sure there is data in the ERTT Tasks and What Id of the Tasks if(!ERTTasks.isEmpty() && !CaseIdset.isEmpty()) { ERTT_TaskCreationValidation.isairtelAccountResearchcompleted_New(ERTTasks,CaseIdset); } } }
Here is Apex class with Logic written
public class ERTT_TaskCreationValidation { public static void isairtelAccountResearchcompleted_New(List<Task> ERTTTasks,Set<Id> caseIdset) { list<Task> lstTAsk=new list<Task>(); map<Id, Case> mapCaseWithTaskList = new map<Id, Case>([select id, (Select id, Action__c from Tasks ) from Case where Id in: caseIdset]); for(Task t : ERTTTasks) { Boolean validationFlag = true; Boolean validationFlag2 = true; System.debug('mapCaseWithTaskList.gett.WhatId.tasks'+ mapCaseWithTaskList.get(t.WhatId).tasks); if(mapCaseWithTaskList.get(t.WhatId).tasks.size()>0) lstTAsk.add(mapCaseWithTaskList.get(t.WhatId).tasks); for(Task t1: mapCaseWithTaskList.get(t.WhatId).tasks){ if(t1.Action__c == 'airtel account contact Research') { validationFlag = false; } } if(validationFlag){ t.addError('Please Create a task for airtel account contact Research before creating any other Task'); } System.debug(' lstTAsk' +lstTAsk); if(lstTAsk.size()==2 && t.Action__c == '2nd field'){ validationFlag2=false; } if(validationFlag2){ t.addError('Please Create a task for 2nd field before creating any other Task'); } } } }
Now the problem is when Task is getting created at Case ,the second Error message is thrown which is "Please Create a task for 2nd field before creating any other Task" whereas requirment is to first show the first error message 'Please Create a task for airtel account contact Research before creating any other Task' and then the second error message
'Please Create a task for 2nd field before creating any other Task'
Any idea what is going wrong in the apex class ?
Your reply with resolution is appreciated
Regards
Fiona


I got your point.
you used below two boolean variables,
Boolean validationFlag = true;
Boolean validationFlag2 = true;
when you create first record validationFlag the\is variable become false but validationFlag2 this remail true thats the reason.
for(Task t1: mapCaseWithTaskList.get(t.WhatId).tasks){
if(t1.Action__c == 'airtel account contact Research') {
validationFlag = false;
validationFlag2 = false;
}
}
replace above code with your code in ERTT_TaskCreationValidation class.
and let me know .
If it helps please mark the best answer it will helps other.
Thanks ,
Lukesh

Help with test apex class for inserting new records
Hi,
I'm having difficulty in writing a test class for my apex class that creates a new lead record based on whether an existing lead has met the conditions. So if a lead has Web to Lead = True and H M!=null and WTL G!=null, it will take the values from that record and create a new one. Please see below class:
APEX CLASS:
public class CreateNewLead {
public static void createnewrecords(List<Lead> leadMap){
List<Lead> insertList = new List<Lead>();
for (Lead rec:LeadMap){
if ((rec.WTL_G__c != null) && (rec.H_M__c != null) && (rec.Web_to_Lead__c==TRUE))
{
// Creating new record
Lead newlist = new Lead();
newlist.WTL_M__c = rec.H_M__c;
newlist.FirstName = rec.FirstName;
newlist.LastName = rec.LastName;
insertList.add(newlist);
}
}
if(insertList.size()>0){
insert insertList;
Constantclass.isenteredtrigger=true;
}
}
}
TEST CLASS:
@isTest
private class CreateNewLead_Test {
static testMethod void UPDATEMPRNGRPN_Test_TestMethod1(){
List<Lead> leadMap = new List<Lead>();
List<Lead> insertList = new List<Lead>();
Lead Ld = new Lead(FirstName='Name2', Web_To_Lead__c=TRUE, H_M__c='12345678901', WTL_G__c='1234567');
insert Ld;
insertList.add(Ld);
CreateNewLead.createnewrecords(insertList);
}
}
I'm getting 0% coverage on this class however I'm not sure on what I'm doing wrong. Can someone please help?





Please note that Questions about how to pass Trailhead challenges are not on topic, because these challenges are intended to be independent demonstrations of your abilities.
Trailhead Help (https://trailhead.salesforce.com/en/help?support=home) can provide assistance for situations where Trailhead does not appear to be functioning correctly. You can reach out to them if this is the case.
Please close the thread by selected as Best Answer so that we can keep our community clean
Thanks!
Messaging is just the Namespace and we have SingleEmailMessage class in it.
Let me know if you need any further information.
If this solution helps, Please mark it as best answer.
Thanks,