• Sridhar Reddy
  • NEWBIE
  • 20 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies

Hi All,

what are the best options to store the following in terms of Managing,tracking, aceess and sharing with in the salesforce ?

- Training materials(sales reps, business users)
- Project documentation(Tech teams) and
- Deployment documentation(salesforece team)

Hi All, 

Follwing trigger is not working ,Can someone help ?
I couldn't find much in the debug log except a query run.

(following snippet can be simply pasted in the dev org for quick review )

 

trigger A_ConPhoneFromCON on Contact (before insert, before update) {

    // Create a map to store the Account IDs and their corresponding phone numbers
    Map<Id, contact> accountIdToPhone = new Map<Id, contact>();

    for (Contact updatedContact : Trigger.new) {
        // Check if the Contact has an associated Account
        if (updatedContact.AccountId != null) {
            // Add the related Account's ID and phone number to the map
            accountIdToPhone.put(updatedContact.AccountId, updatedContact);
        }
    }

    // Retrieve the related Account records and update the Contacts' phone numbers
    List<Account> relatedAccounts = [SELECT Id, Phone FROM Account WHERE Id IN :accountIdToPhone.keySet()];

    for (Contact updatedContact : Trigger.new) {
        // Check if the Contact is associated with an Account
        if (updatedContact.AccountId != null) {
            // Update the Contact's phone number with the related Account's phone number
            updatedContact.Phone = accountIdToPhone.get(updatedContact.AccountId).phone;
        }
    }
}
Can someone please explain how the Map intialization is working ? updated my doubts/question as bold text in the code.

 
trigger AccountTrigger on Account (before insert) {
    // Create a map to store Account records by their Industry
     //Below Map is intialized but still Empty

    Map<String, List<Account>> industryAccountMap = new Map<String, List<Account>>();
    
    // Iterate through the new Account records
    for (Account acc : Trigger.new) {
        if (acc.Industry != null) {
            // Check if the Industry is already a key in the map

   //How below lone is checking the map 
//(which was initialised above and looks empty)

            if (industryAccountMap.containsKey(acc.Industry)) {
                // If the key exists, add the current Account to the corresponding list
                industryAccountMap.get(acc.Industry).add(acc);
            } else {
                // If the key doesn't exist, create a new list with the Account and put it in the map
                List<Account> accountList = new List<Account>{acc};
                industryAccountMap.put(acc.Industry, accountList);
            }
        }
    }
    
    // Now you can access the grouped Account records based on their Industry using the map
    for (String industry : industryAccountMap.keySet()) {
        List<Account> accountsInIndustry = industryAccountMap.get(industry);
        
        // Perform actions on the grouped Account records
        for (Account acc : accountsInIndustry) {
            // Modify or access individual Account records within the industry
            acc.Description = 'Updated description for ' + acc.Name;
        }
    }
}

 
Can someone please explain how the Map intialization is working ? updated my doubts/question as bold text in the code.

 
trigger AccountTrigger on Account (before insert) {
    // Create a map to store Account records by their Industry
     //Below Map is intialized but still Empty

    Map<String, List<Account>> industryAccountMap = new Map<String, List<Account>>();
    
    // Iterate through the new Account records
    for (Account acc : Trigger.new) {
        if (acc.Industry != null) {
            // Check if the Industry is already a key in the map

   //How below lone is checking the map 
//(which was initialised above and looks empty)

            if (industryAccountMap.containsKey(acc.Industry)) {
                // If the key exists, add the current Account to the corresponding list
                industryAccountMap.get(acc.Industry).add(acc);
            } else {
                // If the key doesn't exist, create a new list with the Account and put it in the map
                List<Account> accountList = new List<Account>{acc};
                industryAccountMap.put(acc.Industry, accountList);
            }
        }
    }
    
    // Now you can access the grouped Account records based on their Industry using the map
    for (String industry : industryAccountMap.keySet()) {
        List<Account> accountsInIndustry = industryAccountMap.get(industry);
        
        // Perform actions on the grouped Account records
        for (Account acc : accountsInIndustry) {
            // Modify or access individual Account records within the industry
            acc.Description = 'Updated description for ' + acc.Name;
        }
    }
}