• Mr. Progess
  • NEWBIE
  • 0 Points
  • Member since 2013

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

Hello All,

 

I was given three seperate assignments that i need to code in APEX. I am still learning how to code effectively and efficiently, but  I need some help.

 

Write a function in the programming language of your choice to solve the following problems. Each function should be an accompanied by a unit test.  

i.              Given an array of integers between 1 and 1,000,000. One integer is in the array twice. Find the duplicate.

ii.             Find the first non-repeating character in a string:("DEFD" -> E )

iii.             A standard deck of 52 cards is represented in an array. Each card is represented as an integer. Write a method to shuffle the cards.

 

i did some online research and might have possibly found a solution for the 1st one but i dont know how to set the array of integers between 1 and 1,000,000. Here is some sample code below that i found from a fellow developer. 

 

 

Set<sobject> myset = new Set<sobject>();

List<sobject> result = new List<sobject>();

for (sobject s : originalList) {

  if (myset.add(s)) {

    result.add(s);

  }

}

 

I figure this is probably easy to do but again how do i set the array or am i even on the right track?

 

 

The second one i figure i would need an APEX controller? But i am still a little unclear on how to find the first non repeating character? string:("DEFD" -> E )

 

The third one I am just real unclear on what to do. Any help would be greatly appreciated.

 

thanks,

Hello. I recently had help with this trigger but now another requirement has been added. I need this trigger to only fire when the account name field is null(blank). Can someone help with this. I am still new to learning how to program in Apex:

 

 

trigger AccountAssignment on Contact (after insert, after update) {
     
        List<Contact> conToInsert = [select id,accountid from contact where id in: trigger.newmap.keyset()];

 
        Account defaultAccount = [SELECT ID FROM account Where ID  = '001Z000000Ptgws' limit 1];  
      
          for (Contact c : conToInsert) {             
                       
            if( c.accountid == '001Z000000Ptgws')
              {         
              
                c.accountid = defaultAccount.id;     
                  
               conToInsert.add(c);            
             
               }            
        }
     
        try {
               update conToInsert; 
        } catch (system.Dmlexception e) {
              system.debug (e);
        }
}

Hi,

I am trying to build an apex trigger that populates the Account field to say "dummy" or what ever value i want when a new contact record is created. I am getting this error:

Error: Compile Error: Invalid field Contact for SObject Contact at line 17 column 16  


I am not sure if am doing this trigger correctly and I  was also told that I need to get the ID of the the account to assign to either a new or old list. I.E(a.Account or c.Account). So i am also stuck there which may be the reason for my error above. Can someone help on this. Here is the logic below on what i have so far. I also was wondering if i could set up a custom setting("SFDC name for an application constant) and add a data set that includes the ID so that the ID can be Managed with configuration. This was what someone suggested to me which i have no idea on how to do?


trigger AccountAssignment on Contact (after insert) {
       
        List<Contact> conToInsert = new List<Contact> ();       
       
          for (Contact c : Trigger.new) {              
                        
            if (c.Account = 'Dummy') { 
              
               Account a = new Account (); 
              
               a.Account = c.Account;               
               
               //Account = 'Dummy';            
                   
               conToInsert.add(c);              
              
               }              
        }
       
        try {
               insert conToInsert;   
        } catch (system.Dmlexception e) {
              system.debug (e);
        }     
}

I successfully completed the Salesforce Certified Platform Developer II - Multiple Choice (WI21) but didn't receive a certification logo and the certificate doesn't appear in the trailhead profile. Could anyone please give me a piece of advice?

Hello All,

 

I was given three seperate assignments that i need to code in APEX. I am still learning how to code effectively and efficiently, but  I need some help.

 

Write a function in the programming language of your choice to solve the following problems. Each function should be an accompanied by a unit test.  

i.              Given an array of integers between 1 and 1,000,000. One integer is in the array twice. Find the duplicate.

ii.             Find the first non-repeating character in a string:("DEFD" -> E )

iii.             A standard deck of 52 cards is represented in an array. Each card is represented as an integer. Write a method to shuffle the cards.

 

i did some online research and might have possibly found a solution for the 1st one but i dont know how to set the array of integers between 1 and 1,000,000. Here is some sample code below that i found from a fellow developer. 

 

 

Set<sobject> myset = new Set<sobject>();

List<sobject> result = new List<sobject>();

for (sobject s : originalList) {

  if (myset.add(s)) {

    result.add(s);

  }

}

 

I figure this is probably easy to do but again how do i set the array or am i even on the right track?

 

 

The second one i figure i would need an APEX controller? But i am still a little unclear on how to find the first non repeating character? string:("DEFD" -> E )

 

The third one I am just real unclear on what to do. Any help would be greatly appreciated.

 

thanks,

Hello. I recently had help with this trigger but now another requirement has been added. I need this trigger to only fire when the account name field is null(blank). Can someone help with this. I am still new to learning how to program in Apex:

 

 

trigger AccountAssignment on Contact (after insert, after update) {
     
        List<Contact> conToInsert = [select id,accountid from contact where id in: trigger.newmap.keyset()];

 
        Account defaultAccount = [SELECT ID FROM account Where ID  = '001Z000000Ptgws' limit 1];  
      
          for (Contact c : conToInsert) {             
                       
            if( c.accountid == '001Z000000Ptgws')
              {         
              
                c.accountid = defaultAccount.id;     
                  
               conToInsert.add(c);            
             
               }            
        }
     
        try {
               update conToInsert; 
        } catch (system.Dmlexception e) {
              system.debug (e);
        }
}

Hi,

I am trying to build an apex trigger that populates the Account field to say "dummy" or what ever value i want when a new contact record is created. I am getting this error:

Error: Compile Error: Invalid field Contact for SObject Contact at line 17 column 16  


I am not sure if am doing this trigger correctly and I  was also told that I need to get the ID of the the account to assign to either a new or old list. I.E(a.Account or c.Account). So i am also stuck there which may be the reason for my error above. Can someone help on this. Here is the logic below on what i have so far. I also was wondering if i could set up a custom setting("SFDC name for an application constant) and add a data set that includes the ID so that the ID can be Managed with configuration. This was what someone suggested to me which i have no idea on how to do?


trigger AccountAssignment on Contact (after insert) {
       
        List<Contact> conToInsert = new List<Contact> ();       
       
          for (Contact c : Trigger.new) {              
                        
            if (c.Account = 'Dummy') { 
              
               Account a = new Account (); 
              
               a.Account = c.Account;               
               
               //Account = 'Dummy';            
                   
               conToInsert.add(c);              
              
               }              
        }
       
        try {
               insert conToInsert;   
        } catch (system.Dmlexception e) {
              system.debug (e);
        }     
}