• vlr
  • NEWBIE
  • 35 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 9
    Replies

I am using this code to print out Account fields to PDF file . Programm fails when it tries to retrieve "LastReferencedDate" from the instance of account object. It fails with "System.SObjectException: Invalid field LastReferencedDate". When I run simillar code in Execute Anonymous there is no LastReferencedDate field on the Map. I do not understand why when I debug apex class it tries to retrieve "LastReferencedDate" field and fails, but it does not have LastReferencedDate field when I run it in Execute Anonymous. And why Schema.getGlobalDescribe() returns field which Account does not have.

Can anyone explain me what is going on here? Thanks.

 

My Apex class:

public with sharing class AccountPDFGenerator
 {
     
     public static final String FORM_HTML_START = '<HTML><BODY>';
     public static final String FORM_HTML_END = '</BODY></HTML>';

     public static void generateAccountPDF(Account account)
     {
     	System.debug('Account Name=' + account.Name);
         String pdfContent = '' + FORM_HTML_START;
         try
         {
             pdfContent = '' + FORM_HTML_START;
             pdfContent = pdfContent + '<H2>Account Information in PDF</H2>';
             
             //Dynamically grab all the fields to store in the PDF
             Map<String, Schema.SObjectType> sobjectSchemaMap = Schema.getGlobalDescribe();
             Schema.DescribeSObjectResult objDescribe = sobjectSchemaMap.get('Account').getDescribe();
             Map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
             
             //Append each Field to the PDF
             for(Schema.SObjectField fieldDef : fieldMap.values()) 
             {
             	System.debug('fieldDescResult  =' + fieldDef.getDescribe());
                 Schema.Describefieldresult fieldDescResult = fieldDef.getDescribe();
                 
                 System.debug('field name =' + fieldDescResult.getName());
                 String name = fieldDescResult.getName();
                 
                 System.debug('account.get(name) =' + account.get(name));
                 pdfContent = pdfContent + '<P>' + name + ': ' + account.get(name.trim()) + '</P>';
             }
             pdfContent = pdfContent + FORM_HTML_END;
         }catch(Exception e)
         {
         	System.debug('Error = ' + e.getMessage() );
         	System.debug('Account fields = ' + account );
         	
             pdfContent = '' + FORM_HTML_START;
             pdfContent = pdfContent + '<P>THERE WAS AN ERROR GENERATING PDF: ' + e.getMessage() + '</P>';
             pdfContent = pdfContent + FORM_HTML_END;
         }
         attachPDF(account,pdfContent);
     }
     
     public static void attachPDF(Account account, String pdfContent)
     {
         try
         {
             Attachment attachmentPDF = new Attachment();
             attachmentPDF.parentId = account.Id;
             attachmentPDF.Name = account.Name + '.pdf';
             attachmentPDF.body = Blob.toPDF(pdfContent); //This creates the PDF content
             insert attachmentPDF;
         }catch(Exception e)
         {
             account.addError(e.getMessage());
         }
     }
     
 }

 

Snippet of ebug log:

 

11:07:54.111 (1111596000)|USER_DEBUG|[24]|DEBUG|fieldDescResult  =Schema.DescribeFieldResult[getByteLength=0;getCalculatedFormula=null;getController=null;getDefaultValue=null;getDefaultValueFormula=null;getDigits=0;getInlineHelpText=null;getLabel=Last Referenced Date;getLength=0;getLocalName=LastReferencedDate;getName=LastReferencedDate;getPrecision=0;getRelationshipName=null;getRelationshipOrder=null;getScale=0;getSoapType=DATETIME;getSobjectField=LastReferencedDate;getType=DATETIME;isAccessible=true;isAutoNumber=false;isCalculated=false;isCascadeDelete=false;isCaseSensitive=false;isCreateable=false;isCustom=false;isDefaultedOnCreate=false;isDependentPicklist=false;isDeprecatedAndHidden=false;isDisplayLocationInDecimal=false;isExternalId=false;isFilterable=true;isGroupable=false;isHtmlFormatted=false;isIdLookup=false;isNameField=false;isNamePointing=false;isNillable=true;isPermissionable=false;isRestrictedDelete=false;isSortable=true;isUnique=false;isUpdateable=false;isWriteRequiresMasterRead=false;]
11:07:54.111 (1111606000)|SYSTEM_METHOD_EXIT|[24]|System.debug(ANY)
11:07:54.111 (1111614000)|SYSTEM_METHOD_ENTRY|[25]|Schema.SObjectField.getDescribe()
11:07:54.111 (1111631000)|SYSTEM_METHOD_EXIT|[25]|Schema.SObjectField.getDescribe()
11:07:54.111 (1111644000)|SYSTEM_METHOD_ENTRY|[27]|System.debug(ANY)
11:07:54.111 (1111649000)|USER_DEBUG|[27]|DEBUG|field name =LastReferencedDate
11:07:54.111 (1111654000)|SYSTEM_METHOD_EXIT|[27]|System.debug(ANY)
11:07:54.111 (1111665000)|SYSTEM_METHOD_ENTRY|[30]|SObject.get(String)
11:07:54.111 (1111742000)|EXCEPTION_THROWN|[30]|System.SObjectException: Invalid field LastReferencedDate for Account
11:07:54.111 (1111852000)|SYSTEM_METHOD_EXIT|[30]|SObject.get(String)
11:07:54.111 (1111894000)|SYSTEM_METHOD_ENTRY|[36]|System.SObjectException.getMessage()
11:07:54.111 (1111928000)|SYSTEM_METHOD_EXIT|[36]|System.SObjectException.getMessage()
11:07:54.111 (1111939000)|SYSTEM_METHOD_ENTRY|[36]|System.debug(ANY)
11:07:54.111 (1111945000)|USER_DEBUG|[36]|DEBUG|Error = Invalid field LastReferencedDate for Account
11:07:54.111 (1111950000)|SYSTEM_METHOD_EXIT|[36]|System.debug(ANY)
11:07:54.111 (1111966000)|SYSTEM_METHOD_ENTRY|[37]|String.valueOf(Object)
11:07:54.114 (1114349000)|SYSTEM_METHOD_EXIT|[37]|String.valueOf(Object)
11:07:54.114 (1114376000)|SYSTEM_METHOD_ENTRY|[37]|System.debug(ANY)
11:07:54.114 (1114383000)|USER_DEBUG|[37]|DEBUG|Account fields = Account:{Sub_conc_Academic_Advisor__c=null, Areas_of_Skill_or_Interest__pc=null, TickerSymbol=null, Concentration_Field_Coordinator__c=null, Foundation_Student_Level__c=null, Expected_Graduation_Term__c=null, Personal_Email__c=null, GPA__c=null, Original_City__c=null, Calswec_PCW__c=false, BillingStreet=null, Original_Zip__c=null, PersonAssistantName=null, Awards_Workstudy__c=false, Degree_Title__c=null, Prior_Supervisory_Experience__pc=null, ShippingLongitude=null, Rating=null, Previous__c=null, Program_of_Interest__c=null, Vehical_Required_Lead_Form__c=false, AccountSource=null, Anticipated_Return_Cohort__c=null, Access_to_Vehicle_During_Placement__c=false, Conc_Field_Liaison__c=null, SystemModstamp=2013-09-18 18:07:53, Vehicle_Required_During_Placement__c=null, Cohort_Accepted__c=null, PersonMailingLatitude=null, PersonLastCURequestDate=null, of_FT_Field_Instructors__c=null, Number_of_Health_Medical__c=0, Age__pc=null, Country_of_Citizenship__c=null, Number_of_Mental_Health_MVS__c=0, Foundation_Field_Liaison__c=null, Alternate_Placement_Days_Available__c=null, Imported_Ethnicity__c=null, Percent_Caucasian_Served__c=0, Middle_Name_Alias__c=null, Number_of_Work_and_Life_MVS__c=0, Foundation_Academic_Advisor__c=null, Other_Populations_Served__c=null, PersonDoNotCall=false, Agency_Requirements__c=null, RecordTypeId=012300000015e8sAAA, Percent_Asian_Served__c=0, Special_Schedule__c=false, Is_Active_Employee__pc=false, Number_of_Foundation_Students_Updated__c=null, Residency__c=null, Registered_Units__c=null, General_Focus_of_Services__c=null, Mental_Health_Rank__c=null, University_Title__pc=null, ADA_Compliance_Explanation__c=null, Active__pc=false, Accept_Foundation_Students__c=false, Concentration_Interest__c=null, AccountNumber=null, Consideration_Foundation_Populations_Exc__c=null, Awards_Stipends__c=false, Disability_Type__c=null, USC_Email__c=kross@usc.edu, PersonMailingStreet=null, Field_Status__c=null, Last_Enrollment_Term__c=null, of_PT_Field_Instructors__c=null, Number_of_Health_Medical_Updated__c=null, Phone=null, PersonMobilePhone=null, Sub_Concentration_Coordinator__c=null, BillingLatitude=null, PersonOtherLongitude=null, Prior_Experience_with_Interns__c=false, Primary_Demographic_Group_Served__c=null, LastActivityDate=2013-07-08 00:00:00, PersonMailingCountry=null, Auto_Insurance__c=false, University_Name__pc=null, PersonMailingState=null, Applied_for_Financial_Aid__c=false, Concentrations_Accepted__c=null, Length_of_Service__pc=null, Micro_Practice_Modalities__c=null, Home_Address__pc=null, Ownership=null, ParentId=null, Field_Instructor_Training_Date__pc=null, Languages__pc=null, Number_of_Mental_Health_SCH_PPS_Updated__c=null, Accept_Concentration_Students__c=false, LastModifiedDate=2013-09-18 18:07:53, Sub_conc_Field_Liaison__c=null, SIS_Local_Address_Last_Updated__c=null, Surrogate_Foundation_Liaison__c=null, Number_of_Family_and_Children_SCH_PPS__c=0, Intern_EBP_Training__c=false, PersonHasOptedOutOfFax=false, Primary_Populations_Served__c=null, Cohort_Current__c=null, First_Enrolled_Term__c=null, PersonTitle=null, Resume__pc=null, Resume_Received__pc=false, Agency_Auspice__c=null, Number_of_Mental_Health__c=0, Language__c=null, BillingCity=null, IsDeleted=false, LCSW__pc=false, Concentration_Field_Liaison__c=null, Number_of_Family_and_Children_Updated__c=null, Number_of_Mental_Health_SCH_PPS__c=0, Primary_Email__c=null, Modified_Schedule__c=false, AnnualRevenue=null, Is_LCSW__pc=false, Number_of_Mental_Health_MVS_Updated__c=null, BillingPostalCode=null, PersonEmailBouncedDate=null, GPA_Units__c=null, FirstName=Alba, Placements_Provided__c=null, PersonLeadSource=null, Intern_Workstation__c=null, PersonMailingPostalCode=null, ShippingStreet=null, Unit__pc=null, Ethnicity__c=Native American, MOU_Current__c=false, Disability__c=false, Is_SOWK_Graduate__pc=false, MasterRecordId=null, Placement_Consideration__c=null, Units_Attempted__c=null, PersonHomePhone=null, Percent_Native_American_Served__c=0, Number_of_Concentration_Students__c=0, Agency_Description__c=null, Primary_Contact_Type__c=null, Last_LOA_Semester__c=null, Last_Name_Alias__c=null, International_Phone_2__c=null, PersonLastCUUpdateDate=null, SicDesc=null, Macro_Practice_Modalities__c=null, Preferred_Greeting__pc=null, ADA_Compliant__c=false, Awards_Worstudy_Data_From_Lead__c=null, Conc_Academic_Advisor__c=null, LCSW_Year__pc=null, SIS_First_Enrolled_Term__c=null, Limitations_Personal_Qualities__pc=null, Personal_Email__pc=null, Secondary_Email__c=null, PersonMailingCity=null, Last_Semester_GPA__c=null, BillingLongitude=null, Tertiary_Populations_Served__c=null, BillingCountry=null, Reason_for_Enrollment_Exception__c=null, Number_Family_Children_SCH_PPS_Updated__c=null, PersonMailingLongitude=null, On_SAP_List__c=true, Id=001e000000AHXqMAAX, Date_of_Interview__pc=null, PersonEmailBouncedReason=null, Type=null, Site_Change__c=null, Number_of_Mental_Health_Updated__c=null, Accept_Concentration_Students_Updated__c=null, Faculty_Id__pc=null, Receive_Holiday_Card__pc=false, Placement_Consideration_Exception__c=null, Special_Student__c=false, Why_Current_Interest__c=null, Fax=null, Lead_Academic_Center_Interest__c=null, Level__pc=null, Intern_Activity_Description__c=null, Cleaned__c=false, Can_Provide_Services_in_Non_English_Lang__c=false, IUC__c=false, Evidence_Based_Practice__c=false, COPA_Rank__c=null, Consideration_Foundation_Populations__c=null, Sub_Pop_Code__c=null, Placement_Status__c=null, Has_Multiple_Locations__c=false, Number_of_Work_and_Life_MVS_Updated__c=null, Areas_of_Skill_or_Experience__pc=null, MSW_School__pc=null, Objective__c=null, Secondary_Populations_Served__c=null, Valid_Driver_s_Licence__c=false, Anticipated_Return_Semester_Year__c=null, Southern_California_County__c=null, Field_Personal_Statement__c=null, CreatedById=005a0000007rRD2AAM, Calswec_MH__c=false, Degree_Name__c=null, PersonAssistantPhone=null, OwnerId=005a0000007rRD2AAM, Number_of_Foundation_Students__c=null, BillingState=null, Reviewed_USC_Field_Requirements__pc=false, Number_of_COPA_MVS_Updated__c=null, of_Contract_Field_Instructors__c=null, First_Name_Alias__c=null, Language_2_Fluency__c=null, Waiver_Exam__c=false, CreatedDate=2013-06-28 21:01:45, JigsawCompanyId=null, Sic=null, Work_and_Life_Rank__c=null, Major__c=null, Field_Instructor_Training_Location__pc=null, Number_of_MSW_Employees__c=null, PersonHasOptedOutOfEmail=false, Placement_Clearance_Issue_Details__c=null, MSW_Degree_Year__pc=null, Notes_from_Agency_Lead__c=null, Concentration_Academic_Advisor__c=null, Site=null, Hours_of_Operation__c=null, Concentrations_Accepted_Last_Updated__c=null, Academic_Review_Completed__c=false, Sub_conc_Field_Coordinator__c=null, PR_Number__pc=null, Other_Language_1__c=null, Transfer_Student__c=false, Number_of_Work_and_Life_Updated__c=null, Conc_Field_Coordinator__c=null, IsPersonAccount=true, Industry=null, SalesforceCustomer=null, PersonContactId=003e00000070iW3AAI, Other_Language_2__c=null, Language_1_Fluency__c=null, Number_of_COPA__c=0, Date_Clean_Completed__c=null, Awards_Workstudy_Agency__c=false, Prior_Teaching_Experience__pc=null, Secondary_Reports_To__pc=null, Sub_Concentration__c=null, Description=null, Online_2Tor_Agency__c=false, Admissions_Term__c=null, LastModifiedById=005a0000007rRD2AAM, Faculty_USC_ID__pc=null, Location__pc=null, International_Student__c=false, Program_Change__c=null, Home_Visits_Required__c=null, Health_Rank__c=null, Latitude__c=null, Seminar_Instructor__c=null, PersonEmail=null, Number_of_Work_and_Life__c=0, Geographic_Area__c=null, LastName=Caldera, PersonDepartment=null, Gender__c=Female, NumberOfEmployees=null, Primary_Language__c=null, Tertiary_Demographic_Group_Served__c=null, ShippingCity=null, Degree__pc=null, Accept_Foundation_Students_Updated__c=null, Jigsaw=null, ShippingCountry=null, Units_Earned__c=null, Salutation=null, Number_of_Family_and_Children__c=0, USC_ID__c=67895789, AssistantEmail__pc=null, PersonOtherStreet=null, Longitude__c=null, PersonOtherPostalCode=null, Home_Visits_Required_From_Lead__c=false, Enrollment_Status__c=Full Time, Provides_Reimbursement_For__c=null, Academic_Condition__c=false, Post_Code__c=null, SIS_Permanent_Address_Last_Updated__c=null, Number_of_Health_Medical_MVS__c=0, PersonOtherPhone=null, Mezzo_Practice_Modalities__c=null, Grade_Points__c=null, Stipends_Available_To__c=null, Bilingual_Ability__c=null, Citizenship_Status__c=null, Memorandum_of_Agreement_Expiration_Date__c=null, Degree_Conferred_Date__c=null, of_Foundation_Placements__c=null, Completed_Field_Instructor_Training__pc=false, International_Phone_1__c=null, Percent_Latino_Served__c=0, Position__pc=null, County__c=null, Percent_African_American_Served__c=0, of_Concentration_Placements__c=null, Number_of_Family_and_Children_MVS__c=0, Faculty_Type__pc=null, Enrollment_Exception__c=null, Awarded_Work_Study__c=false, Number_of_Health_Medical_MVS_Updated__c=null, Prior_Teaching_or_Supervisory_Experience__pc=null, Paper_Opt_Out__c=false, PersonOtherState=null, ShippingLatitude=null, Status_of_Enrollment_Exception_Request__c=null, Preferred_Last_Name__c=null, Status_of_Site_Change__c=null, Why_Interested__pc=null, Site_Change_Effective_Semester__c=null, Program_Change_Effective_Semester__c=null, Limitations__pc=null, Additional_Comments__c=null, Status_Notes__pc=null, Number_of_COPA_Updated__c=null, Number_of_Family_Children_MVS_Updated__c=null, Campus__c=a0Be0000000X44mEAC, Placement_Consideration_Details__c=null, Fluency__c=null, ShippingPostalCode=null, PersonOtherCity=null, Status__c=null, Number_of_COPA_MVS__c=0, Concentration__c=null, ShippingState=null, PersonOtherCountry=null, Academic_Probation__c=false, Preferred_First_Name__c=null, Enrollment_Exception_Effective_Semester__c=null, Hire_Date__pc=null, Secondary_Demographic_Group_Served__c=null, Has_Field_Instructor__c=false, Status_of_Program_Change__c=null, Placement_Clearance_Issue__c=false, Families_and_Children_Rank__c=null, Stipend_Amount__c=null, Website=null, PersonBirthdate=null, PersonOtherLatitude=null}

 

 

 

 Thanks

 

 

 

 

 

 

 

I am new to Salesforce, so excuse me if I missed he obvious.

We have a Saleforce Site setup which is called ContactDirectory. I received a requirement to split this page to two pages: one for faculty, and another for staff. I tried two approaches trying to avoid the third approach.

My first thought was that I can simply choose Faculty Record Type for Contact object in a profile of the first site, and Staff Record Type for the second site. It turned out I misunderstand the purpose of selecting record types in profile of the site. I am still not clear on it, but it did not work.

My second way was to retrieve URL in a controller and then alternate SOQL query conditioned to this URL. URL which contains faculty will only select records for Faculty Record Type etc. Here I am not sure if it is good idea to build logic around URL. The main reason I am stack with idea is I do not know how to fix test cases that use PageReference to trigger controller. Specifically, I do not know how to set/pass URL when triggering VF page.

The third option would be just to copy everything for the second Site.

What would the best approach here? Should I try to reuse VF page and controller for similar sites?

Thanks.

Hi,

We have a requirement for rows to have different colors based on the record value. There are many online example how to achieve zebra style colors (odd,even), and we are using it now. However, I have not found a solution for multiple colors. (and also my css file does not affect table when i put "odd" and "even" styles into css file. It only works when it is embedded into VF page. ). Here is the VF page:

 

<apex:page controller="ContactController" showHeader="false" sidebar="false" standardStylesheets="false">
<style>
.odd {background-color: #FCF7F7;}
.even {background-color: #E3DCDB;}
</style>
<apex:stylesheet value="{!URLFOR($Resource.contactCss)}"/>
<apex:messages />

<apex:outputText style="font: normal normal 14px/30px Verdana, Arial, Georgia, serif;" rendered="{!NOT(ISNULL(contacts)) && contacts.size > 0}" value="School of Social Work Directory" />
<BR />
<apex:outputText style="font: normal normal 12px/30px Verdana, Arial, Georgia, serif;" rendered="{!NOT(ISNULL(contacts)) && contacts.size > 0}" value="Generated: {!NOW()}" />
<BR />
<BR />
<apex:pageBlock rendered="{!NOT(ISNULL(contacts)) && contacts.size > 0}" >


     <apex:dataTable value="{!contacts}" var="c" border="2" cellpadding="2" id="theTable" rowClasses="odd,even">
    
        <apex:column value="{!c.Name}" headerValue="Name" styleClass="cell" />
        <apex:column value="{!c.Phone}" headerValue="Phone" styleClass="cell" width="200px"/>
        <apex:column value="{!c.Location__c}" headerValue="Location" styleClass="cell"/>
        <apex:column value="{!c.Email}" headerValue="Email" styleClass="cell"/>        
        <apex:column value="{!c.Title}" headerValue="Title" styleClass="cell"/>
        
     </apex:dataTable>

</apex:pageBlock>
</apex:page>

 Here is static resource file:

 

.odd {background-color: #FCF7F7;}
.even {background-color: #E3DCDB;}
.table  
{
border-collapse:collapse;
width:100%;
border:1px solid black;
padding:2px;
}
th 
{
border:1px solid black;
padding:2px;
font: normal bold 11px/30px Verdana, Arial, Georgia, serif;
}
.cell 
{
border:1px solid black;
padding:2px;
font: normal normal 11px/30px Verdana, Arial, Georgia, serif;
}

 Thanks.

 Hai.............

 

              I had one problem regarding Dynamic search....

         I Had one custom object (Candidate) and input fields First Name ,LastName , City, Education  etc.....

On my visual force page, without typing any value in the input text field the values are displaying automatically and when i enter any value in the input field ERROR msg is displaying even the record is present

 

 

MY visualforce code :

<apex:page controller="CandidateSearchController" sidebar="false">
 <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("First_Name__c").value,
          document.getElementById("Last_Name__c").value,
          document.getElementById("City__c").value,
          document.getElementById("Education__c").options[document.getElementById("Education__c").selectedIndex].value
          );
      }
      </script> 
 
  <apex:form >
  <apex:pageMessages id="errors" />
 
  <apex:pageBlock title="Find Me A Candidate!" mode="edit">
 
  <table width="100%" border="0">
  <tr>  
    <td width="200" valign="top">
 
      <apex:pageBlock title="Parameters" mode="edit" id="criteria">
 
       
 
      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="First_Name__c" value="" />
          <apex:param name="Last_Name__c" value="" />
          <apex:param name="City__c" value="" />
          <apex:param name="Education__c" value="" />
      </apex:actionFunction>
 
      <table cellpadding="2" cellspacing="2">
      <tr>
        <td style="font-weight:bold;">First Name<br/>
        <input type="text" id="First_Name__c" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Last Name<br/>
        <input type="text" id="Last_Name__c" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">City<br/>
        <input type="text" id="City__c" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Education<br/>
          <select id="Education__c" onchange="doSearch();">
            <option value=""></option>
            <apex:repeat value="{!Education }" var="edc">
              <option value="{!edc}"> {!edc}</option>
            </apex:repeat>
          </select>
        </td>
      </tr>
      </table>
 
      </apex:pageBlock>
 
    </td>
    <td valign="top">
 
    <apex:pageBlock mode="edit" id="results">
 
        <apex:pageBlockTable value="{!candidates}" var="candidate">
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="First Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="first_name__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!Candidate.First_Name__c}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Last Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="last_Name__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!candidate.Last_Name__c}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="City" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="City__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!candidate.City__c}"/>
            </apex:column>
 
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Education" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Education__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!candidate.Education__c}"/>
            </apex:column>
 
        </apex:pageBlockTable> 
 
    </apex:pageBlock> 
 
    </td>
  </tr>
  </table>
 
  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />           
  </apex:pageBlock>    
 
  </apex:pageBlock>
 
  </apex:form>
 
</apex:page>

 

 

 

here is my Controller code;

 

public with sharing class CandidateSearchController {   
    
    private String soql {get;set;}
    // the collection of contacts to display
      Public List<Candidate__c> candidates {get;set;}
    // the current sort direction. deaults to asc
      public String sortDir{
      get { if (sortDir == null) { sortDir = 'asc'; } 
             return sortDir;
             }
             set;
             }
    // the current field to sort by. defaults to last name 
        public String sortField {
          get {
                if  ( sortField == null) {
                sortField = 'Last_Name__c'; } return sortField; }
                set;
                }
      // format the soql for display on the visualforce page 
           public String debugSoql {
              get { return soql + ' order by ' + sortField + ' ' + sortDir + 'limit 20 '; }
               set;
               }
      // init the contrller and display some sample data when the page loads
          public CandidatesearchController() {
            soql='select First_name__c,Last_name__c,City__c,Education__c from Candidate__c where Candidate__c.First_name__c != null';    
                   runQuery();
                   }
        // toggles the sorting  of query from asc<-->desc
            public void toggleSort() {
              //simply toggle the direction  
                   sortDir = sortDir.equals('asc') ? 'desc' : 'asc' ;
                  // run the query again
                    runQuery();
                    }             
        //runs the actualquery
           public void runQuery() {
              try {
                   candidates = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20 ');
                    }
                    catch (Exception e) {
                     ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ' OOOps! ') );
                     }
                   }                                
    // runs the search with parameters passed via JavaScript
      public PageReference runSearch(){
      
      
          String FirstName = Apexpages.currentPage().getParameters().get('First_Name__c');
    String LastName = Apexpages.currentPage().getParameters().get('Last_Name__c');
    String City = Apexpages.currentPage().getParameters().get('City__c');
    String Education = Apexpages.currentPage().getParameters().get('Education__c');
 
    soql='select First_name__c,Last_name__c,City__c,Education__c from Candidate__c where Candiadate__c.First_Name__c != null';    

    if (!FirstName.equals(''))
      soql += ' and First_Name__c LIKE \' '+String.escapeSingleQuotes(FirstName)+'%\'';
    if (!LastName.equals(''))
      soql += ' and Last_Name__c LIKE \''+String.escapeSingleQuotes(LastName)+'%\'';
    if (!City.equals(''))
      soql += ' and City__c LIKE \''+String.escapeSingleQuotes(city)+'%\'';  
    if (!Education.equals(''))
      soql += ' and Education__c LIKE (\''+Education+'\')';
 
    // run the query again
    runQuery();
 
    return null;
  }
 
  // use apex describe to build the picklist values
  public List<String> Education {
    get {
      
      
      
      if (Education == null) {
 
        Education = new List<String>();
        Schema.DescribeFieldResult field = Candidate__c.Education__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
         Education.add(f.getLabel());
 
      }
      return Education;          
    }
    set;
  }
 
}

 

I have the following Button below that opens a page to add a new record for "Drugs__c".  It pre-populates the Account field on the page, but I also want to auto populate the DrugsName (Name (text)) field  with the following text, "default".  I dont want our users to worry about filling in this field since it will be overrided with a naming convention using Workflow/FieldUpdate once the record is saved.  

 

Highlighed in red is the id of the field name, "Drugs Name" in the custom object "Drugs__c".  The code is not working properly and not populating the Drug Name field.  Suggestions how to correct this.  

 

 

/a0J/e?CF00NZ0000000etH2={!Account.Name} & CF00NZ0000000etH2_lkid={!Account.Id}&retURL=%2F{!Account.Id}&01IZ00000008qBS="default"

 

 

Hello.  Does anyone know the code needed to alternate background color rows in a datatable?  In other words, I want odd rows to have a white background and even rows should have a gray background.  I am trying to use.p:nth-child(even)/p:nth-child(odd)...but that code does not seem to be working.

 

Thanks in advance.

 

 

Hi,

 

I try this code:

http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php

 

And when I execute, get a Salesforce.com Login, I put my login and when back to my computer (a localhost), get this error:

   https://login.salesforce.com/services/oauth2/token failed with status 0

 

Anyone can explain whats append?!!!

 

Best Regards,

LB