• Unnamalai Subramanian
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 7
    Replies
Hi,

How do we add the badges earned previously to linked in profile?

Regards,
Unna
Hi,

I am trying to update the Old Account's Opportunity description field as Opportunity Owner's email address, for all the contacts whose Account Id is updated. Here is the code I tried. When I tried hard coding description as account Id it worked. But how to get opportunity owner's email address?

trigger accountchange on Contact (after insert, after update) {
  //This queries all Accounts related to the incoming Contact records in a single SOQL query.                                      
  // List<Contact> contactwithAccounts = [select id, firstname, AccountId from Contact where Id IN :Trigger.newMap.keySet()];

  Map<Id, Opportunity> OppToUpdate = new Map<Id,Opportunity>();
  Map<Id,Contact> Mp = new Map<Id,Contact>(); // Store Account Id and contact object
    //indexed for loop
    for(integer i=0; i<trigger.new.size(); i++){
        if(trigger.new[i].AccountId != trigger.old[i].AccountId){  
            System.debug('trigger.old[i].AccountId : '+trigger.old[i].AccountId + ':' + trigger.old[i].Account);
            Mp.put(trigger.old[i].AccountId,trigger.new[i]);   // store account Id and contact object                          
      }                   
    }
    // Update Opportunity of old account with description as opty owner email id
    List<Id> OId = new List<Id>();
    for(Opportunity opp: [Select Id, Description, OwnerId from Opportunity where AccountId =:Mp.Keyset()]){
            opp.Description = '----Added through Trigger - Opty Owner Id' + opp.OwnerId + '--Contact Owner Id';
            OId.add(opp.OwnerId);     // get Opportunity owner id in OId List.       
            OppToUpdate.put(opp.Id, opp);        
    }
    
    Map<Id,User> us1 = new Map<Id,User>([SELECT Id,Email FROM User where id =: OId]); 
    // Throws compilation error as line 27:16 no viable alternative at character'' for above line.
    for (Id userId : us1.Keyset()){
        for(Opportunity op : OppToUpdate){
            if(userId == OppToUpdate.get(op).OwnerId){
                op.Description = us1.get(userId).Email;
            }
        }
    }    
    
    //Now outside the FOR Loop, perform a single Update DML statement. 
   update OppToUpdate.values();
}
Hi, 
I am trying to use dynamic search string in Apex class and while executing below code, I don't see the log window. It executes without error but no log window comes up. What am I missing?

Class:
Public Class ContactAndLeadSearch{
    Public static List<List<sObject>> searchContactsAndLeads(String searchword){
        String searchQuery = 'FIND \'' + searchword + '\' IN NAME FIELDS RETURNING Lead(Name where FirstName = \'' + searchword + '\' or LastName = \'' + searchword + '\'),Contact(FirstName,LastName where FirstName = \'' + searchword + '\' or LastName = \'' + searchword + '\')';
        List<List<sObject>> searchConLead = search.query(searchQuery);
        return searchConLead;
           }
}
In Debug Annonymous window:
List<List<sObject>> searchContactLead = ContactAndLeadSearch.searchContactsAndLeads('Smith');

List<Lead> leadList = New List<Lead>();
List<Contact> contList = New List<Contact>();

leadList = ((List<Lead>)searchContactLead[0]);
contList = ((List<Contact>)searchContactLead[1]);

for(Lead a:leadList){
System.debug('Found following Leads ' + a.Name);
}
for(Contact cts:contList){
System.debug('Found following Contacts ' + cts.FirstName + '' + cts.LastName);
}
 
Hi,
I am working on Apex Basics and tried upserting a account. below is the code and error message. How to identify the unique field to be considered? In the example Contacts>Email is used which is indexed. In Account, Name is indexed and tried it. Please help.

Code: 
try{
    Account act = new Account(Name = '3Com');
    insert act;
    
    Account act2 = new Account(Name = '3Com', 
                               Site = 'Fremont',
                                  NumberOfEmployees = 10);
    upsert act2 Account.fields.Name;
}
catch(DmlException e){
    System.debug('DML Exception found' + e.getMessage());
}
Error Message: Invalid field for upsert, must be an External Id custom or standard indexed field: Account.fields.Name
Hi,

I tried writing the sample apex class to return list of strings. Below is the code and when I check the challenge - I get the error as "Challenge not yet complete... here's what's wrong: Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.". What's wrong in the code?

public class StringArrayTest {
    public static List<String> generateStringArray(Integer len) {
 
        Integer inp = len;        
        List <String> Arrlist = new List<String>();
        for(Integer i=0; i < len; i++){
            Arrlist.add('Test: ' + i);
            system.debug(Arrlist.get(i));
          //  system.debug('len value: '  + inp);
        } 
        return Arrlist;
        
    }

}
Hi,

I am trying to update the Old Account's Opportunity description field as Opportunity Owner's email address, for all the contacts whose Account Id is updated. Here is the code I tried. When I tried hard coding description as account Id it worked. But how to get opportunity owner's email address?

trigger accountchange on Contact (after insert, after update) {
  //This queries all Accounts related to the incoming Contact records in a single SOQL query.                                      
  // List<Contact> contactwithAccounts = [select id, firstname, AccountId from Contact where Id IN :Trigger.newMap.keySet()];

  Map<Id, Opportunity> OppToUpdate = new Map<Id,Opportunity>();
  Map<Id,Contact> Mp = new Map<Id,Contact>(); // Store Account Id and contact object
    //indexed for loop
    for(integer i=0; i<trigger.new.size(); i++){
        if(trigger.new[i].AccountId != trigger.old[i].AccountId){  
            System.debug('trigger.old[i].AccountId : '+trigger.old[i].AccountId + ':' + trigger.old[i].Account);
            Mp.put(trigger.old[i].AccountId,trigger.new[i]);   // store account Id and contact object                          
      }                   
    }
    // Update Opportunity of old account with description as opty owner email id
    List<Id> OId = new List<Id>();
    for(Opportunity opp: [Select Id, Description, OwnerId from Opportunity where AccountId =:Mp.Keyset()]){
            opp.Description = '----Added through Trigger - Opty Owner Id' + opp.OwnerId + '--Contact Owner Id';
            OId.add(opp.OwnerId);     // get Opportunity owner id in OId List.       
            OppToUpdate.put(opp.Id, opp);        
    }
    
    Map<Id,User> us1 = new Map<Id,User>([SELECT Id,Email FROM User where id =: OId]); 
    // Throws compilation error as line 27:16 no viable alternative at character'' for above line.
    for (Id userId : us1.Keyset()){
        for(Opportunity op : OppToUpdate){
            if(userId == OppToUpdate.get(op).OwnerId){
                op.Description = us1.get(userId).Email;
            }
        }
    }    
    
    //Now outside the FOR Loop, perform a single Update DML statement. 
   update OppToUpdate.values();
}
Hi, 
I am trying to use dynamic search string in Apex class and while executing below code, I don't see the log window. It executes without error but no log window comes up. What am I missing?

Class:
Public Class ContactAndLeadSearch{
    Public static List<List<sObject>> searchContactsAndLeads(String searchword){
        String searchQuery = 'FIND \'' + searchword + '\' IN NAME FIELDS RETURNING Lead(Name where FirstName = \'' + searchword + '\' or LastName = \'' + searchword + '\'),Contact(FirstName,LastName where FirstName = \'' + searchword + '\' or LastName = \'' + searchword + '\')';
        List<List<sObject>> searchConLead = search.query(searchQuery);
        return searchConLead;
           }
}
In Debug Annonymous window:
List<List<sObject>> searchContactLead = ContactAndLeadSearch.searchContactsAndLeads('Smith');

List<Lead> leadList = New List<Lead>();
List<Contact> contList = New List<Contact>();

leadList = ((List<Lead>)searchContactLead[0]);
contList = ((List<Contact>)searchContactLead[1]);

for(Lead a:leadList){
System.debug('Found following Leads ' + a.Name);
}
for(Contact cts:contList){
System.debug('Found following Contacts ' + cts.FirstName + '' + cts.LastName);
}
 
Hi,
I am working on Apex Basics and tried upserting a account. below is the code and error message. How to identify the unique field to be considered? In the example Contacts>Email is used which is indexed. In Account, Name is indexed and tried it. Please help.

Code: 
try{
    Account act = new Account(Name = '3Com');
    insert act;
    
    Account act2 = new Account(Name = '3Com', 
                               Site = 'Fremont',
                                  NumberOfEmployees = 10);
    upsert act2 Account.fields.Name;
}
catch(DmlException e){
    System.debug('DML Exception found' + e.getMessage());
}
Error Message: Invalid field for upsert, must be an External Id custom or standard indexed field: Account.fields.Name
Hi,

I tried writing the sample apex class to return list of strings. Below is the code and when I check the challenge - I get the error as "Challenge not yet complete... here's what's wrong: Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.". What's wrong in the code?

public class StringArrayTest {
    public static List<String> generateStringArray(Integer len) {
 
        Integer inp = len;        
        List <String> Arrlist = new List<String>();
        for(Integer i=0; i < len; i++){
            Arrlist.add('Test: ' + i);
            system.debug(Arrlist.get(i));
          //  system.debug('len value: '  + inp);
        } 
        return Arrlist;
        
    }

}