• Jayni belani
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hello,
Can anyone tell when we got this kind of error and how to resolve it ?
I checked the data category name and group data category name in the Data category setup but no change developer names are matching.

Please provide the solution.
Hello,
Can anyone tell when we got this kind of error and how to resolve it ?
I checked the data category name and group data category name in the Data category setup but no change developer names are matching.

Please provide the solution.
Help me to figure out why when I try to update the Account without Opps it doesn't create two new Opps as per below logic.
Here is my helper class
public with sharing class AccountWithTwoDefaultOpp {
    public static void addTwoDefaultOpptToAcct(List<Account> acctList) {

        List<Opportunity> oppList = new List<Opportunity>();

        for (Account acct : acctList) {

            Opportunity opp = new Opportunity();
            opp.Name = acct.Name + ' Default Residential Opp';
            opp.StageName = 'Prospecting';
            opp.CloseDate = System.today().addMonths(1);
            opp.AccountId = acct.Id;
            oppList.add(opp);

            Opportunity opp2 = new Opportunity();
            opp2.Name = acct.Name + 'Default Commercial Opp';
            opp2.StageName = 'Prospecting';
            opp2.CloseDate = System.today().addMonths(1);
            opp2.AccountId = acct.Id;
            oppList.add(opp2);
        }
        insert oppList;
    }
    public static void updateAccount(List<Account> acctList2) {

        List<Opportunity> oppList2 = new List<Opportunity>();

        Map<Id, Account> acctsTypeProspect = new Map<Id, Account>(
        [
                SELECT Id, Name, Type
                FROM Account
                WHERE Type = 'Prospect'
                AND Id NOT IN (SELECT AccountId FROM Opportunity) AND Id IN :acctList2
        ]);

        for (Account account : acctList2) {
            if(account.Type == 'Prospect'){
        }
            for (Opportunity opp : oppList2) {

                if (acctsTypeProspect.get(account.Id).Opportunities.isEmpty()) {

                    Opportunity opp1 = new Opportunity();
                    opp1.Name = 'Default Residential Opp';
                    opp1.AccountId = account.Id;
                    opp1.CloseDate = System.today().addMonths(1);
                    opp1.StageName = 'Prospecting';
                    oppList2.add(opp1);

                    Opportunity opp2 = new Opportunity();
                    opp2.Name = 'Default Commercial Opp';
                    opp2.AccountId = account.Id;
                    opp2.CloseDate = System.today().addMonths(1);
                    opp2.StageName = 'Prospecting';
                    oppList2.add(opp2);
                }

            }
            if(oppList2.size()>0){
                insert oppList2;

            }
        }

    }
}
And Trigger 
trigger AddTwoOppToNewAccount on Account (after insert, after update) {
    if (Trigger.isInsert && Trigger.isAfter){
        AccountWithTwoDefaultOpp.addTwoDefaultOpptToAcct(Trigger.new);
    }

    if  (Trigger.isUpdate) {
        AccountWithTwoDefaultOpp.updateAccount(Trigger.new);
    }
}