Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Other

Salesforce Apex Trigger interview solved scenarios

Rating
-
Sold
-
Pages
19
Uploaded on
14-05-2023
Written in
2022/2023

In this Document I have shared total of 40+ Apex Trigger Scenarios(Basic to Advance) which are very easy to understand and most important for a salesforce developer to cover before appearing in a interview. It helped me to crack multiple number of Salesforce Interview. Thanks:)

Show more Read less
Institution
Course

Content preview

1.when ever a record is inserted to the account automatically inserted to the contact

trigger SCENARIO1 on Account (after insert) {
list<contact> c=new list<contact>();
for(account a:trigger.new)
{
contact b=new contact();
b.LastName=a.Name;
b.AccountId=a.Id;
c.add(b);



}
insert c;

}
===================================================================================
=====

2.when ever a record is inserted to the contact automatically inserted to the account


trigger scenario2 on Contact (after insert) {
if(Recursive.flag)
{
Recursive.flag=false;
list<account>a=new list<account>();
for(contact c:trigger.new)
{
account a1=new account();
a1.Phone=c.Phone;
a1.Name=c.LastName;
a.add(a1);

}
insert a;
}

Recursive trigger fire:
3.avoid recursive trigger

public class Recursive {
public static boolean flag=true;

}

===================================================================================
===========

3.when ever a create opportunity object record updated total opportunies and total amount in account object

trigger scenario24 on Opportunity (after insert) {
set<id>ids=new set<id>();
for(Opportunity op:trigger.new)

,{
ids.add(op.accountid);
}
list<account>ac=[select Total_opportunities__c,Total_Amount__c,(select id,Amount from Opportunities ) from a
ccount where id=:ids];
for(account a:ac)
{
a.Total_opportunities__c=a.opportunities.size();
decimal sum=0;
for(opportunity p:a.opportunities)
{
sum=sum+p.amount;
}
a.Total_Amount__c=sum;


}
update ac;
}
===================================================================================
===================

4.contact object when ever department equal to cse automatically before inserted email field

trigger scenario4 on Contact (before insert) {
for(contact c:trigger.new)
{
if(c.Department=='CSE')
{
c.Email='';
}
}

}

===================================================================================
========

5.when ever we modify inputout object doctorname automatically update droppoff object text field no relation ship

trigger SCENARIO32 on Inputout__c (after update) {
list<Dropoff1__c>d=[select id,name,Text__c from Dropoff1__c where Text__c='naveen'];
string name;
for(Inputout__c c:trigger.new)
{
name=c.Doctor_Name__c;
}
for(Dropoff1__c dp:d)
{
dp.Text__c=name;
}
update d;

}

, ===================================================================================
=======


6.limit reached the records

trigger SCENARIO6 on Account (before insert,before update) {
integer count=0;
list<account>a=[select id,name from account where createddate=today or lastmodifieddate=today];
for(account ac:trigger.new)
{
count=a.size();
ac.NumberofLocations__c=count;
if(count>2)
{
ac.adderror('reached limit today');
}
}

}

===================================================================================
===========

7.can not inser/update/delete that user account object records

trigger scenario30 on Account (before insert,before update,before delete) {
user u=[select id,name from user where username=''];
if(u.id==userinfo.getUserId())
{
if(trigger.isdelete)
{
for(account a:trigger.old)
{
a.adderror('cant delete record');

}
}
if(trigger.isupdate)
{
for(account b:trigger.new)
{
b.adderror('can not update');
}
}
if(trigger.isinsert)
{
for(account c:trigger.new)
{
c.adderror('can not insert');
}
}
}
}
===================================================================================

Written for

Course

Document information

Uploaded on
May 14, 2023
Number of pages
19
Written in
2022/2023
Type
OTHER
Person
Unknown

Subjects

$3.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
mohammedkousarahmed

Get to know the seller

Seller avatar
mohammedkousarahmed Solutionlabs
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions