• Reshmi Sangani 5
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 5
    Replies
I am trying to write a trigger on Account Object.

There are 2 types of Accounts. Product Accounts and Agency Account.
Product accounts have an Agency lookup field.
Requirement:
There is a checkbox field on Agency Accounts called "Agency_Commissionable__c". When this field is checked all the related product Account's( have a checkbox field called) "AdPoint_Sync_Due__c" should be check.
If "Agency_Commissionable__c" on Agency Accounts is unchecked then related Product Account's "AdPoint_Sync_Due__c" should be unchecked.

My Trigger:
//Author:  Reshmi.S
// Name: AccTriggerHandlerUpdAccPaths 
// Created: 09 /25/2020
// Event: after Insert and after update
// Desc: Refresh the child Accounts after Parent Account has been updated
public class AccTriggerHandlerUpdRelAgencyProducts extends TriggerHandlerBase {

    public virtual override void mainEntry(TriggerParameters tp) {

        UpdRelAgencyProducts(tp);
    }

    public virtual override void inProgressEntry(TriggerParameters tp) {

        UpdRelAgencyProducts(tp);
    }
    void UpdRelAgencyProducts(TriggerParameters tp) {

        List < Account > lstToUpdate = new List < Account > ();
        List < Account > checkedAgncyAcc = new List < Account > ();
        List < Account > unCheckedAgncyAcc = new List < Account > ();
        List < Account > ListAcc = (List < Account > ) tp.newList;
        Map < Id, Account > MapAcc = (Map < Id, Account > ) tp.newMap;
        Map < Id, Account > oldAccMap = (Map < Id, Account > ) tp.oldMap;
        Set < Id > checkedsetAccIds = new Set < Id > ();
        Set < Id > unCheckedsetAccIds = new Set < Id > ();
        //Map < id, Account > accMap = new Map < Id, Account > ();

        for (Account acc: ListAcc) {
            if (acc.Agency_Commissionable__c != oldAccMap.get(acc.Id).Agency_Commissionable__c) {
                if (acc.Agency_Commissionable__c == true) {
                    checkedsetAccIds.add(acc.Id);
                } else if (acc.Agency_Commissionable__c == false) {
                    unCheckedsetAccIds.add(acc.Id);
                }
            }
        }
        if (!checkedsetAccIds.isEmpty()) {
            list < Account > accList = [select Id, name, AdPoint_Sync_Due__c, sync__c from Account where Agency__c IN: checkedsetAccIds AND Type = 'product'];

            if (!accList.isEmpty()) {
                for (Account acct: accList) {

                    acct.sync__c = true;
                    lstToUpdate.add(acct);
                }
            }
        } else if (!unCheckedsetAccIds.isEmpty()) {
            list < Account > accLists = [select Id, name, AdPoint_Sync_Due__c, sync__c from Account where Agency__c IN: unCheckedsetAccIds AND Type = 'product'];

            if (!accLists.isEmpty()) {
                for (Account accts: accLists) {

                    accts.sync__c = false;
                    lstToUpdate.add(accts);
                }
            }
        }

        if (lstToUpdate.size() > 0) database.update(lstToUpdate);
    }

}

When I am trying to create a new product record, the following error is coming up
Apex trigger AccountTrigger caused an unexpected exception, contact your administrator: AccountTrigger: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: ()
There is a field on the Account record called "Ultimate Parent ID" .(which is a formula field to calculate the Parent Account ID for that Account).
This field is a 15 character text formula field.
I am trying to write an after trigger to update a field "ultimate Parent ID 18".
The functionality of this trigger is to convert the above 15 digit ID to an 18 digit salesforce ID and store it in a field on the Account record.
Apex:
public without sharing class AccTriggerHandlerUpdUltParentId extends TriggerHandlerBase {

    public virtual override void mainEntry(TriggerParameters tp) {

        UpdUltParentID(tp);
    }

    public virtual override void inProgressEntry(TriggerParameters tp) {

        UpdUltParentID(tp);
    }


    void UpdUltParentID(TriggerParameters tp) {

        List < Account > lstToUpdate = new List < Account > ();
        List < Account > ListAcc = (List < Account > ) tp.newList;
        Map < Id, Account > newMapAcc = (Map < Id, Account > ) tp.newMap;
        Map < Id, Account > oldMapAcc = (Map < Id, Account > ) tp.oldMap;
        Set < Id > setAccountIds = new Set < Id > ();
        string idStr;
        id idval;
         for(Account acc : ListAcc){
            setAccountIds.add(acc.Id);
         }

        if (tp.tEvent == 'afterUpdate') {
            for (Account acctNew: ListAcc) {
                    acctNew.Ultimate_Parent_ID_18__c = acctNew.Ultimate_Parent_Id__c;
                    idval = acctNew.Ultimate_Parent_ID_18__c;
                    acctNew.Ultimate_Parent_ID_18__c = idval;
                    lstToUpdate.add(acctNew);
               // }

            }
        }

    }
}
 I am receiving the following error:

Question: Should this trigger be in an Afterupdate or before Update?
I tried in the context of After but there was an error saying "record is read only".
Thank you for the help!
 
I want to create a validation rule on a Custom object which is related to Opportunity
If the opportunity stage is set to "1","2" or "3"
The date field on the Custom object cannot be edited 
 
Requirement: need to display a link (ex: www.w3schools.com" ) when user select "matched" value on a picklist field.
Our organization makes use of Libraries!
We are planning to switch to Lightning.
Will we lose any functionality when this switch happens?
Thank you!

 
I created a link for pdfs stored in files on the Opportunity record. When I switch to lightning and click on the link, salesforce is directly downloading them instead of viewing them?
How can I view the pdfs instead of downloading?
Thank you!
There is a field on the Account record called "Ultimate Parent ID" .(which is a formula field to calculate the Parent Account ID for that Account).
This field is a 15 character text formula field.
I am trying to write an after trigger to update a field "ultimate Parent ID 18".
The functionality of this trigger is to convert the above 15 digit ID to an 18 digit salesforce ID and store it in a field on the Account record.
Apex:
public without sharing class AccTriggerHandlerUpdUltParentId extends TriggerHandlerBase {

    public virtual override void mainEntry(TriggerParameters tp) {

        UpdUltParentID(tp);
    }

    public virtual override void inProgressEntry(TriggerParameters tp) {

        UpdUltParentID(tp);
    }


    void UpdUltParentID(TriggerParameters tp) {

        List < Account > lstToUpdate = new List < Account > ();
        List < Account > ListAcc = (List < Account > ) tp.newList;
        Map < Id, Account > newMapAcc = (Map < Id, Account > ) tp.newMap;
        Map < Id, Account > oldMapAcc = (Map < Id, Account > ) tp.oldMap;
        Set < Id > setAccountIds = new Set < Id > ();
        string idStr;
        id idval;
         for(Account acc : ListAcc){
            setAccountIds.add(acc.Id);
         }

        if (tp.tEvent == 'afterUpdate') {
            for (Account acctNew: ListAcc) {
                    acctNew.Ultimate_Parent_ID_18__c = acctNew.Ultimate_Parent_Id__c;
                    idval = acctNew.Ultimate_Parent_ID_18__c;
                    acctNew.Ultimate_Parent_ID_18__c = idval;
                    lstToUpdate.add(acctNew);
               // }

            }
        }

    }
}
 I am receiving the following error:

Question: Should this trigger be in an Afterupdate or before Update?
I tried in the context of After but there was an error saying "record is read only".
Thank you for the help!
 
I created a link for pdfs stored in files on the Opportunity record. When I switch to lightning and click on the link, salesforce is directly downloading them instead of viewing them?
How can I view the pdfs instead of downloading?
Thank you!
Hi!

I would love to get some quick help with this validation rule:

NOT( 
OR( 
ISBLANK(Last_Name__c),REGEX(Last_Name__c ,"([a-zA-Z-])*")))

What I want is for Last Name to include only a-z, A-Z, hyphens or spaces. 

When I first wrote it as this: REGEX(Last_Name__c ,"([a-zA-Z])*")))  -- without the hyphen, I was getting it to work to allow spaces. However, once I added the hyphen in, the hyphen was allowed but spaces were no longer allowed. 

What am I doing wrong here? 

Thanks!
Stephanie
I'm doing the simple lightning components challenge and have hit this problem in my existing trailhead org and a brand new dev org that I've just created:

Challenge not yet complete... here's what's wrong: 
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: QVWBQHAG