• Nitish Kulkarni
  • NEWBIE
  • 45 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 11
    Replies
A developer is asked to write negative tests as part of unit testng for a method that calculates a
person’s age based on birth date.
What should the negatve tests include?

a. Throwing a custom exception in the uniit test
b. Assert that a null value is accepted by method
c. Assert that past dates are accepted by method
d. Assert that future dates are rejected by the method

I have confusion between A and D someone please explain
 
public class SampleController
{
public string myString{get{
if(myString == null)
{
return 'a';
}
return myString;
}Private set;}
public String getmyString()
{
return 'getmyString';
}
public string getMyStringMethod()
{
if(myString == null)
{
myString = 'b';
}
return myString;
}
}
Visualforce Code
<apex:page controller="SampleController">
{!MyStringMethod}, {!myString}, {!myString}
</apex:page>
what is the output and please explain it . ? 
 

Can anyone please answer this question and explain


Q. A lead object has a custom feld Priorr_mailrrc. The following trigger is intended to copy
current email into the Priorr_mailrrc feld anytme the email feld is changed


trigger test on Lead (before update) {
for (Lead ld: trigger.new) {
if (ld._mail ! = trigger.oldMap.get(ld.id)._mail) {
ld.Priorr_mailrrc = trigger.oldMap.get(ld.id)._mail;
update ld;
}
}
}

Which type of excepton will this trigger cause?
a. A compile tme excepton
b. A null reference excepton
c. A DML exception
d. A Limit _excepton when doing a bulk update

// Create a list of contacts
List<Contact> conList = new List<Contact> {
        new Contact(FirstName='Joe',LastName='Smith',Department='Finance'),
        new Contact(FirstName='Kathy',LastName='Smith',Department='Technology'),
        new Contact(FirstName='Caroline',LastName='Roth',Department='Finance'),
        new Contact()};
            
// Bulk insert all contacts with one DML call
Database.SaveResult[] srList = Database.insert(conList, false);
// Iterate through each returned result
for (Database.SaveResult sr : srList) {
    if (sr.isSuccess()) {
        // Operation was successful, so get the ID of the record that was processed
        System.debug('Successfully inserted contact. Contact ID: ' + sr.getId());
    } else {
        // Operation failed, so get all errors
        for(Database.Error err : sr.getErrors()) {
            System.debug('The following error has occurred.');
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Contact fields that affected this error: ' + err.getFields());
	 }
    }
}
I am getting invalid constructor syntax error in anonymous apex. this code is from trailhead in which database method is used.
 
Unknown property 'select_rec_condition_class.pos1' error in VF page
 
<!-- Select record on conditions class -->

<apex:page showHeader="false" controller="select_rec_condition_class">
 <apex:form>
  <apex:pageBlock>
   <center>
   <apex:commandButton value="LowSalary" action="{!LessSalary}"/>&nbsp;&nbsp;
   <apex:commandButton value="HighSalary" action="{!MoreSalary}"/>
   </center>
      <font color="red" size="4"><br/>
   Position records whose minpay is less than or equal to 2000
  </font><br/>
  <apex:pageBlockTable value="{!pos1}" var="ps1">
    <apex:column value="{!ps1.Name}"/>
    <apex:column value="{!ps1.Location__c}"/>
    <apex:column value="{!ps1.Min_Pay__c}"/>
    <apex:column value="{!ps1.Max_Pay__c}"/>
    <apex:column value="{!ps1.Open_Date__c}"/>
    <apex:column value="{!ps1.Cloe_Date__c}"/>
    <apex:column value="{!ps1.Status__c}"/>
  </apex:pageBlockTable>
      <br/><br/>
   <font color="blue" size="4">
   Position records whose minpay is greater than 2000
  </font><br/>
  <apex:pageBlockTable value="{!pos2}" var="ps2">
    <apex:column value="{!ps2.Name}"/>
    <apex:column value="{!ps2.Location__c}"/>
    <apex:column value="{!ps2.Min_Pay__c}"/>
    <apex:column value="{!ps2.Max_Pay__c}"/>
    <apex:column value="{!ps2.Open_Date__c}"/>
    <apex:column value="{!ps2.Cloe_Date__c}"/>
    <apex:column value="{!ps2.Status__c}"/>
  </apex:pageBlockTable>
  </apex:pageBlock>
 </apex:form>
</apex:page>

Controller
 
//Select record on conditions class

public class select_rec_condition_class 
{
    List<Position__c> pos1{get;set;}
    public void LessSalary()
    {
     pos1 = [select Name,Location__c,Min_Pay__c,Max_Pay__c,Open_Date__c,Close_Date__c,
              Status__c from Position__c where Min_Pay__c <= 2000];
    }
    List<Position__c> pos2{get;set;}
    public void MoreSalary()
    {
     pos2 = [select Name,Location__c,Min_Pay__c,Max_Pay__c,Open_Date__c,Close_Date__c,
              Status__c from Position__c where Min_Pay__c > 2000];   
    }
}

I am getting unknown property error while using custom controller.I am using Developer console.please help

VisualForce code
<apex:page showHeader="false" controller="insertewsclass">
<style>
td{font-size:20px;color:blue}
.st{font-size:25px;color:red}
</style>
<apex:form >
<apex:image value="{!resource.logo}" width="220" height="100"/>
<apex:pageBlock tabStyle="Employment_Website__c">
<apex:outputText value="{!msg}" style="st"/><br/><br/>
<table boder="0" width="70%" height="70">
<tr>
<td>EWS Name</td>
<td><apex:inputText value="{!name}"/></td>
</tr>
<tr>
<td>Price per post</td>
<td><apex:inputText value="{!pp}"/></td>
</tr>
<tr>
<td>Maximum budget</td>
<td><apex:inputText value="{!mb}"/></td>
</tr>
<tr>
<td>URL</td>
<td><apex:inputText value="{!url}"/></td>
</tr>
<tr>
<td></td>
<td><apex:commandButton value="Insert" action="insert_rec" style="font-size:15px"/>
    &nbsp;<input type="reset" style="font-size:15px"/></td>
</tr>
</table>
</apex:pageBlock>
</apex:form>
</apex:page>

Apex code
public class insertewsclass {
    public string name{get;set;}
    public double pp{get;set;}
    public double mb{get;set;}
    public string url{get;set;}
    public string msg;
    
    public void insert_rec()
    {
        integer namecount = [select count() from Employment_Website__c where Name = :name];
        integer urlcount = [select count() from Employment_Website__c where Website_address__c = :url];
    if(namecount > 0 || urlcount > 0)
    {
      msg = 'Record Insertion Failed';
    }
    else
    {
        Employment_Website__c ob = new Employment_Website__c();
        ob.Name = name;
        ob.Price_per_post__c = pp;
        ob.Maximum_budget__c = mb;
        ob.Website_address__c = url;
        msg = 'Record Inserted Successfully';
    }
    }
    public string getmsg()
    {
        return(msg);
    }
}

 
A developer is asked to write negative tests as part of unit testng for a method that calculates a
person’s age based on birth date.
What should the negatve tests include?

a. Throwing a custom exception in the uniit test
b. Assert that a null value is accepted by method
c. Assert that past dates are accepted by method
d. Assert that future dates are rejected by the method

I have confusion between A and D someone please explain
 
public class SampleController
{
public string myString{get{
if(myString == null)
{
return 'a';
}
return myString;
}Private set;}
public String getmyString()
{
return 'getmyString';
}
public string getMyStringMethod()
{
if(myString == null)
{
myString = 'b';
}
return myString;
}
}
Visualforce Code
<apex:page controller="SampleController">
{!MyStringMethod}, {!myString}, {!myString}
</apex:page>
what is the output and please explain it . ? 
 
// Create a list of contacts
List<Contact> conList = new List<Contact> {
        new Contact(FirstName='Joe',LastName='Smith',Department='Finance'),
        new Contact(FirstName='Kathy',LastName='Smith',Department='Technology'),
        new Contact(FirstName='Caroline',LastName='Roth',Department='Finance'),
        new Contact()};
            
// Bulk insert all contacts with one DML call
Database.SaveResult[] srList = Database.insert(conList, false);
// Iterate through each returned result
for (Database.SaveResult sr : srList) {
    if (sr.isSuccess()) {
        // Operation was successful, so get the ID of the record that was processed
        System.debug('Successfully inserted contact. Contact ID: ' + sr.getId());
    } else {
        // Operation failed, so get all errors
        for(Database.Error err : sr.getErrors()) {
            System.debug('The following error has occurred.');
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Contact fields that affected this error: ' + err.getFields());
	 }
    }
}
I am getting invalid constructor syntax error in anonymous apex. this code is from trailhead in which database method is used.
 
Unknown property 'select_rec_condition_class.pos1' error in VF page
 
<!-- Select record on conditions class -->

<apex:page showHeader="false" controller="select_rec_condition_class">
 <apex:form>
  <apex:pageBlock>
   <center>
   <apex:commandButton value="LowSalary" action="{!LessSalary}"/>&nbsp;&nbsp;
   <apex:commandButton value="HighSalary" action="{!MoreSalary}"/>
   </center>
      <font color="red" size="4"><br/>
   Position records whose minpay is less than or equal to 2000
  </font><br/>
  <apex:pageBlockTable value="{!pos1}" var="ps1">
    <apex:column value="{!ps1.Name}"/>
    <apex:column value="{!ps1.Location__c}"/>
    <apex:column value="{!ps1.Min_Pay__c}"/>
    <apex:column value="{!ps1.Max_Pay__c}"/>
    <apex:column value="{!ps1.Open_Date__c}"/>
    <apex:column value="{!ps1.Cloe_Date__c}"/>
    <apex:column value="{!ps1.Status__c}"/>
  </apex:pageBlockTable>
      <br/><br/>
   <font color="blue" size="4">
   Position records whose minpay is greater than 2000
  </font><br/>
  <apex:pageBlockTable value="{!pos2}" var="ps2">
    <apex:column value="{!ps2.Name}"/>
    <apex:column value="{!ps2.Location__c}"/>
    <apex:column value="{!ps2.Min_Pay__c}"/>
    <apex:column value="{!ps2.Max_Pay__c}"/>
    <apex:column value="{!ps2.Open_Date__c}"/>
    <apex:column value="{!ps2.Cloe_Date__c}"/>
    <apex:column value="{!ps2.Status__c}"/>
  </apex:pageBlockTable>
  </apex:pageBlock>
 </apex:form>
</apex:page>

Controller
 
//Select record on conditions class

public class select_rec_condition_class 
{
    List<Position__c> pos1{get;set;}
    public void LessSalary()
    {
     pos1 = [select Name,Location__c,Min_Pay__c,Max_Pay__c,Open_Date__c,Close_Date__c,
              Status__c from Position__c where Min_Pay__c <= 2000];
    }
    List<Position__c> pos2{get;set;}
    public void MoreSalary()
    {
     pos2 = [select Name,Location__c,Min_Pay__c,Max_Pay__c,Open_Date__c,Close_Date__c,
              Status__c from Position__c where Min_Pay__c > 2000];   
    }
}

I am getting unknown property error while using custom controller.I am using Developer console.please help

VisualForce code
<apex:page showHeader="false" controller="insertewsclass">
<style>
td{font-size:20px;color:blue}
.st{font-size:25px;color:red}
</style>
<apex:form >
<apex:image value="{!resource.logo}" width="220" height="100"/>
<apex:pageBlock tabStyle="Employment_Website__c">
<apex:outputText value="{!msg}" style="st"/><br/><br/>
<table boder="0" width="70%" height="70">
<tr>
<td>EWS Name</td>
<td><apex:inputText value="{!name}"/></td>
</tr>
<tr>
<td>Price per post</td>
<td><apex:inputText value="{!pp}"/></td>
</tr>
<tr>
<td>Maximum budget</td>
<td><apex:inputText value="{!mb}"/></td>
</tr>
<tr>
<td>URL</td>
<td><apex:inputText value="{!url}"/></td>
</tr>
<tr>
<td></td>
<td><apex:commandButton value="Insert" action="insert_rec" style="font-size:15px"/>
    &nbsp;<input type="reset" style="font-size:15px"/></td>
</tr>
</table>
</apex:pageBlock>
</apex:form>
</apex:page>

Apex code
public class insertewsclass {
    public string name{get;set;}
    public double pp{get;set;}
    public double mb{get;set;}
    public string url{get;set;}
    public string msg;
    
    public void insert_rec()
    {
        integer namecount = [select count() from Employment_Website__c where Name = :name];
        integer urlcount = [select count() from Employment_Website__c where Website_address__c = :url];
    if(namecount > 0 || urlcount > 0)
    {
      msg = 'Record Insertion Failed';
    }
    else
    {
        Employment_Website__c ob = new Employment_Website__c();
        ob.Name = name;
        ob.Price_per_post__c = pp;
        ob.Maximum_budget__c = mb;
        ob.Website_address__c = url;
        msg = 'Record Inserted Successfully';
    }
    }
    public string getmsg()
    {
        return(msg);
    }
}

 
Hi,
 I have a checkbox field called Pin_Status___c, and I want to use this field in output field, but it's not enabled when using it the output field.
          <apex:pageBlockSectionItem >
              <apex:outputLabel value="PIN" id="test">
                <!--<apex:panelGrid columns="2">-->
<apex:outputPanel>
                <!--<apex:inputField value="{!Account.PIN__c}" styleClass="omni" style="width: 55px;"/>-->
                <apex:outputField value="{!Account.PIN_Status__c}" styleClass="omni" id="test" />
                  </apex:outputPanel></apex:outputLabel>
               <!-- </apex:panelGrid>-->
          </apex:pageBlockSectionItem>