• dlCamelot
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 16
    Replies
Have code that successfully brings back a list of IDs for records (dnbFinalMatchList), however, I'd struggling to return this as a wrapper table instead.  My classes keep getting rejected.  See original working code below:
 
Public Class Foobar {

@AuraEnabled 
    public static List<String> getDnBMatches(String companyName){
        
        List<String> dnbFinalMatchList = new List<String>();  
        List<String> dnbCompleteMatches = new List<String>(); 
        List<String> dnbPartialMatches = new List<String>();
        List<String> nameFragments = new List<String>();
        List<DatacloudDandBcompany> dnbData2 = new List<DatacloudDandBcompany>();
        Integer emptyList = 0;
        Map<id,DatacloudDandBcompany> dnbData = new Map<id,DatacloudDandBcompany>();


        if (String.isnotBlank(companyName)){
            for (String fragment : companyName.split(' ')){
                     nameFragments.add(fragment);
                     system.debug('DC - Fragments - ' + nameFragments);
                } 


            if(nameFragments != null) {
                dnbData2 = [SELECT companyID,
                                                    Name,
                                                    DunsNumber,
                                                    City,
                                                    State,
                                                    Country,
                                                    Zip
                                      FROM DatacloudDandBCompany WHERE Name IN :  nameFragments LIMIT 50];
                system.debug(dnbData2);

                if(dnbData2 != null) {
                    for (DatacloudDandBCompany c: dnbData2 ){
                        if (companyName == c.name){
                            dnbCompleteMatches.add(c.companyid);
                        }
                        dnbPartialMatches.add(c.companyid); 
                        
                    }
                dnbFinalMatchList.addall(dnbCompleteMatches);
                dnbFinalMatchList.addall(dnbPartialMatches);
                system.debug(dnbFinalMatchList);
                return dnbFinalMatchList;
                }
                else {
                    return null;
                }

            }
            else {
                return null;
            }
        }
        else{
        return null;    
        } 
         
    }

}

 
I'm trying to create a wrapper for my row return but I somehow need 2 classes to accomplish this.  I've only successfully written one of the classes which returns a string.  How do I take this new query - and make it into a wrapper?

New dnbData2 query:
dnbData2 = [SELECT companyID, Name, DunsNumber,City,State,Country,Zip FROM DatacloudDandBCompany WHERE Name IN :  nameFragments LIMIT 50];

Old Class that only returns a string:
Public class Foobar{

        @AuraEnabled 
    public static List<String> getDnBMatches(String companyName){
        List<String> dnbFinalMatchList = new List<String>();  
        List<String> dnbCompleteMatches = new List<String>(); 
        List<String> dnbPartialMatches = new List<String>();
        List<String> nameFragments = new List<String>();
        List<DatacloudDandBcompany> dnbData2 = new List<DatacloudDandBcompany>();
        Integer emptyList = 0;
        Map<id,DatacloudDandBcompany> dnbData = new Map<id,DatacloudDandBcompany>();
   
        if (String.isBlank(companyName)){
                system.debug('DC - No Company Name');
                return null;
        }else{
                for (String fragment : companyName.split(' ')){
                     nameFragments.add(fragment);
                     system.debug('DC - Fragments - ' + nameFragments);
                     } 
                     
               dnbData2 = [SELECT companyId, Name FROM DatacloudDandBCompany WHERE Name IN :('Deloitte','Consulting') LIMIT 50];
               system.debug(dnbData2);

                for (DatacloudDandBCompany c: dnbData2 ){
                    if (companyName == c.name){
                        dnbCompleteMatches.add(c.companyid);
                        system.debug('DC - dnbComplete Matches Loop');
                    }
                    dnbPartialMatches.add(c.companyid); 
                    system.debug('DC - dnbPartial Matches Loop');
                }

                if (dnbCompleteMatches.size() > emptyList) {
                    system.debug('DC - dnbComplete Matches Loop' + dnbCompleteMatches);
                    return dnbCompleteMatches;
                    

                }
                else {
                    return dnbPartialMatches;
                    

                }
         
        }
    }    
}
Please note, I have to keep the data manipulation in the new version (i.e. string fragment work, complete and partial results additions, etc.)
 
How do I merge these two lists of results into a master list (ex: dnbFinalMatchList )?  What would also be nice to have is that the list order has dnbCompleteMatches before dnbPartialMatches.  

Class So Far:
public static List<String> getDnBMatches(String companyName){
    	List<String> dnbFinalMatchList = new List<String>();  
        List<String> dnbCompleteMatches = new List<String>(); 
        List<String> dnbPartialMatches = new List<String>();
    	List<String> nameFragments = new List<String>();
        Integer emptyList = 0;
        Map<id,DatacloudDandBcompany> dnbData = new Map<id,DatacloudDandBcompany>();
   
        if (String.isBlank(companyName)){
            	return null;
        }else{
            	for (String fragment : companyName.split(' ')){
                     nameFragments.add('%' + fragment + '%');
                     }
                dnbData.putall([SELECT companyId FROM DatacloudDandBCompany WHERE Name LIKE :nameFragments]);
                for (DatacloudDandBCompany c: dnbData.values()){
                    if (companyName == c.name){
                        dnbCompleteMatches.add(c.companyid);
                    }
                    dnbPartialMatches.add(c.companyid); 
                }

                if (dnbCompleteMatches.size() > emptyList) {
                    return dnbCompleteMatches;
                }
                else {
                    return dnbPartialMatches;
                }
         
        }
    }

 
How do I my code so that I can pull 1 return statement or the other.  See below:
 
@AuraEnabled 
    public static List<String> getDnBMatches(String companyName){
    	List<String> dnbFinalMatchList = new List<String>();  
        List<String> dnbCompleteMatches = new List<String>(); 
        List<String> dnbPartialMatches = new List<String>();
    	List<String> nameFragments = new List<String>();
        Map<id,DatacloudDandBcompany> dnbData = new Map<id,DatacloudDandBcompany>();
   
        if (String.isBlank(companyName)){
            	return null;
        }else{
            	for (String fragment : companyName.split(' ')){
                     nameFragments.add('%' + fragment + '%');
                     }
                dnbData.putall([SELECT companyId FROM DatacloudDandBCompany WHERE Name LIKE :nameFragments]);
                for (DatacloudDandBCompany c: dnbData.values()){
                    if (companyName == c.name){
                        dnbCompleteMatches.add(c.companyid);
                    }
                    dnbPartialMatches.add(c.companyid); 
                }
        
         return dnbCompleteMatches;
         return dnbPartialMatches;
        }
    }
This part is the challenge:
return dnbCompleteMatches; return dnbPartialMatches; 
 
I'm trying to pass a string parameter to an Apex Controller then do a fuzzy SoQL search (% like % ) to find accounts with similar names.  Here's the code so far...

Lightning Controller:
buttonSearch : function(component, event, helper){
        var companyName = component.find("CompanyName").get("v.value");
    },

Apex Controller: 
Public Static void nameToSearch(String companyName){
        system.debug(companyName);
    }

How do I:
1) Bind the js controller parameter to apex?
2) execute the search in apex?  record ids should be the result. 
 
Trying to create a wrapper class that contains a custom variable.  So far, I have a regular table list, but want to add a custom variable (int) called 'Score'  which will be a calculation.  This variable will never be stored in a field.

Component Class: 
public class AccountScores {
  @AuraEnabled
  public static List<Account> getAccounts() {
    return [SELECT Id, name, industry, Type, Location__c, Phone
    FROM Account ORDER BY createdDate ASC LIMIT 10];
      
      
  }
}
Lightning Component:
<aura:component controller="AccountScores" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="accounts" type="List" />
  <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
  <!--
    Use a data table from the Lightning Design System:
    https://www.lightningdesignsystem.com/components/data-tables/
  -->
  <table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer slds-table--fixed-layout">
    <thead>
      <tr class="slds-text-heading--label">
        <th scope="col"><div class="slds-truncate" title="ID">ID</div></th>
        <th scope="col"><div class="slds-truncate" title="Name">Name</div></th>
        <th scope="col"><div class="slds-truncate" title="Type">Type</div></th>
        <th scope="col"><div class="slds-truncate" title="Score">Score</div></th>
        <th scope="col"><div class="slds-truncate" title="Phone">Phone</div></th>
        <th scope="col"><div class="slds-truncate" title="Delete">Delete</div></th>
      </tr>
    </thead>
    <tbody>
      <!-- Use the Apex model and controller to fetch server side data -->
      <aura:iteration items="{!v.accounts}" var="account">
        <tr>
          <th scope="row"><div class="slds-truncate" title="{!account.Id}">{!account.Id}</div></th>
          <td><div class="slds-truncate" title="{!account.Name}">{!account.Name}</div></td>
          <td><div class="slds-truncate" title="{!account.Type}">{!account.Type}</div></td>
          <td><div class="slds-truncate" title="{____}">{!THIS WILL BE THE CUSTOM SCORE}</div></td>
          <td><div class="slds-truncate" title="{!account.Phone}">{!account.Phone}</div></td>
          <td>
            <form class="account-form" onsubmit="{!c.deleteAccount}">
              <input type="hidden" value="{!account.Name}" class="account-name" />
              <!--
                Use a Lightning Base Component
                To display an icon next to the label
               -->
              <lightning:button label="Delete"
                                iconName="utility:delete"
                                iconPosition="left"
                                variant="destructive"
                                />
            </form>
          </td>
        </tr>
      </aura:iteration>
    </tbody>
  </table>
</aura:component>
Any ideas where  to start?  Code is helpful.
 
I have a single page that needs to preserve/keep a picklist value selected. I do this with LocalStorage. However, selecting the submit button then refreshes/clears the storage.

I want storage to only clear when the page closes. How can I fix this? Thanks!

JS for the VF Page: 
window.onload = confirmRecordType;

$(document).ready(function(){
                var type = localStorage.getItem("recordtype");
                $("[id*='NewUserAccess']").hide();
                $("[id*='Other']").hide();
                $("[id*='Details']").hide();
                $("[id*='Select_Record_Type']").change(function(){
                        if ($(this).val() == "New User Access") {
                                $("[id*='NewUserAccess']").show();
                                $("[id*='Other']").hide();
                                $("[id*='Details']").hide();
                        }  else if ($(this).val() == "Other") {
                                $("[id*='NewUserAccess']").hide();
                                $("[id*='Other']").show();
                                $("[id*='Details']").show();
                        } else if ($(this).val() == "Reporting Request" || $(this).val() == "Integration" || $(this).val() == "Enhancement") {
                                $("[id*='NewUserAccess']").hide();
                                $("[id*='Other']").hide();
                                $("[id*='Details']").show();

                       }    else {
                       };
                        var recordtype = $('[id*=Select_Record_Type]').val();
                        alert("record type stored on change " + recordtype);
                        localStorage.setItem("recordtype", recordtype);
                        var type = localStorage.getItem("recordtype");
                       alert(recordtype);

        } );
});


 function confirmRecordType() {
        alert("loading function");
        var recordtype = localStorage.getItem("recordtype");
        alert("new storage recordtype is" + recordtype );
                if (recordtype == "New User Access") {
                            $("[id*='NewUserAccess']").show();  
                            $("[id*='Other']").hide();
                            $("[id*='Details']").hide();
                }  else if (recordtype == "Other") {
                            $("[id*='NewUserAccess']").hide(); 
                            $("[id*='Other']").show();
                            $("[id*='Details']").show();
                } else if (recordtype == "Reporting Request" || $(this).val() == "Integration" || $(this).val() == "Enhancement") {
                            $("[id*='NewUserAccess']").hide(); 
                            $("[id*='Other']").hide();
                            $("[id*='Details']").show();
                }   else if (recordtype == "null") {
                            $("[id*='NewUserAccess']").hide();  
                            $("[id*='Other']").hide();
                            $("[id*='Details']").hide();
                }
            
} 

window.onbeforeunload = windowClosing;

function windowClosing(event) {
     localStorage.setItem("recordtype", "null");
}

Button for the VF Page: 
<apex:commandbutton action="{!submitRequest}" value="{!$Label.Submit_Request}"  />
Controller function of the button:
public PageReference submitRequest() {
            
           /*Get submitter info through email address entered*/
           list<User> currentUserLst = new List<User>(); 
           currentUserLst = [Select id, firstname, lastName, email from User Where email =: er.Email__c limit 1];   

          if (!currentUserLst.isEmpty()){
            /*If email matches User*/
            try{        
                insert er;
             }
            catch(DmlException ex){

                ApexPages.addMessages(ex);
                PageReference np = new PageReference('/apex/EnhancementRequestv2');
                np.setRedirect(false);
                system.debug('exception');
                return np;
             }
             
         
        }  
        /*If email does not match user */
        ELSE{ 
            
            Util.addPageError('Your email address does not match an account on file.  Please reverify.');
            PageReference np = new PageReference('/apex/EnhancementRequestv2');
            np.setRedirect(false);
            system.debug('exception');
            return np;
        }




 
Trying to get my VisualForce blocks to display based on the selection.  If 'new user request' selected in request type field, then NewAccount block should show.  If any other value is selected in request type field, then Details block should show.  

-------------------------------------------------------------------------------------------------------
VF Page

<apex:page controller="EnhancementRequestControllerv2" cache="false" showHeader="false" sidebar="false" title="Enhancement Request">
    <apex:includeScript value="{!$Resource.Jquery}" />
    <style>
    span.pbSubExtra {
      display: none;
    }
    input.instructions{
      margin: 10px; 
      width: 100%;
      text-align: left;
      margin-left: auto;
      margin-right: auto;
    }
    input.labels{
      margin: 10px;
      width: 100%;
      text-align: right;
      margin-left: auto;
      margin-right: auto;
      font-weight:bold
    }
    </style>
    
    <apex:image id="logo" value="{!$Resource.logo}" /> 
    
    <div style="width: 700px; margin-left: 5px;">
        <Script>
            $(document).ready(function(){
            $('[id*=NewAccount]').hide();
            $('[id*=Details]').hide();
            $('[id*=Select_Record_Type]').change(recordtype);
  

            function followupFields(){
                 alert('Showing followup fields');
                 var param = $('[id*=Select_Record_Type]').val();
                 if(param='New User Access'){
                     $('[id*=NewAccount]').show();       
                     alert('NewAccountDetails');
                     } 
                 else $('[id*Details]').show().
                    }     
            }
        });   
           
        </Script>
    <apex:form >
          <!-- main form section -->
          <apex:pageBlock id="thePB" mode="edit" rendered="{!NOT(showConfirmation)}"  >
                     <apex:pageMessages />
                     <apex:pageBlockSection collapsible="false" columns="1" title="Request Submission Form">
                     </apex:pageBlockSection>
             
                     <apex:pageBlockSection columns="1">
          
                                <apex:pageBlockSectionItem >
                                         <apex:outputPanel layout="block" styleClass="instructions">
                                                   <apex:outputLabel value="What is your request for the team?"  />
                                         </apex:outputPanel>
                                </apex:pageBlockSectionItem>
                   </apex:pageBlockSection> 
            
                   <apex:pageBlockSection columns="1">
                     <apex:pageBlockSectionItem >  
                            <apex:outputLabel value="{!$ObjectType.Enhancement_Request__c.Fields.Request_Type__c.Label}"  />
                            <apex:inputField id="Select_Record_Type" value="{!er.Request_Type__c}" style="width: 350px; height: 30px;" onchange="change();" />  
                     </apex:pageBlockSectionItem>
                      <br />
          </apex:pageBlockSection>
          
          <apex:pageBlockSection columns="1" id="NewAccount">
                    <apex:pageBlockSectionItem > 
                            <apex:outputPanel layout="block" styleClass="instructions">
                                <apex:outputLabel value="Please provide details of the new user account requested."  />
                            </apex:outputPanel>
                    </apex:pageBlockSectionItem>  
                  <apex:pageBlockSectionItem >
                        <apex:outputLabel id="showlabel" value="{!$ObjectType.Enhancement_Request__c.Fields.First_Name_New__c.Label}" />
                        <apex:inputField value="{!er.First_Name_New__c}" style="width: 350px;"/>  
                    </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                        <apex:outputLabel id="showlabel" value="{!$ObjectType.Enhancement_Request__c.Fields.Last_Name_New__c.Label}" />
                        <apex:inputField value="{!er.Last_Name_New__c}" style="width: 350px;"/>  
                    </apex:pageBlockSectionItem> 
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel id="showlabel" value="{!$ObjectType.Enhancement_Request__c.Fields.Email_New__c.Label}" />
                        <apex:inputField value="{!er.Email_New__c}" style="width: 350px;"/>  
                    </apex:pageBlockSectionItem> 
           </apex:pageBlockSection> 
             <apex:pageBlockSection columns="1" id="Details"> 
                  <apex:pageBlockSectionItem >  
                            <apex:outputLabel value="{!$ObjectType.Enhancement_Request__c.Fields.Details__c.Label}"  />
                            <apex:inputField value="{!er.Details__c}" style="width: 350px; height: 75px;" />
                  </apex:pageBlockSectionItem>
             </apex:pageBlockSection>
                      
             <br/>
              
             <apex:pageBlockSection columns="1"> 
                    <apex:pageBlockSectionItem >
                            <apex:outputPanel layout="block" styleClass="instructions">
                                    <apex:outputLabel value="Indicate the email account to receive notifications regarding this request."  /><br/>
                            </apex:outputPanel>
                    </apex:pageBlockSectionItem>
             </apex:pageBlockSection>
               <!-- submitter details  -->
             <apex:pageBlockSection columns="1"> 
                    <apex:pageBlockSectionItem >
                            <apex:outputPanel layout="block" styleClass="label">
                                    <apex:outputLabel value="Submitter Email"/>
                            </apex:outputPanel>
                            <apex:outputPanel layout="block" style="width: 100%; text-align: left; margin-left: auto; margin-right: auto;">
                                    <apex:inputField value="{!er.Email__c}" style="width: 350px;" />
                            <br/>
                            </apex:outputPanel>
                    </apex:pageBlockSectionItem>
               </apex:pageBlockSection>
                 
                 
            <!-- buttons section -->    
            <apex:pageBlockSection columns="1" collapsible="false" showHeader="false">
                    <apex:pageBlockSectionItem >
                            <apex:outputPanel layout="block" style="margin: 10px; width: 100%; text-align: center; margin-left: auto; margin-right: auto;">
                                    <apex:commandButton action="{!submitRequest}" value="Submit Request" />
                                    <apex:commandButton value="Clear" onclick="window.location.href=window.location.href; return false;"/>
                            </apex:outputPanel>
                    </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
      </apex:pageBlock>
    
      <!-- confirmation message, only renders when request is submitted -->
      <apex:pageBlock mode="edit" rendered="{!showConfirmation}" id="pb_conf" >
                <apex:pageBlockSection columns="1" title="Enhancement Request">
                    <apex:outputPanel layout="block" style="margin-bottom: 5px;">
                        Your request has been submitted and is being processed. You should receive an email confirmation regarding your submission.  
                    </apex:outputPanel>
                </apex:pageBlockSection>
      </apex:pageBlock>
    
    </apex:form>
    </div>
</apex:page> 
------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here is the controller, though it is not used for much:


public with sharing class EnhancementRequestControllerv2 {

    /*Constructors*/
    public EnhancementRequestControllerv2(){
    } 
    
    /*VF Page block render variable*/
    public Boolean showConfirmation { 
    set;
    get {
      if (showConfirmation == null)
          showConfirmation = false;
      return showConfirmation;
          }
    }

    
    /*  New Request */
    public Enhancement_Request__c er {
      get {
          if (er == null)
              er = new Enhancement_Request__c();
          return er;          
      }
      set;
    }
    
    /*Submission Logic*/
    public PageReference submitRequest() {
        
            /*General Field Validations*/
            //if (Util.isBlank(er.Email__c)) Util.addPageError('Please provide an email address.');
            
           /*Get submitter info through email address entered*/
           list<User> currentUserLst = new List<User>(); 
           currentUserLst = [Select id, firstname, lastName, email from User Where email =: er.Email__c limit 1];   
        
          
        IF(!currentUserLst.isEmpty()){
            /*If email matches  User*/
            try{
                /*Add user to practitioner field */
                er.Practitioner__c = currentUserLst[0].id;
                er.Email__c = currentUserLst[0].email;
                /*Indicate intake channel*/
                er.Form_Channel__c = TRUE;
                /*Hide submission page; show confirmation page*/
                showConfirmation = true;
                insert er;
                /* updated for automate approval */
                Approval.ProcessSubmitRequest sApprovalProcess = new Approval.ProcessSubmitRequest();
                sApprovalProcess.setComments('Submitted for Approval');
                sApprovalProcess.setObjectId(er.Id);
                Approval.ProcessResult result;
                result = Approval.process(sApprovalProcess);                
             }
            catch(DmlException ex){
                ApexPages.addMessages(ex);
             }
         
        }  
        /*If email does not match a user */
        ELSE{ 
            Util.addPageError('Your email address does not match a  account on file.  Please reverify or reach out to an admin.');
        }
        return null;
      
    }
   
}
I'm trying to create a form submission page (see VF below) that creates a new record with a custom controller (see Controller below) on my custom object = Enhancement Request.     Could someone figure out the gap in execution here?  

Bonus points:
1) I need to render visualforce blocks based on 'showConfirmation' variable; it should be TRUE when no error messages are present.  

CONTROLLER:

public with sharing class EnhancementRequestControllerv2 {
    /*  New Request */
  public Enhancement_Request__c er {
      get {
          if (er == null)
              er = new Enhancement_Request__c();
                er.Form_Channel__c = TRUE;
          return er;
      }
      set;
  }
   Public string CurrentUserId{get;set;}
   Public String CurrentUserEmailId{get;set;}
   Public String CurrentUserName{get;set;}

   public EnhancementRequestControllerv2(){
            CurrentUserId = userinfo.getuserid();
            CurrentUserEmailId = userinfo.getUserEmail(); 
            CurrentUserName = userinfo.getName();

    }
    */
 
        
    /*Save new record*/
    public PageReference submitRequest() {
     
        
        try{
            insert er;
               }
            catch(DmlException ex){
            ApexPages.addMessages(ex);
             
            }
        return null;  
    }
   
}
*******************************************************************************************************************************************************

VISUALFORCE PAGE

<apex:page controller="EnhancementRequestControllerv2"
           cache="false"
  showHeader="false"
  sidebar="false"
    title="Enhancement Request">

<html>
<head>
<title>Enhancement Request</title>
<style>
span.pbSubExtra {
  display: none;
}
input.instructions{
  margin: 10px; 
  width: 100%;
  text-align: left;
  margin-left: auto;
  margin-right: auto;
}
input.labels{
  margin: 10px;
  width: 100%;
  text-align: right;
  margin-left: auto;
  margin-right: auto;
  font-weight:bold
}
</style>
</head>
<body>
<apex:image id="logo" value="{!$Resource.logo}" /> 

<div style="width: 700px; margin-left: 5px;">
<apex:form >

  <apex:pageMessages />
  
  <apex:pageBlock id="thePB" mode="edit" rendered="{!NOT(showConfirmation)}" >

    <!-- main form section -->
    <apex:pageBlockSection collapsible="false" columns="1" title="Enhancement Submission Form">
          <!-- instructions -->
          <apex:pageBlockSectionItem >
              <apex:outputPanel layout="block" styleClass="instructions">
                  <apex:outputLabel value="What is your request for the team?"  />
              </apex:outputPanel>
          </apex:pageBlockSectionItem>
         <!-- inputs -->
           <apex:pageBlockSectionItem >  
              <apex:outputLabel value="{!$ObjectType.Enhancement_Request__c.Fields.Request_Type__c.Label}"  />
              <apex:inputField value="{!er.Request_Type__c}" style="width: 350px; height: 30px;" />   
           </apex:pageBlockSectionItem>  
           
           <apex:pageBlockSectionItem >  
              <apex:outputLabel value="{!$ObjectType.Enhancement_Request__c.Fields.Details__c.Label}"  />
              <apex:inputField value="{!er.Details__c}" style="width: 350px; height: 75px;" />
           </apex:pageBlockSectionItem> 
           <br/>
          <!-- instructions part2 -->
          <apex:pageBlockSectionItem >
              <apex:outputPanel layout="block" styleClass="instructions">
                  <apex:outputLabel value="The following account will receive notifications regarding this request."  /><br/>
              </apex:outputPanel>
           </apex:pageBlockSectionItem>
           <!-- submitter details -->  
           <apex:pageBlockSectionItem >
              <apex:outputPanel layout="block" styleClass="label">
                 <apex:outputLabel value="Submitter Name"/>
              </apex:outputPanel>
              <apex:outputPanel layout="block" style="width: 100%; text-align: left; margin-left: auto; margin-right: auto;">
                 <apex:outputText value="{!CurrentUserName}"/><br/>
              </apex:outputPanel>
           </apex:pageBlockSectionItem>
           <apex:pageBlockSectionItem >
              <apex:outputPanel layout="block" styleClass="label">
                 <apex:outputLabel style="font-weight:bold" value="Submitter Email"/>
              </apex:outputPanel>
              <apex:outputPanel layout="block" style="width: 100%; text-align: left; margin-left: auto; margin-right: auto;">
                 <apex:outputText value="{!CurrentUserEmailId}"/><br/>
              </apex:outputPanel>
          </apex:pageBlockSectionItem>

    </apex:pageBlockSection>
  
    <!-- buttons section -->    
    <apex:pageBlockSection columns="1" collapsible="false" showHeader="false">
      <apex:pageBlockSectionItem >
        <apex:outputPanel layout="block" style="margin: 10px; width: 100%; text-align: center; margin-left: auto; margin-right: auto;">
          <apex:commandButton action="{!submitRequest}" value="Submit Request" />
          <apex:commandButton value="Clear" onclick="window.location.href=window.location.href; return false;"/>
        </apex:outputPanel>
      </apex:pageBlockSectionItem>
    </apex:pageBlockSection>

  </apex:pageBlock>

  <!-- confirmation message, only renders when request is submitted -->
  <apex:pageBlock mode="edit" id="pb_conf" rendered="{!showConfirmation}">
    <apex:pageBlockSection columns="1" title="Enhancement Request">
      <apex:outputPanel layout="block" style="margin-bottom: 5px;">
        Your request has been submitted and is being processed. You should receive an email confirmation regarding your submission.  
      </apex:outputPanel>
    </apex:pageBlockSection>
  </apex:pageBlock>

</apex:form>
</div>

</body>
</html>

</apex:page>
Salesforce has a standard button on the Child Cases related list: New Case --> Child Case: Copy Parent Details

How can I recreate this button's actions on the Case Feed?  Is there a way to create a custom case action that prepopulates fields?
Trying to write a trigger purely to do the following:
WHEN case created (not edited)
THEN Case.Case_Owner__c (lookup field) overwrites OwnerID field.

Also need to include any catch exceptions in the code (just to keep best practices)

This is not working.  Any help?
trigger UpdateCaseOwner on Case (after insert) {
  // create a set of all the unique ownerIds
  Set<id> ownerIds = new Set<id>();
  //Identifying which records need data grabbed 
    for (Case c : Trigger.new)
      ownerIds.add(c.OwnerId);
    
  //Grabbing the data from those records
  Map<id, Case> owners = new Map<id, Case>([Select Case_Owner__c from Case Where Id in :ownerIds]); 

  //Adding that data back into the original records
      for (Case c : Trigger.new)
           try {
            c.OwnerID = owners.get(c.OwnerId).Case_Owner__c;
            }
            catch (System.NullPointerException e) {
            System.debug('Null pointer exception''); 
        }
}

 
On the service console, you can setup a tab/subtab relationship setup with Contact and Case objects.  This displays in the console a Contact's highlights panel followed by that Contact's Case Detail(s).  When creating a new case, no contact yet exists.  However, when you add the contact to the Case lookup and save the new Case record, the console tab never updates, only the subtab.

So how do I save a new case in the subtab, and then see that contact in the tab?  Is there a trigger that can be written upon new case save?
Trying to embed a video from the brightcove repository in a knowledge article.  Here's the iframe code:

<iframe align="middle" frameborder="0" scrolling="no" allowfullscreen="1" height="420" src="http://link.brightcove.com/services/player/bcpid<userID>?bckey=<playerkey>&secureConnections=true&secureHTMLConnections=true" width="480"></iframe>  

Is this ok?  What do I need for Visualforce page?
Created 85% of a test class that covers CollaborationGroups and FeedItems created.  How can I test that an error is properly being displayed on a FeedItem as it's created?  

Trigger Portion I'm trying to cover:
FeedItem List --> AddError

Best answer gets voted on!
Trying to build a trigger that will limit posts on a few Chatter Groups.  If anyone posts something that is NOT an announcement in these groups (indicated by 'Announcements' in the Group description), then they should receive an error.

The below code works if there's 1 group, but I need this to work for more than one group.
trigger announcementsOnly on FeedItem (after insert, after update) {

CollaborationGroup group = [SELECT OwnerId, Id FROM CollaborationGroup WHERE Description LIKE '%Announcements%'];
    
 List <FeedItem> fList = new List <FeedItem>();
    
    for(FeedItem items : trigger.new)
        
    {
        
       if(items.ParentId == group.Id && items.Type != 'AdvancedTextPost')

       {
      	 	items.addError('Please post an announcement post, not a text post.);
      	}
    }
    
}
Best answer will be voted on!
 
I am trying to build a VF page based off a bootstrap template.  This page throws an error in MavensMate, but does not tell the details of the error (syntax maybe?).  Does anyone else see what I'm missing?  Thanks!
<apex:page showHeader="false" sidebar="false" standardStylesheets="false" docType="html-5.0" standardController="Account" recordSetVar="accounts">

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="" />
    <meta name="author" content="" />
    <link rel="icon" href="../../favicon.ico" />

    <title>Dashboard Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <apex:stylesheet value="{!URLFOR{!Resource.bootstrap,'/css/bootstrap.min.css'}}" />

  </head>

  <body>
<!--
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#">Dashboard</a></li>
            <li><a href="#">Settings</a></li>
            <li><a href="#">Profile</a></li>
            <li><a href="#">Help</a></li>
          </ul>
          <form class="navbar-form navbar-right">
            <input type="text" class="form-control" placeholder="Search..." />
          </form>
        </div>
      </div>
    </nav>
-->

    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
        </div>

        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
          <h1 class="page-header">Dashboard</h1>
          <h2 class="sub-header">Section title</h2>
          <div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>#</th>
                  <th>Header</th>
                  <th>Header</th>
                  <th>Header</th>
                  <th>Header</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>1,001</td>
                  <td>Lorem</td>
                  <td>ipsum</td>
                  <td>dolor</td>
                  <td>sit</td>
                </tr>
                <tr>
                  <td>1,002</td>
                  <td>amet</td>
                  <td>consectetur</td>
                  <td>adipiscing</td>
                  <td>elit</td>
                </tr>
                <tr>
                  <td>1,003</td>
                  <td>Integer</td>
                  <td>nec</td>
                  <td>odio</td>
                  <td>Praesent</td>
                </tr>
                <tr>
                  <td>1,003</td>
                  <td>libero</td>
                  <td>Sed</td>
                  <td>cursus</td>
                  <td>ante</td>
                </tr>
                <tr>
                  <td>1,004</td>
                  <td>dapibus</td>
                  <td>diam</td>
                  <td>Sed</td>
                  <td>nisi</td>
                </tr>
                <tr>
                  <td>1,005</td>
                  <td>Nulla</td>
                  <td>quis</td>
                  <td>sem</td>
                  <td>at</td>
                </tr>
                <tr>
                  <td>1,006</td>
                  <td>nibh</td>
                  <td>elementum</td>
                  <td>imperdiet</td>
                  <td>Duis</td>
                </tr>
                <tr>
                  <td>1,007</td>
                  <td>sagittis</td>
                  <td>ipsum</td>
                  <td>Praesent</td>
                  <td>mauris</td>
                </tr>
                <tr>
                  <td>1,008</td>
                  <td>Fusce</td>
                  <td>nec</td>
                  <td>tellus</td>
                  <td>sed</td>
                </tr>
                <tr>
                  <td>1,009</td>
                  <td>augue</td>
                  <td>semper</td>
                  <td>porta</td>
                  <td>Mauris</td>
                </tr>
                <tr>
                  <td>1,010</td>
                  <td>massa</td>
                  <td>Vestibulum</td>
                  <td>lacinia</td>
                  <td>arcu</td>
                </tr>
                <tr>
                  <td>1,011</td>
                  <td>eget</td>
                  <td>nulla</td>
                  <td>Class</td>
                  <td>aptent</td>
                </tr>
                <tr>
                  <td>1,012</td>
                  <td>taciti</td>
                  <td>sociosqu</td>
                  <td>ad</td>
                  <td>litora</td>
                </tr>
                <tr>
                  <td>1,013</td>
                  <td>torquent</td>
                  <td>per</td>
                  <td>conubia</td>
                  <td>nostra</td>
                </tr>
                <tr>
                  <td>1,014</td>
                  <td>per</td>
                  <td>inceptos</td>
                  <td>himenaeos</td>
                  <td>Curabitur</td>
                </tr>
                <tr>
                  <td>1,015</td>
                  <td>sodales</td>
                  <td>ligula</td>
                  <td>in</td>
                  <td>libero</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="../../dist/js/bootstrap.min.js"></script>
    <!-- Just to make our placeholder images work. Don't actually copy the next line! -->
    <script src="../../assets/js/vendor/holder.js"></script>
  </body>
</html>

</apex:page>

 
Made a basic VF page for accounts that compiles with no errors.  However, the page columns render blank and don't show any records.  Is there something I need to adjust in the view permissions?  

Note: I'm trying to view the account page from the admin user who is also the owner of all accounts.
<apex:page showHeader="true" sidebar="true" standardStylesheets="true" docType="html-5.0" standardController="Account" recordSetVar="accounts">

<apex:pageBlock>
	<apex:pageBlockTable value="{!accounts}" var="a">
		<apex:column value="{!a.Name}" />
		<apex:column value="{!a.ShippingStreet}<{!a.ShippingCity}{!a.ShippingState}{!a.ShippingPostalCode}" />
	</apex:pageBlockTable>
</apex:pageBlock>

</apex:page>


Page Code:
<apex:page showHeader="true" sidebar="true" standardStylesheets="true" docType="html-5.0" standardController="Account" recordSetVar="accounts">

<apex:pageBlock>
    <apex:pageBlockTable value="{!accounts}" var="a">
        <apex:column value="{!a.Name}" />
        <apex:column value="{!a.ShippingStreet}<{!a.ShippingCity}{!a.ShippingState}{!a.ShippingPostalCode}" />
    </apex:pageBlockTable>
</apex:pageBlock>

</apex:page>
Trying to write a trigger that fires when a contact is created/updated.  The trigger would update a lookup field on the account (Account.Primary_Contact__c).  The correct ID comes from a contact record that has Contact.Primary_Contact__c = true.  

Why won't this work?

trigger fillPrimaryonAcct on Contact (before insert, before update) {
    //Collect IDs to update
    List<Id> cIdList = new list<Id>();
    List<Id> aIdList = new list<Id>();

    //Loop
    for(contact c: trigger.new) {
        aIdList.add(c.Id);
    
    }
    //List that grabs the Id of the primary contact
    List<Contact> pContact = [SELECT Id FROM Contact WHERE Primary_Contact__c = true, Id = :id];

}

Any better ways to do this would be appreciated!
Hi all,

I'm so close to getting this trigger to work, but could use some help with the last bit.  For context, this is a cross-object (child to parent) relationship - Event Attendence (child) adds/edits will update a date field on the Contact (parent).   What do I need to adjust? 

trigger Contact_Update on EventAttendance__c (before insert, before update) {
  //Holds Ids of Event Attendence Records
  Set<ID> eventattendIDs = new Set<ID>();
  //Maps Contact IDs to Event Attendence Date
  Map<ID,DATE> c2ea = new Map<ID,DATE>();
    
      for(EventAttendance__c ea: Trigger.new){
        eventattendIDs.add(ea.id);
        system.debug('This the event attendence record being added:'+ ea.id);
    }
    
   List<EventAttendance__c> lastDate = [SELECT Event_Date__c FROM EventAttendance__c WHERE Contact__c = :eventattendIDs ORDER BY Event_Date__c DESC LIMIT 1];
   system.debug('This is the date pulled by SoQL' + lastDate);
       
   for (Contact c: lastDate) {
        lastDate.Last_Event_Date__c =
        trigger.newMap.get(c2ea.date);  
    }
    
    update eventattendIDs;
}

Newbie here so please explain the logic for your changes.
Hi All,

I'm trying to get an array of strings returned based on Integer n, but seem to keep getting a value returned instead of a string.  What do I need to adjust?  Thanks!

public class StringArrayTest {
    public void generateStringArray(){
        List<String>stringArray = new List<String>{};
        Integer n = 4;
        for(Integer i=n;i<stringArray.size();i++){
            String myInt = n.format();
            stringArray.add('Test' + myInt);
        }
         return stringArray;  
    }
}
I'm trying to create a wrapper for my row return but I somehow need 2 classes to accomplish this.  I've only successfully written one of the classes which returns a string.  How do I take this new query - and make it into a wrapper?

New dnbData2 query:
dnbData2 = [SELECT companyID, Name, DunsNumber,City,State,Country,Zip FROM DatacloudDandBCompany WHERE Name IN :  nameFragments LIMIT 50];

Old Class that only returns a string:
Public class Foobar{

        @AuraEnabled 
    public static List<String> getDnBMatches(String companyName){
        List<String> dnbFinalMatchList = new List<String>();  
        List<String> dnbCompleteMatches = new List<String>(); 
        List<String> dnbPartialMatches = new List<String>();
        List<String> nameFragments = new List<String>();
        List<DatacloudDandBcompany> dnbData2 = new List<DatacloudDandBcompany>();
        Integer emptyList = 0;
        Map<id,DatacloudDandBcompany> dnbData = new Map<id,DatacloudDandBcompany>();
   
        if (String.isBlank(companyName)){
                system.debug('DC - No Company Name');
                return null;
        }else{
                for (String fragment : companyName.split(' ')){
                     nameFragments.add(fragment);
                     system.debug('DC - Fragments - ' + nameFragments);
                     } 
                     
               dnbData2 = [SELECT companyId, Name FROM DatacloudDandBCompany WHERE Name IN :('Deloitte','Consulting') LIMIT 50];
               system.debug(dnbData2);

                for (DatacloudDandBCompany c: dnbData2 ){
                    if (companyName == c.name){
                        dnbCompleteMatches.add(c.companyid);
                        system.debug('DC - dnbComplete Matches Loop');
                    }
                    dnbPartialMatches.add(c.companyid); 
                    system.debug('DC - dnbPartial Matches Loop');
                }

                if (dnbCompleteMatches.size() > emptyList) {
                    system.debug('DC - dnbComplete Matches Loop' + dnbCompleteMatches);
                    return dnbCompleteMatches;
                    

                }
                else {
                    return dnbPartialMatches;
                    

                }
         
        }
    }    
}
Please note, I have to keep the data manipulation in the new version (i.e. string fragment work, complete and partial results additions, etc.)
 
How do I merge these two lists of results into a master list (ex: dnbFinalMatchList )?  What would also be nice to have is that the list order has dnbCompleteMatches before dnbPartialMatches.  

Class So Far:
public static List<String> getDnBMatches(String companyName){
    	List<String> dnbFinalMatchList = new List<String>();  
        List<String> dnbCompleteMatches = new List<String>(); 
        List<String> dnbPartialMatches = new List<String>();
    	List<String> nameFragments = new List<String>();
        Integer emptyList = 0;
        Map<id,DatacloudDandBcompany> dnbData = new Map<id,DatacloudDandBcompany>();
   
        if (String.isBlank(companyName)){
            	return null;
        }else{
            	for (String fragment : companyName.split(' ')){
                     nameFragments.add('%' + fragment + '%');
                     }
                dnbData.putall([SELECT companyId FROM DatacloudDandBCompany WHERE Name LIKE :nameFragments]);
                for (DatacloudDandBCompany c: dnbData.values()){
                    if (companyName == c.name){
                        dnbCompleteMatches.add(c.companyid);
                    }
                    dnbPartialMatches.add(c.companyid); 
                }

                if (dnbCompleteMatches.size() > emptyList) {
                    return dnbCompleteMatches;
                }
                else {
                    return dnbPartialMatches;
                }
         
        }
    }

 
Trying to get my VisualForce blocks to display based on the selection.  If 'new user request' selected in request type field, then NewAccount block should show.  If any other value is selected in request type field, then Details block should show.  

-------------------------------------------------------------------------------------------------------
VF Page

<apex:page controller="EnhancementRequestControllerv2" cache="false" showHeader="false" sidebar="false" title="Enhancement Request">
    <apex:includeScript value="{!$Resource.Jquery}" />
    <style>
    span.pbSubExtra {
      display: none;
    }
    input.instructions{
      margin: 10px; 
      width: 100%;
      text-align: left;
      margin-left: auto;
      margin-right: auto;
    }
    input.labels{
      margin: 10px;
      width: 100%;
      text-align: right;
      margin-left: auto;
      margin-right: auto;
      font-weight:bold
    }
    </style>
    
    <apex:image id="logo" value="{!$Resource.logo}" /> 
    
    <div style="width: 700px; margin-left: 5px;">
        <Script>
            $(document).ready(function(){
            $('[id*=NewAccount]').hide();
            $('[id*=Details]').hide();
            $('[id*=Select_Record_Type]').change(recordtype);
  

            function followupFields(){
                 alert('Showing followup fields');
                 var param = $('[id*=Select_Record_Type]').val();
                 if(param='New User Access'){
                     $('[id*=NewAccount]').show();       
                     alert('NewAccountDetails');
                     } 
                 else $('[id*Details]').show().
                    }     
            }
        });   
           
        </Script>
    <apex:form >
          <!-- main form section -->
          <apex:pageBlock id="thePB" mode="edit" rendered="{!NOT(showConfirmation)}"  >
                     <apex:pageMessages />
                     <apex:pageBlockSection collapsible="false" columns="1" title="Request Submission Form">
                     </apex:pageBlockSection>
             
                     <apex:pageBlockSection columns="1">
          
                                <apex:pageBlockSectionItem >
                                         <apex:outputPanel layout="block" styleClass="instructions">
                                                   <apex:outputLabel value="What is your request for the team?"  />
                                         </apex:outputPanel>
                                </apex:pageBlockSectionItem>
                   </apex:pageBlockSection> 
            
                   <apex:pageBlockSection columns="1">
                     <apex:pageBlockSectionItem >  
                            <apex:outputLabel value="{!$ObjectType.Enhancement_Request__c.Fields.Request_Type__c.Label}"  />
                            <apex:inputField id="Select_Record_Type" value="{!er.Request_Type__c}" style="width: 350px; height: 30px;" onchange="change();" />  
                     </apex:pageBlockSectionItem>
                      <br />
          </apex:pageBlockSection>
          
          <apex:pageBlockSection columns="1" id="NewAccount">
                    <apex:pageBlockSectionItem > 
                            <apex:outputPanel layout="block" styleClass="instructions">
                                <apex:outputLabel value="Please provide details of the new user account requested."  />
                            </apex:outputPanel>
                    </apex:pageBlockSectionItem>  
                  <apex:pageBlockSectionItem >
                        <apex:outputLabel id="showlabel" value="{!$ObjectType.Enhancement_Request__c.Fields.First_Name_New__c.Label}" />
                        <apex:inputField value="{!er.First_Name_New__c}" style="width: 350px;"/>  
                    </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                        <apex:outputLabel id="showlabel" value="{!$ObjectType.Enhancement_Request__c.Fields.Last_Name_New__c.Label}" />
                        <apex:inputField value="{!er.Last_Name_New__c}" style="width: 350px;"/>  
                    </apex:pageBlockSectionItem> 
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel id="showlabel" value="{!$ObjectType.Enhancement_Request__c.Fields.Email_New__c.Label}" />
                        <apex:inputField value="{!er.Email_New__c}" style="width: 350px;"/>  
                    </apex:pageBlockSectionItem> 
           </apex:pageBlockSection> 
             <apex:pageBlockSection columns="1" id="Details"> 
                  <apex:pageBlockSectionItem >  
                            <apex:outputLabel value="{!$ObjectType.Enhancement_Request__c.Fields.Details__c.Label}"  />
                            <apex:inputField value="{!er.Details__c}" style="width: 350px; height: 75px;" />
                  </apex:pageBlockSectionItem>
             </apex:pageBlockSection>
                      
             <br/>
              
             <apex:pageBlockSection columns="1"> 
                    <apex:pageBlockSectionItem >
                            <apex:outputPanel layout="block" styleClass="instructions">
                                    <apex:outputLabel value="Indicate the email account to receive notifications regarding this request."  /><br/>
                            </apex:outputPanel>
                    </apex:pageBlockSectionItem>
             </apex:pageBlockSection>
               <!-- submitter details  -->
             <apex:pageBlockSection columns="1"> 
                    <apex:pageBlockSectionItem >
                            <apex:outputPanel layout="block" styleClass="label">
                                    <apex:outputLabel value="Submitter Email"/>
                            </apex:outputPanel>
                            <apex:outputPanel layout="block" style="width: 100%; text-align: left; margin-left: auto; margin-right: auto;">
                                    <apex:inputField value="{!er.Email__c}" style="width: 350px;" />
                            <br/>
                            </apex:outputPanel>
                    </apex:pageBlockSectionItem>
               </apex:pageBlockSection>
                 
                 
            <!-- buttons section -->    
            <apex:pageBlockSection columns="1" collapsible="false" showHeader="false">
                    <apex:pageBlockSectionItem >
                            <apex:outputPanel layout="block" style="margin: 10px; width: 100%; text-align: center; margin-left: auto; margin-right: auto;">
                                    <apex:commandButton action="{!submitRequest}" value="Submit Request" />
                                    <apex:commandButton value="Clear" onclick="window.location.href=window.location.href; return false;"/>
                            </apex:outputPanel>
                    </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
      </apex:pageBlock>
    
      <!-- confirmation message, only renders when request is submitted -->
      <apex:pageBlock mode="edit" rendered="{!showConfirmation}" id="pb_conf" >
                <apex:pageBlockSection columns="1" title="Enhancement Request">
                    <apex:outputPanel layout="block" style="margin-bottom: 5px;">
                        Your request has been submitted and is being processed. You should receive an email confirmation regarding your submission.  
                    </apex:outputPanel>
                </apex:pageBlockSection>
      </apex:pageBlock>
    
    </apex:form>
    </div>
</apex:page> 
------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here is the controller, though it is not used for much:


public with sharing class EnhancementRequestControllerv2 {

    /*Constructors*/
    public EnhancementRequestControllerv2(){
    } 
    
    /*VF Page block render variable*/
    public Boolean showConfirmation { 
    set;
    get {
      if (showConfirmation == null)
          showConfirmation = false;
      return showConfirmation;
          }
    }

    
    /*  New Request */
    public Enhancement_Request__c er {
      get {
          if (er == null)
              er = new Enhancement_Request__c();
          return er;          
      }
      set;
    }
    
    /*Submission Logic*/
    public PageReference submitRequest() {
        
            /*General Field Validations*/
            //if (Util.isBlank(er.Email__c)) Util.addPageError('Please provide an email address.');
            
           /*Get submitter info through email address entered*/
           list<User> currentUserLst = new List<User>(); 
           currentUserLst = [Select id, firstname, lastName, email from User Where email =: er.Email__c limit 1];   
        
          
        IF(!currentUserLst.isEmpty()){
            /*If email matches  User*/
            try{
                /*Add user to practitioner field */
                er.Practitioner__c = currentUserLst[0].id;
                er.Email__c = currentUserLst[0].email;
                /*Indicate intake channel*/
                er.Form_Channel__c = TRUE;
                /*Hide submission page; show confirmation page*/
                showConfirmation = true;
                insert er;
                /* updated for automate approval */
                Approval.ProcessSubmitRequest sApprovalProcess = new Approval.ProcessSubmitRequest();
                sApprovalProcess.setComments('Submitted for Approval');
                sApprovalProcess.setObjectId(er.Id);
                Approval.ProcessResult result;
                result = Approval.process(sApprovalProcess);                
             }
            catch(DmlException ex){
                ApexPages.addMessages(ex);
             }
         
        }  
        /*If email does not match a user */
        ELSE{ 
            Util.addPageError('Your email address does not match a  account on file.  Please reverify or reach out to an admin.');
        }
        return null;
      
    }
   
}
Salesforce has a standard button on the Child Cases related list: New Case --> Child Case: Copy Parent Details

How can I recreate this button's actions on the Case Feed?  Is there a way to create a custom case action that prepopulates fields?
Trying to write a trigger purely to do the following:
WHEN case created (not edited)
THEN Case.Case_Owner__c (lookup field) overwrites OwnerID field.

Also need to include any catch exceptions in the code (just to keep best practices)

This is not working.  Any help?
trigger UpdateCaseOwner on Case (after insert) {
  // create a set of all the unique ownerIds
  Set<id> ownerIds = new Set<id>();
  //Identifying which records need data grabbed 
    for (Case c : Trigger.new)
      ownerIds.add(c.OwnerId);
    
  //Grabbing the data from those records
  Map<id, Case> owners = new Map<id, Case>([Select Case_Owner__c from Case Where Id in :ownerIds]); 

  //Adding that data back into the original records
      for (Case c : Trigger.new)
           try {
            c.OwnerID = owners.get(c.OwnerId).Case_Owner__c;
            }
            catch (System.NullPointerException e) {
            System.debug('Null pointer exception''); 
        }
}

 
HI All

I have created one visualforce page with standard controller account and extension opertunity.I have insert that page over standard layout account section.I have facing one issue it showing Edit,Delete Button as stanadrd controller .I need to hide that button only my visualforce page that inherit from stanadard controller.
I am trying to build a VF page based off a bootstrap template.  This page throws an error in MavensMate, but does not tell the details of the error (syntax maybe?).  Does anyone else see what I'm missing?  Thanks!
<apex:page showHeader="false" sidebar="false" standardStylesheets="false" docType="html-5.0" standardController="Account" recordSetVar="accounts">

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="" />
    <meta name="author" content="" />
    <link rel="icon" href="../../favicon.ico" />

    <title>Dashboard Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <apex:stylesheet value="{!URLFOR{!Resource.bootstrap,'/css/bootstrap.min.css'}}" />

  </head>

  <body>
<!--
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#">Dashboard</a></li>
            <li><a href="#">Settings</a></li>
            <li><a href="#">Profile</a></li>
            <li><a href="#">Help</a></li>
          </ul>
          <form class="navbar-form navbar-right">
            <input type="text" class="form-control" placeholder="Search..." />
          </form>
        </div>
      </div>
    </nav>
-->

    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
        </div>

        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
          <h1 class="page-header">Dashboard</h1>
          <h2 class="sub-header">Section title</h2>
          <div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>#</th>
                  <th>Header</th>
                  <th>Header</th>
                  <th>Header</th>
                  <th>Header</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>1,001</td>
                  <td>Lorem</td>
                  <td>ipsum</td>
                  <td>dolor</td>
                  <td>sit</td>
                </tr>
                <tr>
                  <td>1,002</td>
                  <td>amet</td>
                  <td>consectetur</td>
                  <td>adipiscing</td>
                  <td>elit</td>
                </tr>
                <tr>
                  <td>1,003</td>
                  <td>Integer</td>
                  <td>nec</td>
                  <td>odio</td>
                  <td>Praesent</td>
                </tr>
                <tr>
                  <td>1,003</td>
                  <td>libero</td>
                  <td>Sed</td>
                  <td>cursus</td>
                  <td>ante</td>
                </tr>
                <tr>
                  <td>1,004</td>
                  <td>dapibus</td>
                  <td>diam</td>
                  <td>Sed</td>
                  <td>nisi</td>
                </tr>
                <tr>
                  <td>1,005</td>
                  <td>Nulla</td>
                  <td>quis</td>
                  <td>sem</td>
                  <td>at</td>
                </tr>
                <tr>
                  <td>1,006</td>
                  <td>nibh</td>
                  <td>elementum</td>
                  <td>imperdiet</td>
                  <td>Duis</td>
                </tr>
                <tr>
                  <td>1,007</td>
                  <td>sagittis</td>
                  <td>ipsum</td>
                  <td>Praesent</td>
                  <td>mauris</td>
                </tr>
                <tr>
                  <td>1,008</td>
                  <td>Fusce</td>
                  <td>nec</td>
                  <td>tellus</td>
                  <td>sed</td>
                </tr>
                <tr>
                  <td>1,009</td>
                  <td>augue</td>
                  <td>semper</td>
                  <td>porta</td>
                  <td>Mauris</td>
                </tr>
                <tr>
                  <td>1,010</td>
                  <td>massa</td>
                  <td>Vestibulum</td>
                  <td>lacinia</td>
                  <td>arcu</td>
                </tr>
                <tr>
                  <td>1,011</td>
                  <td>eget</td>
                  <td>nulla</td>
                  <td>Class</td>
                  <td>aptent</td>
                </tr>
                <tr>
                  <td>1,012</td>
                  <td>taciti</td>
                  <td>sociosqu</td>
                  <td>ad</td>
                  <td>litora</td>
                </tr>
                <tr>
                  <td>1,013</td>
                  <td>torquent</td>
                  <td>per</td>
                  <td>conubia</td>
                  <td>nostra</td>
                </tr>
                <tr>
                  <td>1,014</td>
                  <td>per</td>
                  <td>inceptos</td>
                  <td>himenaeos</td>
                  <td>Curabitur</td>
                </tr>
                <tr>
                  <td>1,015</td>
                  <td>sodales</td>
                  <td>ligula</td>
                  <td>in</td>
                  <td>libero</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="../../dist/js/bootstrap.min.js"></script>
    <!-- Just to make our placeholder images work. Don't actually copy the next line! -->
    <script src="../../assets/js/vendor/holder.js"></script>
  </body>
</html>

</apex:page>

 
Made a basic VF page for accounts that compiles with no errors.  However, the page columns render blank and don't show any records.  Is there something I need to adjust in the view permissions?  

Note: I'm trying to view the account page from the admin user who is also the owner of all accounts.
<apex:page showHeader="true" sidebar="true" standardStylesheets="true" docType="html-5.0" standardController="Account" recordSetVar="accounts">

<apex:pageBlock>
	<apex:pageBlockTable value="{!accounts}" var="a">
		<apex:column value="{!a.Name}" />
		<apex:column value="{!a.ShippingStreet}<{!a.ShippingCity}{!a.ShippingState}{!a.ShippingPostalCode}" />
	</apex:pageBlockTable>
</apex:pageBlock>

</apex:page>


Page Code:
<apex:page showHeader="true" sidebar="true" standardStylesheets="true" docType="html-5.0" standardController="Account" recordSetVar="accounts">

<apex:pageBlock>
    <apex:pageBlockTable value="{!accounts}" var="a">
        <apex:column value="{!a.Name}" />
        <apex:column value="{!a.ShippingStreet}<{!a.ShippingCity}{!a.ShippingState}{!a.ShippingPostalCode}" />
    </apex:pageBlockTable>
</apex:pageBlock>

</apex:page>
Trying to write a trigger that fires when a contact is created/updated.  The trigger would update a lookup field on the account (Account.Primary_Contact__c).  The correct ID comes from a contact record that has Contact.Primary_Contact__c = true.  

Why won't this work?

trigger fillPrimaryonAcct on Contact (before insert, before update) {
    //Collect IDs to update
    List<Id> cIdList = new list<Id>();
    List<Id> aIdList = new list<Id>();

    //Loop
    for(contact c: trigger.new) {
        aIdList.add(c.Id);
    
    }
    //List that grabs the Id of the primary contact
    List<Contact> pContact = [SELECT Id FROM Contact WHERE Primary_Contact__c = true, Id = :id];

}

Any better ways to do this would be appreciated!
Hi All,

I am trying to draft a my first trigger from scratch (up to this point, I have only been tweaking code already in existance).  I'm struggling to develop a multi-object trigger.  I would like a child record (task) to be created upon a parent record meeting certain criteria.  Here's the work so far:

trigger ClosedOpportunityTask on Opportunity (after insert,after update) {
    //Maps,Sets,Lists to Be Used
    Set<Id> oppIds = new set<Id>();
    Map<Id,Opportunity> mapTask2Opp = new map<Id,Opportunity>();
    List<Task> taskList = new List<Task>();
    
    //Bulk Trigger Loop
    for (Opportunity o: trigger.new){
        oppIds.add(o.Id);
        mapTask2Opp.put(o.id, o);
    }
   
   //Tasks to be Created
   taskList = [SELECT Id, Subject FROM Task WHERE whatid IN : oppIds];
   
   //Create new task only if one doesn't already exist 
    if(taskList.size()= 0){
        for(Task t: Tasklist){
            t.What = ? //needs to get the parent opp's id
            t.Subject = 'Follow Up Test Task';
        }
        update taskList;
    } 
}


Right now, my logic for finding records without tasks 'taskList.size()= 0' is not effective, nor do I have a good way to link the task back to the parent via the 'Related To' field (API = 'What').

Can anyone lead me in the right direction for fixing?  If you can, please also explain why.  I'd really like to learn from my mistakes!  :)