• ColinKenworthy
  • NEWBIE
  • 75 Points
  • Member since 2010

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 22
    Replies
Hi, I am trying to display and update fields for an my License_Verification__c Object 
with a lookup with Contacts.  I want to update and save in one shot, however my 
contact fields are not being updated on Save and not sure what I am missing, please help.
public with sharing class ConAcctVerificationInfoControllerExt {
   
    
private ApexPages.StandardController std;           

// Associated Licenses
public List<License_Verification__c> licenses;

// License Agency Contact
Contact LicenseAgencyContact;

public ConAcctVerificationInfoControllerExt(ApexPages.StandardController stdCtrl)
    {      
    std=stdCtrl;     
    }           
    
    public Account getAccount()     
    {      
        return (Account) std.getRecord();    
    }    
     

//----------------------------LICENSES METHOD--------------------------------------->
     
      public List<License_Verification__c> getlicenses()     
       {        
         if ( (null!=getAccount().id) && (licenses == null) )
              
       {            
        licenses=[SELECT Id, Account__r.ID, Account__c, LV_Agency_Contact__r.ID, LV_Agency_Contact__r.Company_Name__c,LV_Agency_Contact__r.Email, LV_Agency_Contact__r.Phone, LV_Agency_Contact__r.LastName,LV_Agency_Contact__r.FirstName, LV_Agency_Contact__r.Fax, LV_License_Type__c, LV_License_Number__c,LV_License_Expiration_Date__c                          
        FROM License_Verification__c                           
        WHERE Account__c = : getAccount().ID                          
        ORDER BY CreatedDate];
                       }                                    
        return licenses;   
       }       
     
public PageReference save()     
  {      
  Boolean result=true;      
  PageReference pr=Page.TestParentChild;      
  if (null!=getAccount().id)      
  {       
  result=updateContacts();     
   }      
    else     
  {       
   pr.setRedirect(true);      
  }             
  if (result)      
  {         
// call standard controller save, but don't capture the return value which will redirect to view page         
  update Principalcontact;
  update IDV;
  update licenses; // ONLY FIELDS ON PARENT OBJECT ARE BEING UPDATED ON SAVE                                                
   std.save();            
 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Changes saved'));      
 }         
pr.getParameters().put('id', getAccount().id);             
 return pr;     
 }  

 

 

<apex:page standardController="Account" extensions="ConAcctVerificationInfoControllerExt" title="Test Verification Info" >

<apex:pageMessages />     
<apex:form >         

<apex:pageBlock mode="mainDetail">             
<apex:pageBlockButtons location="top">                 
<apex:commandButton action="{!cancel}" value="Exit" />                 
<apex:commandButton action="{!save}" value="Save" />                 
</apex:pageBlockButtons> 

            
<apex:repeat value="{!licenses}" var="license" >                     

<apex:pageBlockSection columns="2"  title="License {!license.LV_License_Type__c}:{!license.LV_License_Number__c} Verification" collapsible="true">                         
                
<!--<apex:repeat value="{!$ObjectType.License_Verification__c.FieldSets.LV_Input_Info}" var="field">                      
<apex:inputField value="{!license[field]}" />                     
</apex:repeat>--> 
<apex:inputfield value="{!license.LV_Agency_Contact__r.ID}" /> 
<apex:inputfield value="{!license.Account__r.ID}" />
<apex:inputfield value="{!license.LV_License_Type__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.FirstName}" />
<apex:inputfield value="{!license.LV_License_Number__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.LastName}" />  
<apex:inputfield value="{!license.LV_License_Expiration_Date__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.Email}" />
<apex:inputfield value="{!license.LV_Agency_Contact__r.Company_Name__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.Phone}" />                       

<div style="text-align:center">                            
<apex:commandButton action="{!save}" value="Save" />
<!--<apex:commandButton action="{!AddNewLicense}" value="Add New" /> -->                            
</div>     
                                           
</apex:pageBlockSection>                        
               
</apex:repeat>             

 

  • May 23, 2011
  • Like
  • 0

Hi,

 

I have created a pageblock table and listed all transactions under a contact. In that transactions, For example there are 4 transactions for a single credit card number fora single contact.I need only the last transaction for that  credit card number.

 

For that, I want to remove the duplicates of credit card number. 

 

Here is my code:

 

Page:

 

 

<apex:page standardController="Contact" extensions="CreditTransactions">
<apex:form >
 <apex:pageBlock >
<apex:pageBlockTable value="{!trans}" var="transaction">
  <apex:column headerValue="Date Last Used" value="{!transaction.TransactionDate__c}"/> 
    <apex:column headerValue="Last 4 digits" value="{!transaction.CreditCard4x4__c}"/> 
    <apex:column headerValue="Expiration Date" value="{!transaction.CardExpiration__c}"/> 
    <apex:column headerValue="Card Type" value="{!transaction.Credit_Card_Name__c}"/> 
    <apex:column >
    <apex:commandButton action="{!VTerminal}" value="Virtual Terminal"/>
    </apex:column>
</apex:pageBlockTable>
  </apex:pageBlock>
  </apex:form>
 <apex:detail />
</apex:page>
Controller:
public with sharing class CreditTransactions {
public List<CnP_Transaction__c> trans{get;set;}
public List<CnP_Transaction__c> duplicates{get;set;}
 set<string> CreditOrderNumber=new set<string>();
 public String ContactId{get;set;}
    public CreditTransactions(ApexPages.StandardController controller) {
     
     ContactId = ApexPages.currentPage().getParameters().get('Id');
     List<CnP_Transaction__c> ToCreateCredits=[select Id, Name,CreditCard4x4__c, Contact__c from CnP_Transaction__c where Contact__c = :contactId];
 
         for(Integer i=0;i<ToCreateCredits.size();i++){
             CreditOrderNumber.add(ToCreateCredits[i].CreditCard4x4__c);
         }
         
  
         
     System.debug('Credit Order numberrrr'+CreditOrderNumber);
     trans = [select Id,Name,TransactionDate__c,Contact__c,Credit_Card_Name__c,CreditCard4x4__c,CardExpiration__c from CnP_Transaction__c where CreditCard4x4__c IN :CreditOrderNumber and Contact__c= :ContactId and CreditCard4x4__c!=null];
    }
    public CreditTransactions() {
     }
     public PageReference Vterminal() 
    {
     return Page.VirtualTerminal;
    }
}
I want  a list of records in the table which does not repeat any credit card number and if more transactions with the same credit card is there need to display the last transaction..
Can any one of you help me regarding this.
Anu

 

Hello -

 

I am trying to add a visualforce page to my custom object that will show the related products.

 

So my "Sales Checklist" object is housed on the opportunity, sales fills all the information out then the object is sent to a queue.

 

But to save time i want to pull in the opportunityLineItems in to the sales checklist?

 

Is this possable? I know very little visualforce.

 

This is as far as I have gotten:

 

<apex:page StandardController="Sales_Checklist__c">
<apex:relatedList list="Opportunity__r" />

<apex:pageBlock title="{!Sales_Checklist__c.Opportunity__r.Name}"/>

  <apex:dataTable value="{!Sales_Checklist__c.Opportunity__r}" var="opp" cellPadding="4" border="1">
                
           <apex:column ><apex:facet name="header">Product Name</apex:facet></apex:column>
                
                
           <apex:column><apex:facet name="header">Quantity</apex:facet></apex:column>
                
                
           <apex:column ><apex:facet name="header">Unit Price</apex:facet></apex:column>
                
              
           <apex:column ><apex:facet name="header">Total Price</apex:facet></apex:column>
  </apex:dataTable>
</apex:page>

 

 

any help would be greatlt appriciated

 

Thanks,

Niki

I've created a really simple custom object (Colin__c) with a few text, picklist and checkbox fields. I've created a simple VF page with inline editing on the fields.

Now, depending on what I do between filling in a value in the field and clicking the Save button, it will affect whether the new value is saved or not.

 

 

<apex:page id="P1" standardController="Colin__c" >

    <apex:form id="F1" >
    <apex:sectionHeader title="{!Colin__c.Name}" />

    <apex:PageBlock id="PB1">
        <apex:pageMessages />

        <apex:pageBlockButtons id="PBB" location="both">
            <apex:commandButton id="inlineEditSave"   value="Save"   action="{!save}"   style="display:none"/>
            <apex:commandButton id="inlineEditCancel" value="Cancel" action="{!cancel}" style="display:none"/>
            <apex:commandButton id="editButton"       value="Edit"   action="{!edit}"/>
            <apex:commandButton id="deleteButton"     value="Delete" action="{!delete}" onclick="if ((Modal.confirm && Modal.confirm('Are you sure?')) || (!Modal.confirm && window.confirm('Are you sure?'))) {return true;} else {return false;}"/>
        </apex:pageBlockButtons>

        <apex:pageBlockSection id="PBS" title="Details" columns="2">
        <apex:inlineEditSupport event="ondblclick" showOnEdit="inlineEditSave,inlineEditCancel" hideOnEdit="deleteButton,editButton" resetFunction="resetInlineEdit"/>
            <apex:outputField id="cli02" value="{!Colin__c.Text02__c}"/>     <apex:outputField id="clc02" value="{!Colin__c.Checkbox02__c}"/>
            <apex:outputField id="cli03" value="{!Colin__c.Text03__c}"/>     <apex:outputField id="clc03" value="{!Colin__c.Checkbox03__c}"/>
            <apex:outputField id="cli04" value="{!Colin__c.Text04__c}"/>     <apex:outputField id="clc04" value="{!Colin__c.Checkbox04__c}"/>
            <apex:outputField id="clp01" value="{!Colin__c.Picklist01__c}"/> <apex:outputField id="clp02" value="{!Colin__c.Picklist02__c}"/>
        </apex:pageBlockSection>

    </apex:PageBlock>
    </apex:form>
</apex:page>

 

So if I double click on the text field, amend value, hit enter. The text turns orange and I get the undo icon as expected. But when I click Save, the value goes back to its OLD value!

 

If I double click on the text field, amend value, click Save (with the cursor still in the field), the value is updated.

 

 

Why does the way I amend the value affect whether the value saves or not?

It is not the behaviour of inline edit in standard page layouts.

 

Or am I coding my inline edit incorrectly? Can you see anything unusual?

 

Hi all,

 

I created an object called Locations that pulls data from another custom object called FNL.  I created a button on the Opportunity object that will allow a rep to lookup a given FNL location and create a Location item.  I currently have the following features working: The FNL search fields, the matching values based on the search and the existing Locations that are already associated to the Opportunity.

 

What I am having trouble with is being able to create checkboxes next to the matching values that are returned that will allow me to add them to the Opportunity.

 

public class LocationSearchController {

 public PageReference Cancel() {
        return null;
    }

        public Opportunity o { get; set; }
    Id myid= ApexPages.currentPage().getParameters().get('id');
    
    public PageReference ViewData() {

    return null;
    }
     
  // the soql without the order and limit
  private String soql {get;set;}
  // the collection of FNL to display
  public List<FNL__c> fnl {get;set;}
 
  // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
 
  // the current field to sort by. defaults to Name
  public String sortField {
    get  { if (sortField == null) {sortField = 'Name'; } 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 controller and display some sample data when the page loads
  public LocationSearchController() {
    soql = 'select Name, FNL_Suite__c, FNL_City__c, FNL_State__c, FNL_Zip__c, Building_Code__c from FNL__c where Name != null';
    runQuery();
   
    o = [select Id, Name, OwnerId, Account.Name, RecordType.Name, Existing_Order_Number__c, AboveNet_Order_Number__c, Quote_MRC_Total__c, 
                 Quote_NRC_Total__c, TechChange__c, Commencement_Date__c, PrepaymentAmount__c, ImplementationComments__c, BillingComments__c 
                 from Opportunity 
                 where id = :myid];     
  }
  
  public Opportunity getOpportunity() {
            return o;
  }
 
 
    //Our collection of the class/wrapper objects cLoctact 
    public List<cLocation> locationList {get; set;}

    //This method uses a simple SOQL query to return a List of Contacts
    public List<cLocation> getLocations() {
        if(locationList == null) {
            locationList = new List<cLocation>();
            for(Location__c c : [select Id, Street__c, City__c, State__c, zip__c, Entrances_Required__c, Location__c, Proposed_Demarc__c,
                            Country__c, FNL_Building_Code__c, Location_Type__c, Available_Entrance__c, Building_Fiber_Demarc__c, Name, 
                            Building_is_OnNet__c, Building_Type__c, Suite__c, FNL_Street__c from Location__c where Account__c = :o.AccountId]) {
                // As each contact is processed we create a new cLoctact object and add it to the contactList
                locationList.add(new cLocation(c));
            }
        }
        return locationList;
    }
   
     public PageReference processSelected() {

        //We create a new list of Locations that we be populated only with FNL if they are selected
        List<Location__c> selectedLocations = new List<Location__c>();

        //We will cycle through our list of cLocations and will check to see if the selected property is set to true, if it is we add the FNL to the selectedLocations list
        for(cLocation cLoc : getLocations()) {
            if(cLoc.selected == true) {
                selectedLocations.add(cLoc.loc);
            }
        }

        // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
        List <Location__c> newloc = new List<Location__c>();

        for(Location__c loc : selectedLocations) {
            
            Location__c nloc; 
            nloc = loc.clone(false);
            nloc.Opportunity__c = o.Id;
            nloc.Account__c = null;
            
            newloc.add(nloc);
        }
        
        insert newloc;
        return null;
    }

//Our collection of the class/wrapper objects cLocations 
    public List<dfnl> fnlList {get; set;}

    //This method uses a simple SOQL query to return a List of FNL
    public List<dfnl> getfnl() {
        if(fnlList == null) {
            fnlList = new List<dfnl>();
               for(FNL__c d : Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20') ) 
            {
                // As each contact is processed we create a new cFNL object and add it to the Location List
                fnlList.add(new dfnl(d));
             }
        }
        return fnlList;
    }
   
     public PageReference processSelectedf() {

        //We create a new list of Contacts that we be populated only with Contacts if they are selected
        List<FNL__c> selectedfnl = new List<FNL__c>();

        //We will cycle through our list of cLoctacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedLocations list
        for(dfnl dF : getfnl()) {
            if(dF.selected == true) {
                selectedfnl.add(dF.fnl2);
            }
        }

        // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
        List <Location__c> newloc1 = new List<Location__c>();

        for(FNL__c fnl : selectedfnl) {
            
            Location__c nloc1;
            nloc1.Access_Type__c = fnl.Access_Type__c;
            nloc1.Assets__c = fnl.Assets__c;
            nloc1.FNL_Building_Code__c = fnl.Building_Code__c;
            nloc1.Building_Fiber_Demarc__c = fnl.Building_Fiber_Demarc__c;
            nloc1.Building_Type__c = fnl.Building_Type__c;
            nloc1.Datacenter__c = fnl.Datacenter__c;
            nloc1.Entrances_Required__c = fnl.Entrance__c;
            nloc1.Street__c = fnl.FNL_Street__c;
            nloc1.Suite__c = fnl.FNL_Suite__c;
            nloc1.City__c = fnl.FNL_City__c;
            nloc1.State__c = fnl.FNL_State__c;
            nloc1.Zip__c = fnl.FNL_Zip__c;
            nloc1.Country__c = fnl.FNL_Country__c;
            nloc1.IP_POP__c = fnl.IP_POP__c;
            nloc1.IP_VPOP__c = fnl.IP_VPOP__c;
            nloc1.LH_POP__c = fnl.LH_POP__c;
            nloc1.LH_VPOP__c = fnl.LH_VPOP__c;
            nloc1.Opportunity__c = o.Id;
            nloc1.Account__c = null;
            
            newloc1.add(nloc1);
        }
        
        insert newloc1;
        return null;
    }


    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
    public class cLocation {
        public Location__c loc {get; set;}
        public Boolean selected {get; set;}

        //This is the contructor method. When we create a new cLoctact object we pass a Contact that is set to the con property. We also set the selected value to false
        public cLocation(Location__c c) {
            loc = c;
            selected = false;
         }
    }
     
      // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
    public class dFNL {
        public FNL__c fnl2 {get; set;}
        public Boolean selected {get; set;}

     //This is the contructor method. When we create a new cLoctact object we pass a Contact that is set to the con property. We also set the selected value to false
        public dFNL(FNL__c d) {
            fnl2 = d;
            selected = false;
         }
    }
  
     
  // 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 actual query
  public void runQuery() {
 
    try {
      fnl = 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 Name = Apexpages.currentPage().getParameters().get('Name');
    String fnlcity= Apexpages.currentPage().getParameters().get('fnlcity');
    String buildingcode= Apexpages.currentPage().getParameters().get('buildingcode');
 
    soql = 'select Name, FNL_Suite__c, FNL_City__c, FNL_State__c, FNL_Zip__c, Building_Code__c from FNL__c where Name != null';
    if (!Name.equals(''))
      soql += ' and Name LIKE \''+String.escapeSingleQuotes(Name)+'%\'';
    if (!fnlcity.equals(''))
      soql += ' and FNL_City__c LIKE \''+String.escapeSingleQuotes(fnlcity)+'%\'';
    if (!buildingcode.equals(''))
      soql += ' and Building_Code__c LIKE \''+String.escapeSingleQuotes(buildingcode)+'%\''; 
 
    // run the query again
    runQuery();

    return null;
  }
 

}

 

<apex:page controller="LocationSearchController" sidebar="false">
 
   <apex:form >
      <apex:pageBlock >
         <apex:pageBlockButtons >
            <apex:commandButton value="Add Selected Location to Opportunity" action="{!processSelected}" rerender="table" onclick="window.top.close()" oncomplete="javascript&colon;closeRefresh('{!Opportunity.Id}');"/>
            <apex:commandButton value="Cancel" action="{!Cancel}" rerender="table" onclick="window.top.close();"/>
         </apex:pageBlockButtons>
         <!-- In our table we are displaying the cContact records -->
         <apex:pageBlockTable value="{!locations}" var="c" id="table">
            <apex:column >
            <!-- This is our selected Boolean property in our wrapper class -->
             <apex:inputCheckbox value="{!c.selected}"/>
            </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                   <apex:column value="{!c.loc.Name}" />
                   <apex:column value="{!c.loc.Street__c}" />
                   <apex:column value="{!c.loc.City__c}" />
                   <apex:column value="{!c.loc.State__c}" />
         </apex:pageBlockTable>
      </apex:pageBlock>
   </apex:form>
    
   <apex:form >
      <apex:pageMessages id="errors" />
 
      <apex:pageBlock title="FNL Lookup" mode="edit">
         <table width="100%" border="0">
            <tr>  
               <td width="200" valign="top">
                  <apex:pageBlock title="Parameters" mode="edit" id="criteria">
                     <script type="text/javascript">
                        function doSearch() {
                        searchServer(
                        document.getElementById("Name").value,
                        document.getElementById("fnlcity").value,
                        document.getElementById("buildingcode").value);
                        } 
                     </script> 
 
                     <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
                        <apex:param name="Name" value="" />
                        <apex:param name="fnlcity" value="" />
                        <apex:param name="buildingcode" value="" />
                     </apex:actionFunction>
 
                     <table cellpadding="2" cellspacing="2">
                        <tr>
                           <td style="font-weight:bold;">Street<br/>
                              <input type="text" id="Name" onkeyup="doSearch();"/>
                           </td>
                        </tr>
                        <tr>
                           <td style="font-weight:bold;">City<br/>
                              <input type="text" id="fnlcity" onkeyup="doSearch();"/>
                           </td>
                        </tr>
                        <tr>
                           <td style="font-weight:bold;">Building Code<br/>
                              <input type="text" id="buildingcode" onkeyup="doSearch();"/>
                           </td>
                        </tr>
                     </table>
                  </apex:pageBlock>
               </td>
                 <td valign="top">
                    <apex:pageBlock mode="edit" id="results">
                    <!-- In our table we are displaying the cContact records -->
                       <apex:pageBlockTable value="{!fnl}" var="d" id="FNLtable">

                            <apex:column value="{!d.Name}" />
                            <apex:column value="{!d.FNL_Suite__c}" />
                            <apex:column value="{!d.FNL_City__c}" />
                            <apex:column value="{!d.FNL_State__c}" />
                            <apex:column value="{!d.FNL_Zip__c}" />
                            <apex:column value="{!d.Building_Code__c}" />
                       </apex:pageBlockTable>
                       <apex:pageBlockButtons >
                          <apex:commandButton value="Add Selected Location to Opportunity" action="{!processSelected}" rerender="table" onclick="window.top.close()" oncomplete="javascript&colon;closeRefresh('{!Opportunity.Id}');"/>
                       </apex:pageBlockButtons>
                    </apex:pageBlock>
                 </td>
            </tr>
         </table>
            <apex:pageBlock title="Debug - SOQL" id="debug">
               <apex:outputText value="{!debugSoql}" />           
            </apex:pageBlock>    
      </apex:pageBlock>
   </apex:form>
</apex:page>

 Any help would be appriciated.

 

Thanks.

Hi,

I'd like to put up a big screen in our sales department showing a dashboard. But in order for that to be of any interest, data has to be somewhat up-to-date.

My idea was to create a simple VisualForce Page which shows the dashboard and a small piece of JavaScript which clicks the Refresh button every hour.

However, I'm having problems getting the script to actually click the Refresh button. I could get it to work in a Home Page Component but showing the dashboard there isn't really an option.

Does anyone have anything similar running who would be interested in sharing their code?

Thanks.

Søren Nødskov Hansen

  • May 24, 2011
  • Like
  • 0

Hi,

 

I am getting a strange error when I am trying to display the colums in a datatable:

 

<apex:dataTable value="{!EmailAttachments}" var="ar

 <apex:dataTable value="{!EmailAttachments}" var="attach" columns="2" rendered="{!(attachments!=NULL)}" width="80%">
                <apex:column value="{!attach.Name}" headerValue="File Name" width="55px;"> 
                </apex:column>
                              <apex:column headerValue="Action" width="60px;">
                    <apex:commandLink Value="View" action="{!URLFOR($Action.Attachment.Download,attach.Id)}" target="_blank">
                        <apex:param name="attachment" value="{!attach.Id}" assignTo="{!attachmentId}"/>
                    </apex:commandLink>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
                    <apex:commandLink value="Remove" action="{!removeEmailAttachment}">                        
                        <apex:param name="attachment" value="{!attach.Id}" assignTo="{!emailaId}"/>
                    </apex:commandLink>
                </apex:column> 
            </apex:dataTable>  

 

 

and the controller method is:

 

 

  public List<Attachment> getEmailAttachments() {        
         //List<Attachment> attachment = 
         return [select Id, Name , BodyLength, CreatedById from Attachment where ParentId = :ApexPages.currentPage().getParameters().get('id') and Id in :emailattachId];        
         //return attachment;    
     }        
     
     public PageReference removeEmailAttachment(){        
         try{
             Attachment attach = [select Id, Name from attachment where id=:emailaId and ParentId = :ApexPages.currentPage().getParameters().get('id')];        
             delete attach;  
             return null;
         }catch(Exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage()));
            return null;  
         }         
     } 

 

I am getting this strange error since two days. Is this a bug? Can anyone help me with this issue.

 

 

  • May 23, 2011
  • Like
  • 0

I've created a really simple custom object (Colin__c) with a few text, picklist and checkbox fields. I've created a simple VF page with inline editing on the fields.

Now, depending on what I do between filling in a value in the field and clicking the Save button, it will affect whether the new value is saved or not.

 

 

<apex:page id="P1" standardController="Colin__c" >

    <apex:form id="F1" >
    <apex:sectionHeader title="{!Colin__c.Name}" />

    <apex:PageBlock id="PB1">
        <apex:pageMessages />

        <apex:pageBlockButtons id="PBB" location="both">
            <apex:commandButton id="inlineEditSave"   value="Save"   action="{!save}"   style="display:none"/>
            <apex:commandButton id="inlineEditCancel" value="Cancel" action="{!cancel}" style="display:none"/>
            <apex:commandButton id="editButton"       value="Edit"   action="{!edit}"/>
            <apex:commandButton id="deleteButton"     value="Delete" action="{!delete}" onclick="if ((Modal.confirm && Modal.confirm('Are you sure?')) || (!Modal.confirm && window.confirm('Are you sure?'))) {return true;} else {return false;}"/>
        </apex:pageBlockButtons>

        <apex:pageBlockSection id="PBS" title="Details" columns="2">
        <apex:inlineEditSupport event="ondblclick" showOnEdit="inlineEditSave,inlineEditCancel" hideOnEdit="deleteButton,editButton" resetFunction="resetInlineEdit"/>
            <apex:outputField id="cli02" value="{!Colin__c.Text02__c}"/>     <apex:outputField id="clc02" value="{!Colin__c.Checkbox02__c}"/>
            <apex:outputField id="cli03" value="{!Colin__c.Text03__c}"/>     <apex:outputField id="clc03" value="{!Colin__c.Checkbox03__c}"/>
            <apex:outputField id="cli04" value="{!Colin__c.Text04__c}"/>     <apex:outputField id="clc04" value="{!Colin__c.Checkbox04__c}"/>
            <apex:outputField id="clp01" value="{!Colin__c.Picklist01__c}"/> <apex:outputField id="clp02" value="{!Colin__c.Picklist02__c}"/>
        </apex:pageBlockSection>

    </apex:PageBlock>
    </apex:form>
</apex:page>

 

So if I double click on the text field, amend value, hit enter. The text turns orange and I get the undo icon as expected. But when I click Save, the value goes back to its OLD value!

 

If I double click on the text field, amend value, click Save (with the cursor still in the field), the value is updated.

 

 

Why does the way I amend the value affect whether the value saves or not?

It is not the behaviour of inline edit in standard page layouts.

 

Or am I coding my inline edit incorrectly? Can you see anything unusual?

 

Hi, I am trying to display and update fields for an my License_Verification__c Object 
with a lookup with Contacts.  I want to update and save in one shot, however my 
contact fields are not being updated on Save and not sure what I am missing, please help.
public with sharing class ConAcctVerificationInfoControllerExt {
   
    
private ApexPages.StandardController std;           

// Associated Licenses
public List<License_Verification__c> licenses;

// License Agency Contact
Contact LicenseAgencyContact;

public ConAcctVerificationInfoControllerExt(ApexPages.StandardController stdCtrl)
    {      
    std=stdCtrl;     
    }           
    
    public Account getAccount()     
    {      
        return (Account) std.getRecord();    
    }    
     

//----------------------------LICENSES METHOD--------------------------------------->
     
      public List<License_Verification__c> getlicenses()     
       {        
         if ( (null!=getAccount().id) && (licenses == null) )
              
       {            
        licenses=[SELECT Id, Account__r.ID, Account__c, LV_Agency_Contact__r.ID, LV_Agency_Contact__r.Company_Name__c,LV_Agency_Contact__r.Email, LV_Agency_Contact__r.Phone, LV_Agency_Contact__r.LastName,LV_Agency_Contact__r.FirstName, LV_Agency_Contact__r.Fax, LV_License_Type__c, LV_License_Number__c,LV_License_Expiration_Date__c                          
        FROM License_Verification__c                           
        WHERE Account__c = : getAccount().ID                          
        ORDER BY CreatedDate];
                       }                                    
        return licenses;   
       }       
     
public PageReference save()     
  {      
  Boolean result=true;      
  PageReference pr=Page.TestParentChild;      
  if (null!=getAccount().id)      
  {       
  result=updateContacts();     
   }      
    else     
  {       
   pr.setRedirect(true);      
  }             
  if (result)      
  {         
// call standard controller save, but don't capture the return value which will redirect to view page         
  update Principalcontact;
  update IDV;
  update licenses; // ONLY FIELDS ON PARENT OBJECT ARE BEING UPDATED ON SAVE                                                
   std.save();            
 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Changes saved'));      
 }         
pr.getParameters().put('id', getAccount().id);             
 return pr;     
 }  

 

 

<apex:page standardController="Account" extensions="ConAcctVerificationInfoControllerExt" title="Test Verification Info" >

<apex:pageMessages />     
<apex:form >         

<apex:pageBlock mode="mainDetail">             
<apex:pageBlockButtons location="top">                 
<apex:commandButton action="{!cancel}" value="Exit" />                 
<apex:commandButton action="{!save}" value="Save" />                 
</apex:pageBlockButtons> 

            
<apex:repeat value="{!licenses}" var="license" >                     

<apex:pageBlockSection columns="2"  title="License {!license.LV_License_Type__c}:{!license.LV_License_Number__c} Verification" collapsible="true">                         
                
<!--<apex:repeat value="{!$ObjectType.License_Verification__c.FieldSets.LV_Input_Info}" var="field">                      
<apex:inputField value="{!license[field]}" />                     
</apex:repeat>--> 
<apex:inputfield value="{!license.LV_Agency_Contact__r.ID}" /> 
<apex:inputfield value="{!license.Account__r.ID}" />
<apex:inputfield value="{!license.LV_License_Type__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.FirstName}" />
<apex:inputfield value="{!license.LV_License_Number__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.LastName}" />  
<apex:inputfield value="{!license.LV_License_Expiration_Date__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.Email}" />
<apex:inputfield value="{!license.LV_Agency_Contact__r.Company_Name__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.Phone}" />                       

<div style="text-align:center">                            
<apex:commandButton action="{!save}" value="Save" />
<!--<apex:commandButton action="{!AddNewLicense}" value="Add New" /> -->                            
</div>     
                                           
</apex:pageBlockSection>                        
               
</apex:repeat>             

 

  • May 23, 2011
  • Like
  • 0

Hi,

 

I have created a pageblock table and listed all transactions under a contact. In that transactions, For example there are 4 transactions for a single credit card number fora single contact.I need only the last transaction for that  credit card number.

 

For that, I want to remove the duplicates of credit card number. 

 

Here is my code:

 

Page:

 

 

<apex:page standardController="Contact" extensions="CreditTransactions">
<apex:form >
 <apex:pageBlock >
<apex:pageBlockTable value="{!trans}" var="transaction">
  <apex:column headerValue="Date Last Used" value="{!transaction.TransactionDate__c}"/> 
    <apex:column headerValue="Last 4 digits" value="{!transaction.CreditCard4x4__c}"/> 
    <apex:column headerValue="Expiration Date" value="{!transaction.CardExpiration__c}"/> 
    <apex:column headerValue="Card Type" value="{!transaction.Credit_Card_Name__c}"/> 
    <apex:column >
    <apex:commandButton action="{!VTerminal}" value="Virtual Terminal"/>
    </apex:column>
</apex:pageBlockTable>
  </apex:pageBlock>
  </apex:form>
 <apex:detail />
</apex:page>
Controller:
public with sharing class CreditTransactions {
public List<CnP_Transaction__c> trans{get;set;}
public List<CnP_Transaction__c> duplicates{get;set;}
 set<string> CreditOrderNumber=new set<string>();
 public String ContactId{get;set;}
    public CreditTransactions(ApexPages.StandardController controller) {
     
     ContactId = ApexPages.currentPage().getParameters().get('Id');
     List<CnP_Transaction__c> ToCreateCredits=[select Id, Name,CreditCard4x4__c, Contact__c from CnP_Transaction__c where Contact__c = :contactId];
 
         for(Integer i=0;i<ToCreateCredits.size();i++){
             CreditOrderNumber.add(ToCreateCredits[i].CreditCard4x4__c);
         }
         
  
         
     System.debug('Credit Order numberrrr'+CreditOrderNumber);
     trans = [select Id,Name,TransactionDate__c,Contact__c,Credit_Card_Name__c,CreditCard4x4__c,CardExpiration__c from CnP_Transaction__c where CreditCard4x4__c IN :CreditOrderNumber and Contact__c= :ContactId and CreditCard4x4__c!=null];
    }
    public CreditTransactions() {
     }
     public PageReference Vterminal() 
    {
     return Page.VirtualTerminal;
    }
}
I want  a list of records in the table which does not repeat any credit card number and if more transactions with the same credit card is there need to display the last transaction..
Can any one of you help me regarding this.
Anu

 

Hello -

 

I am trying to add a visualforce page to my custom object that will show the related products.

 

So my "Sales Checklist" object is housed on the opportunity, sales fills all the information out then the object is sent to a queue.

 

But to save time i want to pull in the opportunityLineItems in to the sales checklist?

 

Is this possable? I know very little visualforce.

 

This is as far as I have gotten:

 

<apex:page StandardController="Sales_Checklist__c">
<apex:relatedList list="Opportunity__r" />

<apex:pageBlock title="{!Sales_Checklist__c.Opportunity__r.Name}"/>

  <apex:dataTable value="{!Sales_Checklist__c.Opportunity__r}" var="opp" cellPadding="4" border="1">
                
           <apex:column ><apex:facet name="header">Product Name</apex:facet></apex:column>
                
                
           <apex:column><apex:facet name="header">Quantity</apex:facet></apex:column>
                
                
           <apex:column ><apex:facet name="header">Unit Price</apex:facet></apex:column>
                
              
           <apex:column ><apex:facet name="header">Total Price</apex:facet></apex:column>
  </apex:dataTable>
</apex:page>

 

 

any help would be greatlt appriciated

 

Thanks,

Niki

Hi,

 

I need to route a user's request depending on the content of a field either to the standard Editpage (or Detailpage), something like the recordType.

 

In other words: In Accounts, when I click the "Edit" button, it should look into the field "isNewDesign" and depending on that content guide me either to a VF page or the standard Account editpage.

 

I tried to overwrite the standard button and route that to a VF page which stays, or if I need the standard Editor, call the URL '/accountid/e'. But that takes me to the overwritten button and thus to my VF page again.

 

Any idea, how I could call the editor of Accounts other than the URL "/accountid/e"?

  • April 21, 2011
  • Like
  • 0

When developing a Visualforce page for overiding view page for any object, one problem that creeps up is to display the History details of a record. The standard related list Component doesn't works for History.

 

With the help of some code from Community ( I now can't find the link to it :( ), I wrote my own code  then to display the history of an object. It mimics the standard list as far as possible.  

 

Heres the code. It is for the Case object but it can be used for any other object.

 1.Component Code

 

<apex:component controller="CaseHistoriesComponentController">
<!-- Attribute Definition -->
<apex:attribute name="CaseId" description="Salesforce Id of the Case whose Case History needs to be rendered" type="Id" required="true" assignTo="{!caseId}" />

<!-- Case History Related List -->
<apex:pageBlock title="Case History">
<apex:pageBlockTable value="{!histories}" var="History" >
<apex:column headerValue="Date" value="{!History.thedate}"/>
<apex:column headerValue="User"> <apex:outputLink value="/{!History.userId}"> {!History.who} </apex:outputLink></apex:column>
<apex:column headerValue="Action"><apex:outputText escape="false" value="{!History.action}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:component>

 

 

 

 

2. Apex Code

 

public class CaseHistoriesComponentController {

public Id caseId {get; set;}
public cHistories[] histories;

// Variables
public Static final Map<String, Schema.SObjectField> CaseFieldmap = Schema.SObjectType.Case.fields.getMap();
public Static final List<Schema.PicklistEntry> fieldPicklistValues = CaseHistory.Field.getDescribe().getPicklistValues();

public List<cHistories> getHistories()
{
list<cHistories> histories = new list<cHistories>();
String prevDate = '';
for(CaseHistory cHistory : [Select CreatedDate, CreatedBy.Name, CreatedBy.Id, Field, NewValue, OldValue from CaseHistory where CaseId = :caseId order by CreatedDate desc])
{
if((cHistory.newValue == null && cHistory.oldValue == null)
|| (cHistory.newValue != null && !(string.valueOf(cHistory.newValue).startsWith('005') || string.valueOf(cHistory.newValue).startsWith('00G')))
|| (cHistory.oldValue != null && !(string.valueOf(cHistory.oldValue).startsWith('005') || string.valueOf(cHistory.oldValue).startsWith('00G'))))
{
cHistories tempHistory = new cHistories();
// Set the Date and who performed the action
if(String.valueOf(cHistory.CreatedDate) != prevDate)
{
tempHistory.theDate = String.valueOf(cHistory.CreatedDate);
tempHistory.who = cHistory.CreatedBy.Name;
tempHistory.userId = cHistory.CreatedBy.Id;
}
else
{
tempHistory.theDate = '';
tempHistory.who = '';
tempHistory.userId = cHistory.CreatedBy.Id;
}
prevDate = String.valueOf(cHistory.CreatedDate);

// Get the field label
String fieldLabel = CaseHistoriesComponentController.returnFieldLabel(String.valueOf(cHistory.Field));

// Set the Action value
if (String.valueOf(cHistory.Field) == 'created') { // on Creation
tempHistory.action = 'Created.';
}
else if(cHistory.OldValue != null && cHistory.NewValue == null){ // when deleting a value from a field
// Format the Date and if there's an error, catch it and re
try {
tempHistory.action = 'Deleted ' + Date.valueOf(cHistory.OldValue).format() + ' in <b>' + fieldLabel + '</b>.';
} catch (Exception e){
tempHistory.action = 'Deleted ' + String.valueOf(cHistory.OldValue) + ' in <b>' + fieldLabel + '</b>.';
}
}
else{ // all other scenarios
String fromText = '';
if (cHistory.OldValue != null) {
try {
fromText = ' from ' + Date.valueOf(cHistory.OldValue).format();
} catch (Exception e) {
fromText = ' from ' + String.valueOf(cHistory.OldValue);
}
}

String toText = '';
if (cHistory.OldValue != null) {
try {
toText = Date.valueOf(cHistory.NewValue).format();
} catch (Exception e) {
toText = String.valueOf(cHistory.NewValue);
}
}
if(toText != '')
tempHistory.action = 'Changed <b>' + fieldLabel + '</b>' + fromText + ' to <b>' + toText + '</b>.';
else
tempHistory.action = 'Changed <b>' + fieldLabel;
}

// Add to the list
histories.add(tempHistory);
}
}

return histories;
}

// Function to return Field Label of a Case field given a Field API name
public Static String returnFieldLabel(String fieldName)
{
if(CaseHistoriesComponentController.CaseFieldmap.containsKey(fieldName))
return CaseHistoriesComponentController.CaseFieldmap.get(fieldName).getDescribe().getLabel();
else
{
for(Schema.PicklistEntry pickList : fieldPicklistValues)
{
if(pickList.getValue() == fieldName)
{
if(pickList.getLabel() != null)
return pickList.getLabel();
else
return pickList.getValue();
}
}
}
return '';
}
// Inner Class to store the detail of the case histories
public class cHistories {

public String theDate {get; set;}
public String who {get; set;}
public Id userId {get; set;}
public String action {get; set;}
}
}

  Let me know your views on the code or if you have any questions