• Lantin Mary
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
The challenge is to search for the inserted record with an inline SOSL search, using Execute Anonymous.

This is what I did using Execute Anonymous Window
 
List<List<sObject>> searchList = [FIND 'Mission Control' IN ALL FIELDS 
                                  RETURNING Contact(FirstName, LastName,
                                  Phone, Email, Description)];
Contact[] searchContacts = (Contact[])searchList[0];
System.debug('Found the following contacts:');
for (Contact c : searchContacts) {
   System.debug('"'+c.LastName + ', ' + c.FirstName+'"');
}

But still there's an error when I check the challenge.

Challenge Not yet complete... here's what's wrong: 
Could not find the contact's name in the debug log. Be sure to run a query for your record, and to write your contact's name to the debug log using the System.debug() method.
I am working on a dynamic table, where i can add and delete rows using a command button. But when i delete a specific row, the values on the look up fields are cleared or assigned to a different row. Below are the code snippets. Thanks.
User-added image
<apex:variable value="{!0}" var="rowNum"/> 
            <apex:pageBlockSection columns="1" title="Adding Multiple Expense" collapsible="False">
            <apex:commandButton value="Add New" action="{!addNewRow}" rerender="ExpenseHead" immediate="true" />       
                <apex:pageBlockTable value="{!ExpenseList}" var="expItem"> 
                    <apex:column headerValue="User"> 
                        <apex:inputField value="{!expItem.User__c}" />
                    </apex:column>            
                    <apex:column headerValue="Category">                    
                       <apex:inputfield value="{!expItem.Category__c}"/>
                    </apex:column>
                    <apex:column headerValue="Amount">
                         <apex:inputField id="AmountId" value="{!expItem.Amount__c}"/>
                    </apex:column>
                    <apex:column headerValue="Use Day">
                        <apex:inputField value="{!expItem.Use_Day__c}"/>
                    </apex:column>
                    <apex:column headerValue="Status">
                        <apex:inputfield styleClass="RemoveNone" value="{!expItem.Status__c}"/>
                    </apex:column>
                    <apex:column headerValue="Done">
                        <apex:inputfield value="{!expItem.Done__c}"/>
                    </apex:column>
                    <apex:column headerValue="Project">
                        <apex:inputField value="{!expItem.Project__c}"/>
                    </apex:column>
                    <apex:column >
                         <apex:commandLink value="Delete" action="{!Deleterow}" rerender="ExpenseHead" immediate="true" > 
                             <apex:param value="{!rowNum}" name="rowToRemove" assignTo="{!rowToRemove}"/>
                         </apex:commandLink>
                         <apex:variable var="rowNum" value="{!rowNum + 1}"/>
                    </apex:column>            
                </apex:pageBlockTable>
            </apex:pageblockSection>
 
public class MultipleExpensesController{

    public Expense__c expense{get;set;}
    public Integer rowToRemove {get;set;}
    public List<Expense__c> ExpenseList{get;set;}
      
    public Expense__c setExpense(Expense__c ex){
        this.expense = ex;
        return expense;
    }
    
     public MultipleExpensesController(ApexPages.StandardController controller){
       expense = new Expense__c();
       ExpenseList = new List<Expense__c>();
       ExpenseList.add(expense);
    }

    public void deleteRow(){
      ExpenseList.remove(rowToRemove );
      system.debug(' index '+ rowToRemove );
    }
    
    public void addNewRow(){
       expense = new Expense__c();
       ExpenseList.add(expense);
    }
       
}

 
The challenge is to search for the inserted record with an inline SOSL search, using Execute Anonymous.

This is what I did using Execute Anonymous Window
 
List<List<sObject>> searchList = [FIND 'Mission Control' IN ALL FIELDS 
                                  RETURNING Contact(FirstName, LastName,
                                  Phone, Email, Description)];
Contact[] searchContacts = (Contact[])searchList[0];
System.debug('Found the following contacts:');
for (Contact c : searchContacts) {
   System.debug('"'+c.LastName + ', ' + c.FirstName+'"');
}

But still there's an error when I check the challenge.

Challenge Not yet complete... here's what's wrong: 
Could not find the contact's name in the debug log. Be sure to run a query for your record, and to write your contact's name to the debug log using the System.debug() method.
The challenge is to search for the inserted record with an inline SOSL search, using Execute Anonymous.

This is what I did using Execute Anonymous Window
 
List<List<sObject>> searchList = [FIND 'Mission Control' IN ALL FIELDS 
                                  RETURNING Contact(FirstName, LastName,
                                  Phone, Email, Description)];
Contact[] searchContacts = (Contact[])searchList[0];
System.debug('Found the following contacts:');
for (Contact c : searchContacts) {
   System.debug('"'+c.LastName + ', ' + c.FirstName+'"');
}

But still there's an error when I check the challenge.

Challenge Not yet complete... here's what's wrong: 
Could not find the contact's name in the debug log. Be sure to run a query for your record, and to write your contact's name to the debug log using the System.debug() method.
I am working on a dynamic table, where i can add and delete rows using a command button. But when i delete a specific row, the values on the look up fields are cleared or assigned to a different row. Below are the code snippets. Thanks.
User-added image
<apex:variable value="{!0}" var="rowNum"/> 
            <apex:pageBlockSection columns="1" title="Adding Multiple Expense" collapsible="False">
            <apex:commandButton value="Add New" action="{!addNewRow}" rerender="ExpenseHead" immediate="true" />       
                <apex:pageBlockTable value="{!ExpenseList}" var="expItem"> 
                    <apex:column headerValue="User"> 
                        <apex:inputField value="{!expItem.User__c}" />
                    </apex:column>            
                    <apex:column headerValue="Category">                    
                       <apex:inputfield value="{!expItem.Category__c}"/>
                    </apex:column>
                    <apex:column headerValue="Amount">
                         <apex:inputField id="AmountId" value="{!expItem.Amount__c}"/>
                    </apex:column>
                    <apex:column headerValue="Use Day">
                        <apex:inputField value="{!expItem.Use_Day__c}"/>
                    </apex:column>
                    <apex:column headerValue="Status">
                        <apex:inputfield styleClass="RemoveNone" value="{!expItem.Status__c}"/>
                    </apex:column>
                    <apex:column headerValue="Done">
                        <apex:inputfield value="{!expItem.Done__c}"/>
                    </apex:column>
                    <apex:column headerValue="Project">
                        <apex:inputField value="{!expItem.Project__c}"/>
                    </apex:column>
                    <apex:column >
                         <apex:commandLink value="Delete" action="{!Deleterow}" rerender="ExpenseHead" immediate="true" > 
                             <apex:param value="{!rowNum}" name="rowToRemove" assignTo="{!rowToRemove}"/>
                         </apex:commandLink>
                         <apex:variable var="rowNum" value="{!rowNum + 1}"/>
                    </apex:column>            
                </apex:pageBlockTable>
            </apex:pageblockSection>
 
public class MultipleExpensesController{

    public Expense__c expense{get;set;}
    public Integer rowToRemove {get;set;}
    public List<Expense__c> ExpenseList{get;set;}
      
    public Expense__c setExpense(Expense__c ex){
        this.expense = ex;
        return expense;
    }
    
     public MultipleExpensesController(ApexPages.StandardController controller){
       expense = new Expense__c();
       ExpenseList = new List<Expense__c>();
       ExpenseList.add(expense);
    }

    public void deleteRow(){
      ExpenseList.remove(rowToRemove );
      system.debug(' index '+ rowToRemove );
    }
    
    public void addNewRow(){
       expense = new Expense__c();
       ExpenseList.add(expense);
    }
       
}