Saturday 11 August 2018

Salesforce Basics :



Using same List for Update:

List<Account> acList=[select id,name from account limit 2];
system.debug('>>>acList>>>>'+acList);
for(account ac:acList){
    ac.name='Test';
}
system.debug('before update List>>'+acList);
update acList;

Here "acList" contains Updated value



Will It Updates.Parents name field?

List<Contact> contactList=[select id,accountId,account.name from contact limit 2];
for(contact c:contactList){
c.account.name='Update Parent Account';
}

update contactList;

Ans: It will not








Nested usage of Map and List


Map<String, Integer> TestMap = new Map<String, Integer>();
TestMap.put('Hello', 100);
TestMap.put('World', 200);
TestMap.put('Witch', 200);
TestMap.put('Salesforce', 100);
TestMap.put('sfdcinpractice.com', 100);

Map<Integer, List<String>> TestWordMap = new Map<Integer, List<String>>();
for(String curWord: TestMap.keySet())
{
    system.debug('curWord>>>>'+curWord);
    Integer curPage = TestMap.get(curWord);
    system.debug('>>curPage>>>'+curPage);
    if(!TestWordMap.containsKey(curPage))
    {
        TestWordMap.put(curPage, new List<String>()); //We need to initialise the list
    }
    system.debug('@@@@TestWordMap@@@@'+TestWordMap);
    TestWordMap.get(curPage).add(curWord); //TestWordMap.get(curPage) is a list here
    system.debug('#####TestWordMap####'+TestWordMap);
}