• agrawal mukul
  • NEWBIE
  • 55 Points
  • Member since 2021
  • lead salesforce dev
  • Accenture


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 10
    Replies
Hi guys, I want to write a trigger on account for which if there is any contact whose inactive(custom field) is not ticked then for the parent account it should display the error msg on inactive field. Inactive is a custom checkbox type field both on account and contact. Here is my code.

public class Assessment1TriggerHandler {

    public static void onBeforeInsert(List<Account> acList){
        
        Set<Id> acIDs = new Set<Id>();
        for(Account a:acList){
            acIDs.add(a.id);
        }
        if(acIDs !=null){  
            try{
                List<Account> newAccs = [Select id, Inactive__c, (Select id, accountId, Inactive__c From Contacts)
                                         From Account Where Id IN: acIDs];
                List<Contact> inactCons = new List<Contact>();
                System.debug('===newAcs======>'+newAccs);
                for(Account ac : newAccs){
                    for(Contact c: ac.contacts){
                        System.debug('===Contact==>'+c);                        
                        System.debug('====InactiveField====>'+c.Inactive__c);
                        if(!c.Inactive__c){
                            inactCons.add(c);     
                            System.debug('Contact List size  ===>'+inactCons.size());  
                             if(inactCons.size()>0){
                                if(ac.Inactive__c == true){
                                    System.debug('===ac.Inactive__c===>'+ac.Inactive__c);
                                    ac.Inactive__c.addError('Test error');
                                }
                            }
                        }                       
                    }
                }
            }
            Catch(Exception e){
                System.debug('ErrorLine ='+e.getLineNumber() + 'ErrorMsg: '+e.getMessage());
            }
        }
    }
}

ac.Inactive__c.addError('Test error'); is throwing error - Invalid data on UI. Please help me out
Here is the code but it won't work properly if I attached document in the notes and Attachment section then also it will throw an error. if any one know then please help me.
Code::  

trigger closeWonMustAttach on Opportunity (before insert, before update) {
  // Find all opportunities and their list of attachments...
  Map<Id,Opportunity> opportunityAttachments = new Map<Id,Opportunity>(
    [SELECT Id,(SELECT Id FROM Attachments) FROM Opportunity WHERE Id IN :Trigger.new]
  );
  // For each opportunity being created or modified...
  for(Opportunity opp:Trigger.new) {
    if(opp.StageName=='Closed Won' && // If it is changing to closed/won...
      (!opportunityAttachments.containsKey(opp.id) || // And the opportunity was not found (Insert)...
       opportunityAttachments.get(opp.id).Attachments == null || // Or the opportunity attachment list was null...
       opportunityAttachments.get(opp.id).Attachments.size()==0)) { // Or the attachment list has no entries...
      opp.StageName.addError('You must first attach a file to this opportunity before changing to Closed/Won.'); // So we prevent saving here.
    }
  }
}
  • September 20, 2021
  • Like
  • 0
Using batch Create a scheduler which will run midnight daily. The scheduler will  check for duplicate Accounts and if find any then it will merge the accounts and relate its child records(Contacts,Opportunity and Cases) to the one which is existing.
Hi guys, I want to write a trigger on account for which if there is any contact whose inactive(custom field) is not ticked then for the parent account it should display the error msg on inactive field. Inactive is a custom checkbox type field both on account and contact. Here is my code.

public class Assessment1TriggerHandler {

    public static void onBeforeInsert(List<Account> acList){
        
        Set<Id> acIDs = new Set<Id>();
        for(Account a:acList){
            acIDs.add(a.id);
        }
        if(acIDs !=null){  
            try{
                List<Account> newAccs = [Select id, Inactive__c, (Select id, accountId, Inactive__c From Contacts)
                                         From Account Where Id IN: acIDs];
                List<Contact> inactCons = new List<Contact>();
                System.debug('===newAcs======>'+newAccs);
                for(Account ac : newAccs){
                    for(Contact c: ac.contacts){
                        System.debug('===Contact==>'+c);                        
                        System.debug('====InactiveField====>'+c.Inactive__c);
                        if(!c.Inactive__c){
                            inactCons.add(c);     
                            System.debug('Contact List size  ===>'+inactCons.size());  
                             if(inactCons.size()>0){
                                if(ac.Inactive__c == true){
                                    System.debug('===ac.Inactive__c===>'+ac.Inactive__c);
                                    ac.Inactive__c.addError('Test error');
                                }
                            }
                        }                       
                    }
                }
            }
            Catch(Exception e){
                System.debug('ErrorLine ='+e.getLineNumber() + 'ErrorMsg: '+e.getMessage());
            }
        }
    }
}

ac.Inactive__c.addError('Test error'); is throwing error - Invalid data on UI. Please help me out

Hi folks,

Running into an error and not quite sure why. I am trying to schedule a cron job for the last day of the month. My cron expression is:

0 30 22 L * ?

Which should fire at 10:30 PM on the last day of the month, for every month, specifying no day of week as far as I can tell from the documentation:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm

However, I am getting the error:

"Support for specifying 'L' and 'LW' with other days of the month is not implemented"

I was getting this error before when I WAS trying to specify some days of the month in addition to the last day, but now I am stumped as to why I am hitting this when I am only specifying "L" in the Day of Month portion of the cron expression. Any ideas would be appreciated.

Thanks,

Chris

  • September 21, 2021
  • Like
  • 0
Hello Devs,

I'm new to Flow and having issues assigning adding a Record (Single) Variable type to a Record Collection variable. The logical order is:

1. An Apex Action is kicked off, returning a data type of Apex-Defined Data Type list
2. A Loop is kicked off iterating through the list of the Apex-Defined Data Type
3. Assign a Record Data Type the attributes of the Apex-Defined Data Type
4. Add the Record into a Record Collection varible.

The issue that I am having is that it looks like nothing is being added into the Record Collection. The debug results I get reads as: 

ASSIGNMENT: Assign_to_Record_Collection
{!oanda_exchange_rate_record_collection} Add {!oanda_exchange_rate_record}
Result
{!oanda_exchange_rate_record_collection} = "[OandaExchangeRate__c (No ID)]"


Please see screenshots below for context.

Loop ScreenshotUser-added image
Loop Element Configuration
User-added image

Assign to Record Configuration
User-added image


Assign to Record Collection Configuration

User-added image

Assign to Record Debug

User-added image

 
Here is the code but it won't work properly if I attached document in the notes and Attachment section then also it will throw an error. if any one know then please help me.
Code::  

trigger closeWonMustAttach on Opportunity (before insert, before update) {
  // Find all opportunities and their list of attachments...
  Map<Id,Opportunity> opportunityAttachments = new Map<Id,Opportunity>(
    [SELECT Id,(SELECT Id FROM Attachments) FROM Opportunity WHERE Id IN :Trigger.new]
  );
  // For each opportunity being created or modified...
  for(Opportunity opp:Trigger.new) {
    if(opp.StageName=='Closed Won' && // If it is changing to closed/won...
      (!opportunityAttachments.containsKey(opp.id) || // And the opportunity was not found (Insert)...
       opportunityAttachments.get(opp.id).Attachments == null || // Or the opportunity attachment list was null...
       opportunityAttachments.get(opp.id).Attachments.size()==0)) { // Or the attachment list has no entries...
      opp.StageName.addError('You must first attach a file to this opportunity before changing to Closed/Won.'); // So we prevent saving here.
    }
  }
}
  • September 20, 2021
  • Like
  • 0