• Andrea Ianni
  • NEWBIE
  • 153 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 9
    Replies
This is the Challenge:

To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.The Apex class must be called 'AccountHandler' and be in the public scope.
The Apex class must have a public static method called 'insertNewAccount'.
The 'insertNewAccount' method must accept an incoming string as a parameter, name the account after the parameter, insert it into the system and then return the account record.
The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.


My Class:

public class AccountHandler {

    public static Account insertNewAccount (String accName, Account a) {
         try{   
          a.name = accName;
    
         insert a;
        return a;
        }
        catch(Exception e) {
            return null;
        }
    }    
}



User-added image


Throwing this error, how many times i modified the class.
what is the correct class.?
 
I have this very simple class..  
trigger RestrictContactByName on Contact (before insert, before update) {
    //check contacts prior to insert or update for invalid data
    For (Contact c : Trigger.New) {
        if(c.LastName == 'INVALIDNAME') {   //invalidname is invalid
            c.AddError('The Last Name "'+c.LastName+'" is not allowed for DML');
        }
    }
}
.. and the corresponding Test Class:  
@isTest
private class TestRestrictContactByName {

	@isTest static void metodoTest() {
		
		List listaContatti = new List();
		Contact c1 = new Contact(FirstName='Francesco', LastName='Riggio');
		Contact c2 = new Contact(LastName = 'INVALIDNAME');
		listaContatti.add(c1);
		listaContatti.add(c2);
		
		//insert listaContatti;
		
		// Perform test
        Test.startTest();
        Database.SaveResult [] result = Database.insert(listaContatti, false);
        Test.stopTest(); 
		
		c1.LastName = 'INVALIDNAME';
		update c1;
       		
	}
	
}

When I run the Test class from the Developer Console I get 100% of coverage on the RestrictContactByName class but, when I check the challenge on the trailhead it returns the error:

Challenge not yet complete... here's what's wrong: The 'RestrictContactByName' class did not achieve 100% code coverage via your test methods

Has someone had my same issue?
trigger theNameGioele on Contact (before insert, after insert) {

    for (Contact cont: Trigger.new){
        if(cont.firstname == 'Gioele'){
            cont.Description = 'This guy has my son name!';
        }    
    }
   
}
Look at this very easy example.

Behaviour I expected: when I insert "Gioele Ianni" in SF the system change the Description of the record, before the insert. Then it overwrite the field Description with the same statement, after the insert.

Real behaviour: Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger theNameGioele caused an unexpected exception, contact your administrator: theNameGioele: execution of AfterInsert caused by: System.FinalException: Record is read-only: Trigger.theNameGioele: line 5, column 1


Obviously everything works if I remove the "after insert".



 
I have this very simple class..  
trigger RestrictContactByName on Contact (before insert, before update) {
    //check contacts prior to insert or update for invalid data
    For (Contact c : Trigger.New) {
        if(c.LastName == 'INVALIDNAME') {   //invalidname is invalid
            c.AddError('The Last Name "'+c.LastName+'" is not allowed for DML');
        }
    }
}
.. and the corresponding Test Class:  
@isTest
private class TestRestrictContactByName {

	@isTest static void metodoTest() {
		
		List listaContatti = new List();
		Contact c1 = new Contact(FirstName='Francesco', LastName='Riggio');
		Contact c2 = new Contact(LastName = 'INVALIDNAME');
		listaContatti.add(c1);
		listaContatti.add(c2);
		
		//insert listaContatti;
		
		// Perform test
        Test.startTest();
        Database.SaveResult [] result = Database.insert(listaContatti, false);
        Test.stopTest(); 
		
		c1.LastName = 'INVALIDNAME';
		update c1;
       		
	}
	
}

When I run the Test class from the Developer Console I get 100% of coverage on the RestrictContactByName class but, when I check the challenge on the trailhead it returns the error:

Challenge not yet complete... here's what's wrong: The 'RestrictContactByName' class did not achieve 100% code coverage via your test methods

Has someone had my same issue?
This is the Challenge:

To pass this challenge, create an Apex class that inserts a new account named after an incoming parameter. If the account is successfully inserted, the method should return the account record. If a DML exception occurs, the method should return null.The Apex class must be called 'AccountHandler' and be in the public scope.
The Apex class must have a public static method called 'insertNewAccount'.
The 'insertNewAccount' method must accept an incoming string as a parameter, name the account after the parameter, insert it into the system and then return the account record.
The 'insertNewAccount' method must also accept an empty string, catch the failed DML and return null.


My Class:

public class AccountHandler {

    public static Account insertNewAccount (String accName, Account a) {
         try{   
          a.name = accName;
    
         insert a;
        return a;
        }
        catch(Exception e) {
            return null;
        }
    }    
}



User-added image


Throwing this error, how many times i modified the class.
what is the correct class.?
 
Unable to complete the challenge for the Apex Trigger using Bulk
error:Executing against the trigger does not work as expected.

Trigger code:

trigger ClosedOpportunityTrigger on Opportunity (before insert,before update)
{
  List <task> taskinsert= new List<task>();
   for(Opportunity o: Trigger.new)
    {
     if(o.StageName=='Closed Won')
     {
         Task t= new Task();
         t.Subject='Follow up Task';
        t.whatid=o.id;
taskinsert.add(t);
          
     }
        

      
    }
    insert taskinsert;
    
}
This is my controller :

public class ContactsListController{

 private string sortOrder = 'LastName';
 
 public List<Contact> getContacts(){
 
  string soqlQuery = 'SELECT Id, FirstName, LastName, Title, Email'+ 'from Contacts'+ 'OrderBy' + sortOrder 
                          + 'ASC' + 'LIMIT 10' ;
  
  List<Contact> results = Database.query(soqlQuery);
  return results;
  
 }                         

}



And this is my visualforce page :

<apex:page controller="ContactsListController" >
  <apex:form >
   <apex:pageBlock title="Contacts List" id="Contacts_list">
   
    <apex:pageBlockTable value="{!Contacts}" var="ct">
    <apex:column value="{!ct.FirstName}"/>
    <apex:column value="{!ct.LastName}"/>
    <apex:column value="{!ct.Title}"/>
    <apex:column value="{!ct.Email}"/>
    
    </apex:pageBlockTable>
  
   </apex:pageBlock>
  </apex:form>
</apex:page>


I'm getting an error "System.QueryException: unexpected token: 10 " while saving the above vf page. Please help.
Hi All,

We are implement Live Agent feature and configure skill and users, and tried to integrate with our own web-portal.
By Running sample script genereated by Salesforce from Local laptop, it's working well, can see online/offline of agents, also can do Live chat with agents.

When we deploy to our own Tomcat-Apache web-server, we are able to see the online/offline button, but after i click on the Online button the chat window pops up with an error as below:

HTTP ERROR: 500

Problem accessing /content/s/prechatVisitor. Reason:

This is not a JSON Array.
Powered by Jetty://


And URL call in browser looks like below strang url: 
https://9t.la9cs.salesforceliveagent.com/content/s/prechatVisitor?endpoint=https%3A%2F%2F9t.la9cs.salesforceliveagent.com%2Fcontent%2Fs%2Fchat%3Flan......................

I already saw there are two similar discussions on the forum without answer.

Any one could give some help? Thanks!

The Sample HTML script are as below:

<html>
<head></head>
<body>

<img id="liveagent_button_online_573O0000000CaUz" style="display: none; border: 0px none; cursor: pointer" onclick="liveagent.startChat('573O0000000CaUz')" src="https://uat-libertyinsurancesg.cs5.force.com/survey/resource/1421128309000/Live_Agent_online_button" /><img id="liveagent_button_offline_573O0000000CaUz" style="display: none; border: 0px none; " src="https://uat-libertyinsurancesg.cs5.force.com/survey/resource/1421129020000/Live_Agent_offline_button" />
<script type="text/javascript">
if (!window._laq) { window._laq = []; }
window._laq.push(function(){liveagent.showWhenOnline('573O0000000CaUz', document.getElementById('liveagent_button_online_573O0000000CaUz'));
liveagent.showWhenOffline('573O0000000CaUz', document.getElementById('liveagent_button_offline_573O0000000CaUz'));
});</script>


<script type='text/javascript' src='https://c.la9cs.salesforceliveagent.com/content/g/js/32.0/deployment.js'></script>
<script type='text/javascript'>
liveagent.addCustomDetail('Company Name', 'Company ABC');
liveagent.setName('John Doe');
liveagent.init('https://d.la9cs.salesforceliveagent.com/chat', '572O0000000CaT3', '00DO00000050jEO');
</script>
</body>
</html>