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

Writting an Apex Class
trigger EmailContact on Contact (after insert) { List<Messaging.SingleEmailMessage> emailList= new List<Messaging.SingleEmailMessage>(); EmailTemplate emailTemplate = [Select Id,Subject,Description,HtmlValue,DeveloperName,Body from EmailTemplate where name='Contract Signed Thank you']; for(Contact conObj:Trigger.new){ if (conObj.Email != null) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setTargetObjectId(conObj.Id); mail.setSenderDisplayName('System Administrator'); mail.setUseSignature(false); mail.setBccSender(false); mail.setSaveAsActivity(true); mail.setTemplateID(emailTemplate.Id); mail.toAddresses = new String[]{conObj.Email}; emailList.add(mail); } } if(emailList.size()>0){ Messaging.SendEmailResult[] results = Messaging.sendEmail(emailList); if (results[0].success) { System.debug('The email was sent successfully.'); } else { System.debug('The email failed to send: '+ results[0].errors[0].message); } } }
This is what i have so far. i get an error that lines 9&15 are missing ','
@isTest private class EmailContactTestClass { static testMethod void validateEmailContact() { Contact c = new Contact(LastName='Test',Email='test@test.org'); System.debug(c.LastName); insert c; System.assertEquals(0, Limits.getEmailInvocations(); c = [SELECT id FROM Contact WHERE LastName ='Test' limit 1]; System.assertEquals(1, Limits.getEmailInvocations(); } }

Hi, i need help to improve my test coverage for apex trigger
public static void afterupdate(List<opportunity> optylist,map<id,Opportunity> optyoldmap){
Map<Id,Opportunity>mapopp= new Map<Id,Opportunity>();
List<Project__c> projlist= new List<Project__c>();
for(Opportunity opp:optylist){
if ( opp.StageName != optyoldmap.get( opp.Id ).StageName && (opp.StageName=='closed won' || opp.stageName=='Closed Lost' )){
mapopp.put(opp.id,opp);
}
}
projlist=[Select Status__c ,Opportunity__c from Project__c where Opportunity__c in :mapopp.keyset()];
if(projlist.size()>0){
For(Project__c p:projlist ){
if(mapopp.get( p.Opportunity__c ).StageName =='closed won')
P.status__c='Active';
if(mapopp.get( p.Opportunity__c ).StageName =='closed Lost')
p.Status__c='Cancelled';
}}
update projlist;
}
test class:
@isTest
public class update_projectHandlerTest {
public static testmethod void optyprojectTest(){
list<opportunity> opty = new list<opportunity>();
list<project__c> proj = new list<project__c>();
opportunity op = new opportunity ();
op.stagename = 'qualification';
op.Name='test1';
op.CloseDate = System.today();
opty.add(op);
insert opty;
Project__c p1=new Project__c();
p1.Status__c='Active';
p1.opportunity__c=op.id;
p1.Level_of_Effort__c='medium';
proj.add(p1);
insert proj;
test.startTest();
op.stagename = 'closedwon';
update opty;
p1.Status__c='Active';
update proj;
test.stopTest();
}}
thanks in advance.




You have entered wrong picklist value in the 1st test method. stage name should be closed won not closedwon.
try with below code.
@isTest public class update_projectHandlerTest { public static testmethod void optyprojectTest(){ list<opportunity> opty = new list<opportunity>(); list<project__c> proj = new list<project__c>(); opportunity op = new opportunity (); op.stagename = 'qualification'; op.Name='test1'; op.CloseDate = System.today(); opty.add(op); insert opty; Project__c p1=new Project__c(); p1.Status__c='Active'; p1.opportunity__c=op.id; p1.Level_of_Effort__c='medium'; proj.add(p1); insert proj; test.startTest(); op.stagename = 'closed won'; update opty; p1.Status__c='Active'; update proj; test.stopTest(); } public static testmethod void optyprojectTest1(){ list<opportunity> opty = new list<opportunity>(); list<project__c> proj = new list<project__c>(); opportunity op = new opportunity (); op.stagename = 'qualification'; op.Name='test1'; op.CloseDate = System.today(); opty.add(op); insert opty; Project__c p1=new Project__c(); p1.Status__c='Active'; p1.opportunity__c=op.id; p1.Level_of_Effort__c='medium'; proj.add(p1); insert proj; test.startTest(); op.stagename = 'closed Lost'; update opty; p1.Status__c='Cancelled'; update proj; test.stopTest(); } }
Thanks!!

Making one primary contact for account using lightning flow
If any one of the related contact is true in Primary contact checkbox field then other contacts shoud not have option to check that checkbox field.
How to do this lightning flow? can someone suggest ideas. Thanks




Adding the current record in loop to the variable created above:
Updating the collection:
Entire Flow:
If this solution helps, please mark it as best answer.
If you have any doubts, Feel free to post the comment.
Thanks,
12. What are the different data types that are accepted by name field?
13. Can we change the data type from Text to Auto Number for the Name when we already have?
Ans: I feel the answer is yes. If yes, please do let me know the explanation . If no, let me know the reason as well. Thanks guys.


As name is one of the default field that is created while creating object and also internally it is used for indexing Salesforce has given this permissiong to edit the data type of this field.

Multiple record types for a single record
We like to move forward using record type but want to be sure how the data should be parsed out. Do we need to separate the data (so if we have 2 record types Staff and Student, and we have a contact that is a staff and a student, then there will be a Staff record and a Student record for the same contact).
Or can we have 2 record types applied to the same record?




Hi Demi,
Yes You can have multiple record type applied to the same Object but not to same record.
Let me explain you the concept of record type.
So on the contact object you have to create two record type. one as Staff and another as Student.
Also create two different page layout, one is staff pagelayout and another is student pagealout.
Assing the pagelayout i.e., staff record type should have Staff pagalyout and Student will have student pagelayout.
Create Contact.
When you click the new button to create contact, one modal box will pop up which will ask, for which kind of contact you wanna create. First option will be Staff and the Second will Student.
Choose Staff and then create the Record. It will create the contact record as Staff. Follow same for Student.
How to create the page layout and Record type, follow this article :-
https://trailhead.salesforce.com/en/content/learn/projects/customize-a-salesforce-object/create-record-types
https://www.sfdcpoint.com/salesforce/record-types-in-salesforce/#:~:text=Record%20types%20in%20Salesforce%20allow,different%20picklist%20values%20for%20each.
Hope this helps,
Kindly mark it as the best answer so that it can helps others as well.
Regards,
Priya Ranjan

Because the DoesRequireRecordChangedToMeetCriteria field has the value "true", you also need to set the following fields: Filters.
Hi All,
I am trying to deploy a flow using changesets and keep running into this error while validating below.
"Because the DoesRequireRecordChangedToMeetCriteria field has the value "true", you also need to set the following fields: Filters."
I have included every field that is referenced within the flow in the changeset. The only information I can even find on this "DoesRequireRecordChangedToMeetCriteria" variable is that it is now retrievable through the API. I have tried changing the starting conditions on the flow to even be very basic "everytime a record is created" without any conditional logic and still run into the same error. Does anyone have any idea as to what may be prompting this error? Thanks!




If changing of API version does not work. Then you can try to remove that tag in Metadata and try to deploy it.
If the solution helps, Please mark it as best answer.
Thanks,

Error message in Dev console
I alwaays get error when i try to save something from Dev console
Failed to create createContainerMember for containerId duplicate value found: <unknown> duplicates value on record with id: <unknown>

Follow these stepsGo to Developer Console -> Work Space -> New Workspace
Create a new workspace
Save classes/triggers
*https://help.salesforce.com/apex/HTViewSolution?id=000204953&language=en_US
Try again, it should be fixedIf my answer helps resolve your query, please mark it as the 'Best Answer' and upvote it to benefit others and improve the overall quality of Discussion Forums.
-Thanks
Ashlekh Gera

Test class for apex callout from a trigger
I would like to know to write a test class for a trigger which makes a callout.




Can you check the below example for test class .
https://developer.salesforce.com/forums/?id=9062I000000g3emQAA
If this solution helps, Please mark it as best answer.
Thanks,

Can we access OAS3 for API versions older than 54.0?
I'm trying to access the OAS3 spec for versions older than 54.0 but when I add 53.0 or older, I get a "resource not found" response.
Is there any way to access this or is it not available for anything older than 54.0?
I only recently enabled the OAS3 setting under User Interface so I'm wondering if the versions available are based on when this was done?
https://developer.salesforce.com/blogs/2021/01/learn-moar-with-spring-21-openapi-3-0-spec-for-rest-api
TIA




Answer is no. The API version must be 54.0 or greater to access OAS3.
Refer the below article for more information.
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/openapi_beta.htm
If this helps, Please mark it as best answer.
Thanks!!

How to rename Lightning component

Yes that is correct. You need to delete the component and create new one with new name.
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
The closing parenthesis is missing in System.assertEquals(1, Limits.getEmailInvocations() at both the places because of that you are getting compile-time error.
Try this
@isTest private class EmailContactTestClass {
static testMethod void validateEmailContact() {
Contact c = new Contact(LastName='Test',Email='test@test.org');
System.debug(c.LastName);
insert c;
System.assertEquals(0, Limits.getEmailInvocations());
c = [SELECT id FROM Contact WHERE LastName ='Test' limit 1];
System.assertEquals(1, Limits.getEmailInvocations());
}
}
Kindly mark as best answer if it helps.
Thanks
Shubham Jain