Apex Triggers - 47 (Accenture Interview Scenario)

Apex Triggers - 47 (Accenture Interview Scenario)

SFDC Ninja

7 месяцев назад

8,173 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@sameerqadri9877
@sameerqadri9877 - 07.03.2024 08:45

Thx a lot man you helped as a lot !!!
But you posted more than 47 trigger scenarios and how much Experience persons will get this type of questions in the interview as a developer ??
2+ or what ? how much

Ответить
@abhijit14820
@abhijit14820 - 07.03.2024 19:43

Thank you for another trigger scenario sir

Ответить
@abhijit14820
@abhijit14820 - 07.03.2024 19:46

Sir could you please explain how to implement below trigger.
This was given by Tripathi sir. He said he will ask you to implement it.
Please sir if possible do video on this. I tried it but didn't get desired result.
There is a secondary owner look up field to user on account object every time an object is created will have to create a share record and share that particular account with the secondary owner and when accounts get updated this field is change we have to remove previously shared record which got created earlier and we have to create a new record with the updated value on it.
Thank you in advance!

Ответить
@goldylodhi2116
@goldylodhi2116 - 09.03.2024 21:16

Very well explained sir

Ответить
@VishnuReddy-c2q
@VishnuReddy-c2q - 12.03.2024 13:56

In SOQL can we use ORDER BY Amount DESC LIMIT 1.....?

Ответить
@himadripaul7332
@himadripaul7332 - 13.03.2024 01:35

Sir, you changed the approach this is similar to trigger 16 where you used sub query any reason for that ???

Ответить
@madhumohan2952
@madhumohan2952 - 13.03.2024 14:45

can any one say as if we are avoiding aggregate query , so can we have this query to fetch the highest amount like : list<opportunity> opplist = [select id , amount, accountId from amount where accountid IN:accids and order by amount desc limit 1];

Ответить
@madhumohan2952
@madhumohan2952 - 13.03.2024 14:55

can you please say sir will this work ?? i am not able to get the output , can anyone say where it is going wrong?


set<id> accids = new set<id>();
for(opportunity opp:opplist)
{
if(oldmap== null && opp.amount!=null && opp.AccountId != null)
{
accids.add(opp.AccountId);
}
else if(oldmap!=null)
{
if(oldmap.get(opp.id).accountId != opp.AccountId)
{
accids.add(opp.accountId);
accids.add(oldmap.get(opp.id).accountId);
}
else if(opp.Amount != oldmap.get(opp.id).amount)
{
accids.add(opp.AccountId);
}
}

}
system.debug('accids' +accids);

list<account> acclist = [select id , description from account where id in:accids];
list<opportunity> opplist1 = [select id ,amount, accountId from opportunity where accountID in:accids order by amount desc limit 1];
system.debug('highest opportunity' +opplist1);
map<id,string> stringmap= new map<id,string>();
for(opportunity opp: opplist1)
{
stringmap.put(opp.AccountId, opp.name);
}
system.debug('stringmap' +stringmap);


list<account> acclist1= new list<account>();
for(account acc: acclist)
{
if(stringmap.containskey(acc.id))
{
acc.Description = stringmap.get(acc.id);
acclist1.add(acc);
}
}
if(acclist1.size()>0)
{
update acclist1;
}

Ответить
@adeshtiwari5112
@adeshtiwari5112 - 15.03.2024 17:26

please explain trigger with visualization, like for each condition that you have mentioned, give example by doing a quick practical in SF org

Ответить
@hekkelkelseheklalallkh8161
@hekkelkelseheklalallkh8161 - 17.03.2024 00:46

Hi, I have a small doubt, does your code work in the scenario where An Account has only one related opportunity and that opportunity is reparented from this Account to another account........ For the new account, your code works fine, but I have doubt whether for old account the field will be updated to empty as I think the oppMap.get(IDs).name will return System.nullpointer , attempt to de-reference a null object exception, correct me if I am wrong, and explain me the scenario please.

Ответить
@ShwetaBanne
@ShwetaBanne - 19.03.2024 09:06

whenever the contact is created if contact has any related account then if account doesn't have any related opportunity it will create new opp for that account , if account has any related opportunity then the sum of amount of opportunity stored in related account custom field - asked in interview .can you give solution

Ответить
@smitsism
@smitsism - 23.03.2024 00:20

yOU ARE DOINGAMAZING, CAN YOU HELP I NMORE AMAZON LEVEL INTERVIEW?

Ответить
@vipulugle1316
@vipulugle1316 - 26.03.2024 09:24

When the account is updated, send an email to the account owner with the details of contact modified between the last update of account vs current update.
NTT Data interview question.
Pls make a solution video on this scenario, I request.🙏

Ответить
@sainathkide3230
@sainathkide3230 - 01.04.2024 23:03

Can we use parent child query with descending amount and then using first opportunity we cane store it in map ( account id , opp[o].amount )?

Ответить
@manoharsingh1920
@manoharsingh1920 - 16.04.2024 07:54

Your solution is great but It could be more optimized with below code.

List<Account> allAccounts = [SELECT Id, (SELECT Id, Name FROM Opportunities ORDER BY AMOUNT DESC LIMIT 1) FROM Account WHERE Id IN : accountIds];
if(!allAccounts.isEmpty()){
For(Account acc : allAccounts){
if(!acc.Opportunities.isEmpty()){
acc.Description = acc.Opportunities[0].Name;
}
}
List<Database.SaveResult> updatedResults = Database.Update(allAccounts,True);
}

Ответить
@MukheshKummithi
@MukheshKummithi - 27.04.2024 15:59

Hi Sir
I got a scenario for trigger in NTTData interview

You have a Parent Object Order and its child OrderLineItems. On Order Object you have a custom field
Number_of_Line_Items.When you insert a new record of the parent object, based on the value in Number_of_Line_Items field, insert
that many OrderLineItems? Can you Please help me sir to solve this

Ответить
@_DheerajIPPILI
@_DheerajIPPILI - 24.06.2024 18:38

Trigger - Solution Approach
trigger AccDes on Opportunity (after insert, after update, after delete,after undelete) {
if (Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)) {
AccountOpp.handleAfterInsertUpdate(Trigger.new);
}
if (Trigger.isAfter && Trigger.isDelete) {
AccountOpp.handleAfterDelete(Trigger.old);
}
if(Trigger.isAfter && Trigger.isUndelete)
{
AccountOpp.handleAfterUndelete(Trigger.new);
}
}

Handler Class -

public class AccountOpp {
public static void handleAfterInsertUpdate(List<Opportunity> newOpList) {
Set<Id> accIds = new Set<Id>();
for (Opportunity o : newOpList) {
if (o.Amount != null) {
accIds.add(o.AccountId);
}
}

if (!accIds.isEmpty()) {
List<Account> accList = [SELECT Id, Name, Description,
(SELECT Id, Amount, Name
FROM Opportunities
ORDER BY Amount DESC
LIMIT 1)
FROM Account
WHERE Id IN :accIds];

if (!accList.isEmpty()) {
for (Account a : accList) {
if (!a.Opportunities.isEmpty()) {
a.Description = a.Opportunities[0].Name;
}
else
{
a.Description = null;
}
}
update accList;
}
}
}

public static void handleAfterInsertUpdate(List<Opportunity> newOpList, List<Opportunity> oldOpList) {
handleAfterInsertUpdate(newOpList); // Reuse the same method for update
}

public static void handleAfterDelete (List<Opportunity> oplist)
{
handleAfterInsertUpdate(oplist); // Reuse the same method for updat

}
public static void handleAfterUndelete (List<Opportunity> oplist)
{
handleAfterInsertUpdate(oplist); // Reuse the same method for update
}
}

Ответить