• Sambit Sorav
  • NEWBIE
  • 40 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 0
    Replies
Hi everyone, I have a requirment like this - I have a custom field on Account object named Last_Activity__c which is a date type field. If it has values earlier than 45 days FROM TODAY then it should check all its parent accounts and its child accounts. If value is within 45 days then the method should continue checking its parent's Last_Activity__c field value until it finds the value which is outside 45 days. If found a value outside 45 days then it should return true inside apex class. If no value is found outside this range for entire hierarchy then return false. So basically it should check the value of Last_Activity__c in the entire Account Hierarchy.
I need to write a code for this using apex class.
Any help would be appericiated. Thanks!
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, I want to get cookies when I log in into client's website but cookies with HttpOnly flags are not included in getHeaders. Only cookies without HttpOnly flag are returned in headers map. Pls help me with how to resolve this issue.
How can we set session token and cookie inside a mock callout class? Is it possible to set both the things together?
How can I set Data Security in such a way that I am able to hide particular field of an object, where other user has Standard user profile
Hey, Please help me out with the following trigger scenario..

Write an Apex Trigger on Account which adds all the Closed won Opportunity amounts of that Account and shows it on the Account record.
Hi, 

Create an account with name 'test account' & create a field on account - > number of contacts. Write a trigger such that when whenever a new contact is created it is automatically added to 'test account'.

Please help me writing this trigger. I have written the following code. Pls tell me where am I going wrong.
Thanks

trigger InsertContact1 on Contact (after insert) {
      
    Account acList = [Select id, Name from Account where Name = 'Test Account'];
    List<Contact> contList = new List<contact>();
    
    for(Contact c: trigger.new){
        contList.add(c);
    }    insert contList;
    
    if(contList.size()>0){
        for(Contact c: contList){
            c.AccountId = acList.id;
            acList.Number_Of_Contacts__c = integer.valueOf(contList.size());
    }
    }
}