• suvarna Reddy
  • 0 Points
  • Member since 2019

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 6
trigger UpdateChildWithParent on Account (after insert,after update) {
       List<Account> accList = new List<Account>();
        Set<Id> UpdatedCaseIds = new Set<Id>(); 
        for(Account acc : Trigger.new) {
        Map<Id, RecordType> recordTypeMap = new Map<Id, RecordType>([SELECT DeveloperName 
                                                                     FROM RecordType 
                                                                     WHERE Id IN :UpdatedCaseIds]);
         Map<ID, Account> mapAccounts = new Map<ID, Account>([SELECT Id, Status__c 
                                                              FROM Account where Id IN :UpdatedCaseIds]);
        for(Account acc1 : Trigger.new) {
                   RecordType optyRecordType = recordTypeMap.get(acc1.RecordTypeId);       
            if(optyRecordType != null) {            
                      if(optyRecordType.DeveloperName == 'Brand') {                
                 List<Account> AccountForUpdating1 = [SELECT Status__c  FROM Account 
                                                      WHERE Id IN :UpdatedCaseIds]; 
                List<Account> AccountForUpdating2 = [SELECT Status__c  FROM Account 
                                                      WHERE Id IN :UpdatedCaseIds];                 
                List<Opportunity> OppForUpdating1 =[SELECT Status__c FROM Opportunity
                                                      WHERE Id IN:UpdatedCaseIds];
                  List<Opportunity> OppForUpdating2 =[SELECT Status__c FROM Opportunity
                                                      WHERE Id IN:UpdatedCaseIds];               
                                for(Account childObj1:Trigger.new){ 
                           for(Account childObj2:Trigger.new){
                       for(Opportunity opp1:OppForUpdating1){
                         Account acc = mapAccounts.get(opp1.AccountId);
                             acc.Status__c = opp1.Status__c ;                     
                      Update AccountForUpdating1;
              else if(optyRecordType.DeveloperName == 'Merch Owner') {
                    List<Account> AccountUpdating3 = [SELECT AccountManager__c  FROM Account 
                                                     WHERE Id IN :UpdatedCaseIds ];
                    List<Account> AccountUpdating4 = [SELECT AccountManager__c  FROM Account 
                                                     WHERE Id IN :UpdatedCaseIds ];
                    List<Opportunity> OppForUpdating =[SELECT AccountManager__c FROM Opportunity
                                                       WHERE Id IN:UpdatedCaseIds];
                    List<Opportunity> OppForUpdating4 =[SELECT AccountManager__c FROM Opportunity
                                                       WHERE Id IN:UpdatedCaseIds];
                       for(Account childObj3:Trigger.new){ 
                          // System.debug('>>childObj3>>>'+AccountUpdating3);                            
                      for(Account childObj4:Trigger.new){
                            // System.debug('>>childObj4>>>'+AccountUpdating4);
                    for (Opportunity opp : OppForUpdating) {
                    if (opp.AccountManager__c != null) {
                            Account a = mapAccounts.get(opp.AccountManager__c);          
                    update AccountUpdating3;       
Hi All,

Can anyone please help me with bellow challenge.

Create an Apex trigger for Account that matches Shipping Address Postal Code with Billing Address Postal Code based on a custom field.
For this challenge, you need to create a trigger that, before insert or update, checks for a checkbox, and if the checkbox field is true, sets the Shipping Postal Code (whose API name is ShippingPostalCode) to be the same as the Billing Postal Code (BillingPostalCode).The Apex trigger must be called 'AccountAddressTrigger'.
The Account object will need a new custom checkbox that should have the Field Label 'Match Billing Address' and Field Name of 'Match_Billing_Address'. The resulting API Name should be 'Match_Billing_Address__c'.
With 'AccountAddressTrigger' active, if an Account has a Billing Postal Code and 'Match_Billing_Address__c' is true, the record should have the Shipping Postal Code set to match on insert or update.

For above challenge i tried with following code but looks like it doesnt mach the requirement.

trigger AccountAddressTrigger on Account (before insert, before update) {
    for(Account a : Trigger.new){
        If (a.Match_Billing_Address__c = true) {
            /*ShippingPostalCode = BillingPostalCode;*/


Please help me
Hello everyone,

I'm configuring Salesforce for a non-profit and I'm using Salesforce enterprise with the Non-Profit Starter Pack. We're linking our opportunities object to both contacts and accounts/households and we want our users to be able to, when filling up the opportunity form, select the contact that made the donation from a custom contact lookup field (Contact_Name__c) and upon creating the record the standard Account lookup field will be filled up with this contact's account/household name automatically. This way our users won't have to manually fill in both the contact and account fields for every opportunity record they wish to create.

This is the current trigger iteration I'm using:

trigger UpdateRegistrationHousehold on Opportunity (before insert, before update) 
    for (Opportunity a:trigger.new)
        if(a.recordtypeID == '012o0000000NnqM')   
        {a.Account.Name = a.Contact_Name__r.Account.Name;}

We want to implement this functionality only on a particular opportunity record type.

This particular code structure has worked for me when updating other fields prior to this, but for this specific issue it's been yielding errors and driving me nuts. I've been tweaking this bit of code a bit and depending on my tweaks, 1 of two things seems to happen: either the Account field remains unpopulated, or the form doesn't save and I get this error: Error:Apex trigger UpdateRegistrationHousehold caused an unexpected exception, contact your administrator: UpdateRegistrationHousehold: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateRegistrationHousehold: line 6, column 1

I have limited coding knowledge so I'm looking forward to hearing from you guys and learning more in the process! Cheers! :)

Can someone help me with a trigger that would update the contact record owner with account record owner automatically?  I am not too familiar with triggers, hence why I am asking for help, and desperately want to stay away from ongoing data loads.  Thank you in advance for anyone that can assist! 

Does anyone know how I'd go about creating a trigger to convert a lead to an account contact and oppty, based upon a field in the lead?  For example, A lead score of > 30, I'd like to trigger the lead to automatically convert, and kick off a notification email. 


Has anyone done this before?