• Daniel Madhure
  • NEWBIE
  • 0 Points
  • Member since 2015
  • Salesforce Architect
  • Capgemini Norge

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
Hello Guys,

I have user (lookup field )on opportunty i want to make that field manadatory through trigger..

i want show message user is manadatory field please select user.

trigger opportunityTeamMemberTrigger  on OpportunityTeamMember (Before Insert, Before Update) {
     for (OpportunityTeamMember oppTeam: Trigger.new)
       { 
           
           if(oppTeam.User == Null){
           
           
           oppTeam.addError('please select the user');
                     
           }
                  
                } 
      
}


the trigger is active and it not working can any one tell what went wrong 
Error ;- System.LimitException: Apex CPU time limit exceeded

Trigger.accountTrigger: line 35, column 1

trigger accountTrigger on Account (before update,before insert, before delete, After Insert, After Update, After Undelete) {
    
    boolean bByPass = false;
    if (UPSUtility.ByPassCurrentUser() != null && UPSUtility.ByPassCurrentUser().Bypass_Account_Object_Validation_Rules__c)
       bByPass = true;

    if (!bByPass){
        if(!Constants.bTriggerRecursionCheck)
        {
            if (Trigger.IsBefore && (Trigger.IsInsert || Trigger.IsUpdate)){
                Constants.bTriggerRecursionCheck = true;
                AccountTriggerHandler.validateProspectAccountForSite(Trigger.new);
                AccountTriggerHandler.UpdateDistrictName(trigger.new);
                 //AccountTriggerHandler.HIEChangeToNoneInsert(Trigger.new);
           }
            
            if (Trigger.IsBefore && Trigger.IsUpdate){
                AccountTriggerHandler.OwnerChangeUpdate(Trigger.oldMap,Trigger.newMap,Trigger.new); 
                //AccountTriggerHandler.HIEChangeToNoneUpdate(Trigger.oldMap,Trigger.newMap,Trigger.new);
                AccountTriggerHandler.assignedAccountRVARecordType(Trigger.old,Trigger.new,true); 
            }

            if (Trigger.IsBefore && Trigger.IsInsert){
                AccountTriggerHandler.assignedAccountRVARecordType(null,Trigger.new,false); 
            }
        }
        if(Trigger.isAfter && Trigger.isUpdate){
            AccountTriggerHandler.assignedLeadContactRVARecordType(Trigger.old,Trigger.new);
        }
    }
    
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete)){
        Map<Id,Account> mapAccToProcess = new Map<Id,Account>();
         Set<Id>AccountIds = new set<ID>();
        for(Account acc : Trigger.New){
            if(acc.RecordType.DeveloperName != 'Site'){
                if(Trigger.isInsert || Trigger.isUndelete){
                    mapAccToProcess.put(acc.Id, acc);    
                }
                else if(acc.OwnerId != Trigger.oldMap.get(acc.Id).OwnerId || acc.Name != Trigger.oldMap.get(acc.Id).Name || acc.Account_Number_Interface_Key__c != Trigger.oldMap.get(acc.Id).Account_Number_Interface_Key__c){
                    mapAccToProcess.put(acc.Id, acc);
                    AccountIds.add(acc.Id);
                   system.debug('Account Ids' +AccountIds);
                    
                }
            }   
        }
        if(AccountIds.size() >0){
            AccountTriggerHandler.updatePTOwner(AccountIds);
        }
        if(mapAccToProcess.size() > 0){
            AccountTriggerHandler.createUpdateSAD(mapAccToProcess);
        }    
    }
    
    if(Trigger.isBefore && Trigger.isDelete){
        AccountTriggerHandler.deleteSAD(Trigger.oldMap);
    }    
    
    

}




















Test class-:
                
 
@isTest
private  class AccountHeirarchy_Build_Test 
{
   public static integer iter = 0;
   public static integer totalAccountCount = 0;
   
   static list<Account> insertAccountHeirarchy() 
    {
       list<Account> AllAccounts = new list<Account>();
       Account eGnAccount = new Account(name = 'EGN',Top_Level_Parent_Account_Number__c = 'ABC-123-DEF-456-GHIJ');   
       insert eGnAccount;    
       Account parnetAccount = eGnAccount;
       list<Account> SubLevelAccount = new list<Account>();
       
       for (integer iIterationCount =0;iIterationCount<10;iIterationCount++)
        {
            string AccName =  String.fromCharArray(new Integer[]{65 + iIterationCount}) + ':';
            SubLevelAccount = UtilityForTestClass.createAccountBulk( 100, parnetAccount,AccName);
            insert SubLevelAccount;
            system.debug('check ---'+SubLevelAccount.size());
            parnetAccount = SubLevelAccount[50];
            AllAccounts.addAll(SubLevelAccount);
        }   
       
       return AllAccounts;
    }
    
    static TestMethod void checkAccountHeirArchydesearilisation()
    {
        UPSTestUtility testUtilObj = new UPSTestUtility();
        
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];
        try
        {
            UPSD_Bypass_Validation_Rules_Triggers__c custSettingBypassValidation = testUtilObj.buildBypassValidationRulesCustomSettingRecord(p.id,'AccountHeirarchy_Build_Test');
            if(custSettingBypassValidation!=null)
            {
                insert custSettingBypassValidation;
            }
        }
        catch(Exception ex)
        {
            System.debug('Exception caught - '+ex.getMessage());
        }
        User stdUser = new User(Alias = 'standt', Email='standardUPSuser@UPSTEST.com',
            EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
            TimeZoneSidKey='America/Los_Angeles',LocaleSidKey='en_US', ProfileId = p.Id,UserName='standardUPSuser@UPSTEST.com');
        insert stdUser;
        list<Account> AllAccounts = insertAccountHeirarchy();
        integer iRanDomAccountNumber = integer.Valueof(Math.Floor(Math.Random()*10));
        AccountTeamMember atm = new AccountTeamMember(userId = stdUser.id, AccountId = AllAccounts[iRanDomAccountNumber].id);
        insert atm;
        Account acct= new Account(name='test', Top_Level_Parent_Account_Number__c='ABCT123456609');
        insert acct;
        Account acct1= new Account(name='test', Top_Level_Parent_Account_Number__c='ABCT123456609', ParentId= acct.id);
        insert acct1;
        Account acct2= new Account(name='test', Top_Level_Parent_Account_Number__c='ABCT123456609', ParentId= acct1.id);
        insert acct2;
        
        integer iCount = [select count() from Account];
        system.debug('# Account Records--' + iCount);
        //AccountHeirarchy_Built AccHeir = new AccountHeirarchy_Built();
        Test.startTest();
        string jSonReturnVal = AccountHeirarchy_Built.GetAlltheAccountsOfUser(stdUser.id);
        //AccountHeirarchyPageClass.GetAlltheAccountsOfUser(acct1.Id);
        Test.stopTest();
        list<AccountHeirarchy_Built.AccountBox>  lstAccountBox = (list<AccountHeirarchy_Built.AccountBox>)JSON.deserialize(jSonReturnVal,list<AccountHeirarchy_Built.AccountBox>.class);
        integer iCountLstSize = lstAccountBox.size() - 1;
        //system.assert(lstAccountBox[0].sAccountname == 'EGN', 'Apex Account is not EGN');
        checkAssertion(lstAccountBox[0].lstchild );
        //system.assert(AllAccounts.size() == totalAccountCount, 'Account Insert do match with number of Account parsed');
        
    }
    
    static void checkAssertion(list<AccountHeirarchy_Built.AccountBox> lstAccountBox )
    {
        integer countThisIteration = 0;
        
        for (AccountHeirarchy_Built.AccountBox acc : lstAccountBox)
         {
            //system.assert(acc.sAccountName.contains(String.fromCharArray(new Integer[]{65 + iter}) + ':'),
                // '----sAccountName----' + acc.sAccountName + '---string ----' 
                //+ String.fromCharArray(new Integer[]{65 + iter}) + ':' + '---------pop--' + countThisIteration + '---Iter --- ' + iter);
                totalAccountCount++;
            if (!acc.lstchild.IsEmpty())
             {
                iter++;
                checkAssertion(acc.lstchild);
                iter--;
             }
            countThisIteration++;       
         }
    }
    
}
Hello Guys I have two validation rules on opportunty object i want to merge both of them can you please help me how to do that?

First validation rule -:

​Error Message :- If Is Seasonal is checked then Seasonal Start Date and Seasonal End Date are mandatory

AND(
NOT( $Setup.UPSD_Bypass_Validation_Rules_Triggers__c.Bypass_Opportunity_Obj_Validation_Rules__c), 
Is_Seasonal__c = true,
OR(ISBLANK(Seasonal_Start_Date__c),
ISBLANK(Seasonal_End_Date__c))
)


Second validation rule -: 
Error message :- Seasonal Start Date cannot be greater than Seasonal End Date

AND(
NOT( $Setup.UPSD_Bypass_Validation_Rules_Triggers__c.Bypass_Opportunity_Obj_Validation_Rules__c), 
NOT(ISBLANK( Seasonal_Start_Date__c )),
NOT(ISBLANK( Seasonal_End_Date__c )),
Seasonal_Start_Date__c > Seasonal_End_Date__c 
)

 
Hello Guys,

there are multiple validation on my opportuity object. i wan to combine some of them,
can you please guide how to do that.

My first validation rule:

You can update Actions associated to the Build Stage only :

AND( 
NOT( $Setup.UPSD_Bypass_Validation_Rules_Triggers__c.Bypass_Opportunity_Obj_Validation_Rules__c),
ISPICKVAL(StageName ,'Build'), 
OR(
ISCHANGED(Develop_Call_Plan__c),
ISCHANGED(Identify_Key_Decision_Makers_Influencers__c),
ISCHANGED(Uncover_Challenges_and_Develop_Needs__c),
ISCHANGED(Assess_Size_Opportunity__c),
ISCHANGED(Present_Value_Proposition_Pricing__c),
ISCHANGED(Address_Concerns_Objections__c),
ISCHANGED(Finalize_Implementation_Plan__c),
ISCHANGED(Engage_UPS_Resources__c),
ISCHANGED(Customer_Training__c),
ISCHANGED(Anticipate_Competitive_Response__c),
ISCHANGED(Confirm_New_Revenue_Pursue_Full_Adop__c)
)
)


2nd validation : You can update Actions associated to the Closed Stage only

AND( 
NOT( $Setup.UPSD_Bypass_Validation_Rules_Triggers__c.Bypass_Opportunity_Obj_Validation_Rules__c), 
ISPICKVAL(StageName ,'Closed'), 
OR( 
ISCHANGED(Develop_Call_Plan__c),
ISCHANGED(Identify_Key_Decision_Makers_Influencers__c),
ISCHANGED(Uncover_Challenges_and_Develop_Needs__c),
ISCHANGED(Assess_Size_Opportunity__c),
ISCHANGED(Align_UPS_Solutions_Resources__c),
ISCHANGED(Quantify_Value__c),
ISCHANGED(Establish_Pricing__c),
ISCHANGED(Create_Value_Proposal_Impl_Plan__c),
ISCHANGED(Present_Value_Proposition_Pricing__c),
ISCHANGED(Address_Concerns_Objections__c),
ISCHANGED(Finalize_Implementation_Plan__c),
ISCHANGED(Engage_UPS_Resources__c),
ISCHANGED(Customer_Training__c),
ISCHANGED(Anticipate_Competitive_Response__c),
ISCHANGED(Confirm_New_Revenue_Pursue_Full_Adop__c) 

)



can u please tell me how i can merge this validation rules

 
How many Trailhead Playground can I have in a single account? There is a limit of 10?
#trailhead #playground
Hello Guys I have two validation rules on opportunty object i want to merge both of them can you please help me how to do that?

First validation rule -:

​Error Message :- If Is Seasonal is checked then Seasonal Start Date and Seasonal End Date are mandatory

AND(
NOT( $Setup.UPSD_Bypass_Validation_Rules_Triggers__c.Bypass_Opportunity_Obj_Validation_Rules__c), 
Is_Seasonal__c = true,
OR(ISBLANK(Seasonal_Start_Date__c),
ISBLANK(Seasonal_End_Date__c))
)


Second validation rule -: 
Error message :- Seasonal Start Date cannot be greater than Seasonal End Date

AND(
NOT( $Setup.UPSD_Bypass_Validation_Rules_Triggers__c.Bypass_Opportunity_Obj_Validation_Rules__c), 
NOT(ISBLANK( Seasonal_Start_Date__c )),
NOT(ISBLANK( Seasonal_End_Date__c )),
Seasonal_Start_Date__c > Seasonal_End_Date__c 
)

 
I am practicing on trailhead via using my developer org. The chalenging asked me to Create a Guest Administrator and deactivate it. I am currenly the System Administrator of my developer org. We have only one license for System Administrator. How should we solve this issue in order to:
Create a new user using the System Administrator profile and then deactivate that user to preserve the licenses in your org.The new user must use the System Administrator Profile.
The username for the new user must include 'guestadmin' somewhere in it.
The new user must be inactive.
I need some hints or advices. Thanks.
Hi,

I try to convert decimal value: 2152412850.50 to integer by using intValue() method but this method return -2142554446.
It happen for some value only. Is there any way to fix this problem or work around to convert decimal value to integer.

Thanks,