• Yogesh Dighe.
  • NEWBIE
  • 40 Points
  • Member since 2015


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 16
    Replies
Apex class as following-

public class VerifyDate {
//method to handle potential checks against two dates
public static Date CheckDates(Date date1, Date date2) {
//if date2 is within the next 30 days of date1, use date2. Otherwise use the end of the month
if(DateWithin30Days(date1,date2)) {
return date2;
} else {
return SetEndOfMonthDate(date1);
}
}
//method to check if date2 is within the next 30 days of date1
private static Boolean DateWithin30Days(Date date1, Date date2) {
Date date30Days = date1.addDays(30); //create a date 30 days away from date1
if( date2 > date30Days ) { return false; }
else { return true; }
}
 
//method to return the end of the month of a given date
private static Date SetEndOfMonthDate(Date date1) {
Integer totalDays = Date.daysInMonth(date1.year(), date1.month());
Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays);
return lastDay;
}
}

-------------------------------------------------
@Test class as following-

@isTest
public class TestVerifyDate
{
     @isTest static void testWarmTemp()
     {
          Date dte = VerifyDate.CheckDates(1,10);
          System.assertEquals(10,dte);
     }
}

--------------------------

test code show me the following error-
[Error] Error: Compile Error: Method does not exist or incorrect signature: VerifyDate.CheckDates(Integer, Integer) at line 6 column 21
My Trigger is as following:-

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 my Test class as follows:-
@isTest
private class TestRestrictContactByName
{
    @isTest static void TestContact()
    {

        Contact con=new Contact(FirstName='Arjun', LastName='Mahi');
        if(con.LastName=='INVALIDNAME')
        {
             con.AddError('The Last Name "'+con.LastName+'" is not allowed for DML');
            
        }else{insert con;}  
 
        Contact conn=new Contact(FirstName='Arjun', LastName='Kapur');
         if(conn.LastName=='INVALIDNAME')
        {
             conn.AddError('The Last Name "'+conn.LastName+'" is not allowed for DML');
            
        }else {update conn;}  
       
        Contact com=new Contact(FirstName='Rama', LastName='INVALIDNAME');
        
        if(com.LastName=='INVALIDNAME')
        {
             com.AddError('The Last Name "'+com.LastName+'" is not allowed for DML');
            
        }else {insert conn;}
    }
}


plz help me complete this Challenge :)
Thanx in Advance :)
 
public class ContactSearch
{
    public static List<Contact> searchForContacts(String s1, String s2)
    {
        String lnam = s1;
        String mpc =s2;
        Contact[] conlist = [SELECT ID, Name FROM Contact WHERE (LastName=:lnam AND MailingPostalCode=:mpc)];
        List<Contact> conts = new List<Contact>();
        conts = conlist;
        return conts;
    }
}


Above code cant gives me any error in my developer console, so why i cant completing the my Trailhead challenge succefully.??
it gives me following error.
"Challenge not yet complete... here's what's wrong:
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Error....: [] "

 
Is there is any problem in my simple apex code? I cant see DEBUG output on my developer console!
====================================================
public class StrTest
{
    public void generateStringArray(Integer length)
    {
        List<String> myArray = new List<String>();
        for(Integer i=0;i<length;i++)
        {
            myArray.add('Test ' + i);
        }
        System.debug('****' + myArray);
    }      
}

====================================================
developer console>debug>open execute anonymous window>execute.
when i execute code, still i cant see DEBUG output :(

StrTest ob=new StrTest();
ob.generateStringArray(5);

====================================================
plz help me,
THANX in Advance :)
 
public class StringArrayTest
{
    public void generateStringArray()
    {
        String[] colors = new List<String>{'red','green','blue'};
        for(Integer i=0;i<colors.size();i++)
         {
             // Write value to the debug log
              System.debug(colors[i]+i);
         }
    }
}


M just fresher in SFDC...
How can i run above code.??
Thanx in Advance :)
Apex class as following-

public class VerifyDate {
//method to handle potential checks against two dates
public static Date CheckDates(Date date1, Date date2) {
//if date2 is within the next 30 days of date1, use date2. Otherwise use the end of the month
if(DateWithin30Days(date1,date2)) {
return date2;
} else {
return SetEndOfMonthDate(date1);
}
}
//method to check if date2 is within the next 30 days of date1
private static Boolean DateWithin30Days(Date date1, Date date2) {
Date date30Days = date1.addDays(30); //create a date 30 days away from date1
if( date2 > date30Days ) { return false; }
else { return true; }
}
 
//method to return the end of the month of a given date
private static Date SetEndOfMonthDate(Date date1) {
Integer totalDays = Date.daysInMonth(date1.year(), date1.month());
Date lastDay = Date.newInstance(date1.year(), date1.month(), totalDays);
return lastDay;
}
}

-------------------------------------------------
@Test class as following-

@isTest
public class TestVerifyDate
{
     @isTest static void testWarmTemp()
     {
          Date dte = VerifyDate.CheckDates(1,10);
          System.assertEquals(10,dte);
     }
}

--------------------------

test code show me the following error-
[Error] Error: Compile Error: Method does not exist or incorrect signature: VerifyDate.CheckDates(Integer, Integer) at line 6 column 21
My Trigger is as following:-

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 my Test class as follows:-
@isTest
private class TestRestrictContactByName
{
    @isTest static void TestContact()
    {

        Contact con=new Contact(FirstName='Arjun', LastName='Mahi');
        if(con.LastName=='INVALIDNAME')
        {
             con.AddError('The Last Name "'+con.LastName+'" is not allowed for DML');
            
        }else{insert con;}  
 
        Contact conn=new Contact(FirstName='Arjun', LastName='Kapur');
         if(conn.LastName=='INVALIDNAME')
        {
             conn.AddError('The Last Name "'+conn.LastName+'" is not allowed for DML');
            
        }else {update conn;}  
       
        Contact com=new Contact(FirstName='Rama', LastName='INVALIDNAME');
        
        if(com.LastName=='INVALIDNAME')
        {
             com.AddError('The Last Name "'+com.LastName+'" is not allowed for DML');
            
        }else {insert conn;}
    }
}


plz help me complete this Challenge :)
Thanx in Advance :)
 
public class ContactSearch
{
    public static List<Contact> searchForContacts(String s1, String s2)
    {
        String lnam = s1;
        String mpc =s2;
        Contact[] conlist = [SELECT ID, Name FROM Contact WHERE (LastName=:lnam AND MailingPostalCode=:mpc)];
        List<Contact> conts = new List<Contact>();
        conts = conlist;
        return conts;
    }
}


Above code cant gives me any error in my developer console, so why i cant completing the my Trailhead challenge succefully.??
it gives me following error.
"Challenge not yet complete... here's what's wrong:
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Error....: [] "

 
Is there is any problem in my simple apex code? I cant see DEBUG output on my developer console!
====================================================
public class StrTest
{
    public void generateStringArray(Integer length)
    {
        List<String> myArray = new List<String>();
        for(Integer i=0;i<length;i++)
        {
            myArray.add('Test ' + i);
        }
        System.debug('****' + myArray);
    }      
}

====================================================
developer console>debug>open execute anonymous window>execute.
when i execute code, still i cant see DEBUG output :(

StrTest ob=new StrTest();
ob.generateStringArray(5);

====================================================
plz help me,
THANX in Advance :)
 
I am trying to use javascript to display an alert is certain conmditions are met. I am not a javascript programmer.

My code is as follows:

if ("{!Contact.Banned_Warning_Explanation__c}" == "")
{
 alert ("{!Contact.FirstName}" + " " + "{!Contact.LastName}" + " is free to use the center.");
}
else
{
alert ("{!JSENCODE(Contact.Banned_Warning_Explanation__c)}");
};

The first part of this works, if the field is empty the correct message displays. The second part of the clause returns an unterminated literal error. I understand this relates to unhandled line termination characters for example. If the second alert is the only code used it works properly and will display the field even if it is multiline. When I included in the If..else structure is when this error started.
public class StringArrayTest
{
    public void generateStringArray()
    {
        String[] colors = new List<String>{'red','green','blue'};
        for(Integer i=0;i<colors.size();i++)
         {
             // Write value to the debug log
              System.debug(colors[i]+i);
         }
    }
}


M just fresher in SFDC...
How can i run above code.??
Thanx in Advance :)