function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PipPip 

Update Class and Page

I want to update the class and vforce page for something that was already created for my organization. I want to mimic it to keep everything similar and it was made by a 3rd party developer who decided to stop consulting. Here is the new object and fields i want to replace the existing with. It seems that the class and page is complex for a simple add and remove fields. Simply replace everywhere audienceunitlineitem. Any help would be great.

 

New Object -

Audience_Direct__c

 

New Fields

Segment_ID__c Segment_Name__c Data_Provider__c Uniques__c Impression_s__c CPMU__c CPM__c Total_Value__c

 

Class

}

public with sharing class adUnitLineItemExtension 
{  
  private final Publisher_Site__c   p;
  ApexPages.StandardController     stdController;
  
  public Publisher_Site__c      publisher      { get; set; }
  public List<AUWrapper>         adUnitLines     { get; set; }
  public String            focusedLi      { get; set; }
  public Integer            wrapperID      { get; set; }
  public Boolean            saveError      { get; set; }
  public String            errorMessage    { get; set; }
  
  //Extension Constructor
  public adUnitLineItemExtension(ApexPages.StandardController stdCont)
  {
    stdController     = stdCont;
    p          = (Publisher_Site__c)stdController.getRecord();
    publisher      = [SELECT Id, Publisher_Tier__c, Name, Geo_Target__c from Publisher_Site__c where Id = :p.Id LIMIT 1];
    adUnitLines     = new List<AUWrapper>{};
    focusedLi      = '';
    wrapperID      = 0;
    saveError      = false;
    errorMessage    = 'You must set an Ad Size, an Ad Position, and one or more Geotargets before you may save an Ad Unit!';
    
    if (publisher != null)
    {
      List<Ad_Unit__c> auLis = [SELECT Id, 
                       Name,
                       Unit_Name__c,
                       Ad_Size__c, 
                       Ad_Positioning__c,
                       Geotarget__c,
                       Publisher_Site__c
                    from    Ad_Unit__c
                    where  Publisher_Site__c = :publisher.Id 
                    LIMIT  1000];
      
      for(Ad_Unit__c l : auLis)
      {
        AUWrapper wrapper = new AUWrapper(wrapperID++);
        
        wrapper.adUnit   = l;
        wrapper.isNew  = false;
        
        adUnitLines.add(wrapper);
      }
    }
  }
  
  public void addLine()
  {
    AUWrapper wrapper = new AUWrapper(wrapperID++);
    
    wrapper.adUnit.Publisher_Site__c   = p.Id;
    focusedLi               = wrapper.wrapperID;
    saveError              = false;
        
    adUnitLines.add(wrapper);
  }
  
  public void removeLine()
  {
    for(Integer i = 0; i < adUnitLines.size(); i++)
    {
      if (adUnitLines[i].wrapperID == System.currentPageReference().getParameters().get('selectedID'))
      {  
        if (adUnitLines[i].isNew == false)
        {
          delete adUnitLines[i].adUnit;
        }
        
        adUnitLines.remove(i);
        
        focusedLi = '';
        saveError = false;
        
        break;
      }
    }
  }
  
  public void saveLine()
  {
    for(Integer i = 0; i < adUnitLines.size(); i++)
    {
      if (adUnitLines[i].wrapperID == System.currentPageReference().getParameters().get('selectedID'))
      {  
        if(adUnitLines[i].isNew == false)
        {
          saveError =  ((adUnitLines[i].adUnit.Ad_Size__c == '')       ||
                    (adUnitLines[i].adUnit.Ad_Size__c == null)      ||
                    (adUnitLines[i].adUnit.Ad_Positioning__c == '')   ||
                    (adUnitLines[i].adUnit.Ad_Positioning__c == null)  ||
                    (adUnitLines[i].adUnit.Geotarget__c == '')      ||
                    (adUnitLines[i].adUnit.Geotarget__c == null));
          
          if(!saveError)
          {
            update adUnitLines[i].adUnit;
          }
        }
        else
        {          
          saveError = ((adUnitLines[i].adUnit.Ad_Size__c == '')       ||
                    (adUnitLines[i].adUnit.Ad_Size__c == null)      ||
                    (adUnitLines[i].adUnit.Ad_Positioning__c == '')   ||
                    (adUnitLines[i].adUnit.Ad_Positioning__c == null)  ||
                    (adUnitLines[i].adUnit.Geotarget__c == '')      ||
                    (adUnitLines[i].adUnit.Geotarget__c == null));
          
          if(!saveError)
          {
            insert adUnitLines[i].adUnit;
            
            Ad_Unit__c au =  [SELECT  Id, 
                        Name,
                        Unit_Name__c,
                        Ad_Size__c, 
                        Ad_Positioning__c,
                        Geotarget__c,
                        Publisher_Site__c
                     from   Ad_Unit__c
                     where  Id = :adUnitLines[i].adUnit.Id
                     LIMIT  1];
                     
            if(au != null)
            {
              adUnitLines[i].adUnit   = au;
              adUnitLines[i].isNew  = false;
            }
          }
        }
        
        focusedLi = '';
        
        break;
      }
    }
  }
  
  public void editLine()
  {
    focusedLi = System.currentPageReference().getParameters().get('selectedID');
  }

 

Page

 

</apex:page>

<apex:page standardController="Publisher_Site__c" extensions="adUnitLineItemExtension">

<apex:detail relatedList="false" >

<apex:form >	
	<apex:pageBlock id="adUnitLineItems" title="Publisher Ad Units">
	
		<apex:outputPanel style="color: red; text-aline: center" id="messages">
			<apex:outputPanel style="color: red; text-align: center" id="errorMessage" rendered="{!saveError}">
				{!errorMessage}
			</apex:outputPanel>
		</apex:outputPanel>
		
		<apex:pageBlockButtons location="top">
         	  <apex:commandButton action="{!addLine}" value="Add Ad Unit" rerender="auLines,messages" status="adding" />
         	  <span style = "color: green">
         	  	<apex:actionStatus id="adding" startText="Adding..." />
         	  </span>
         	  <span style = "color: blue">
         	  	<apex:actionStatus id="saving" startText="Saving..." />
         	  </span>
			  <span style = "color: red">
			  	<apex:actionStatus id="deleting" startText="Deleting..." />
			  </span>
			  <span style = "color: blue">
			  	<apex:actionStatus id="editing" startText="Loading..." />
			  </span>
        </apex:pageBlockButtons>
		<apex:pageBlockSection columns="1">
			<apex:pageBlockSectionItem >
				<apex:pageBlockTable id="auLines" value="{!adUnitLines}" var="auLi">
					 <apex:column headervalue="Action">
					     <apex:commandLink rendered="{!IF(auLi.wrapperID != focusedLi, true, false)}" value="Edit" action="{!editLine}" rerender="auLines,messages" status="editing">
					     	 <apex:param name="selectedID" value="{!auLi.wrapperID}" />
					     </apex:commandLink>
					     <apex:commandLink rendered="{!IF(auLi.wrapperID == focusedLi, true, false)}" value="Save" action="{!saveLine}" rerender="auLines,messages" status="saving">
					     	 <apex:param name="selectedID" value="{!auLi.wrapperID}" />
						</apex:commandLink>
						|&nbsp;
						<apex:commandLink value="Del" action="{!removeLine}" rerender="auLines,messages" status="deleting">
							 <apex:param name="selectedID" value="{!auLi.wrapperID}" />
						</apex:commandLink>
					 </apex:column>
					 <apex:column headervalue="Name">
					 	<apex:outputField rendered="{!IF(auLi.wrapperID != focusedLi, true, false)}" value="{!auLi.adUnit.Unit_Name__c}" />
						<apex:inputField rendered="{!IF(auLi.wrapperID == focusedLi, true, false)}" value="{!auLi.adUnit.Unit_Name__c}" />
					 </apex:column>
					 <apex:column headervalue="Size">
						<apex:outputField rendered="{!IF(auLi.wrapperID != focusedLi, true, false)}" value="{!auLi.adUnit.Ad_Size__c}" />
						<apex:inputField rendered="{!IF(auLi.wrapperID == focusedLi, true, false)}" value="{!auLi.adUnit.Ad_Size__c}" />
					 </apex:column>
					 <apex:column headervalue="Positioning">
						<apex:outputField rendered="{!IF(auLi.wrapperID != focusedLi, true, false)}" value="{!auLi.adUnit.Ad_Positioning__c}" />
						<apex:inputField rendered="{!IF(auLi.wrapperID == focusedLi, true, false)}" value="{!auLi.adUnit.Ad_Positioning__c}" />
					 </apex:column>
					 <apex:column headervalue="Geotarget">
						<apex:outputField rendered="{!IF(auLi.wrapperID != focusedLi, true, false)}" value="{!auLi.adUnit.Geotarget__c}" />
						<apex:inputField rendered="{!IF(auLi.wrapperID == focusedLi, true, false)}" value="{!auLi.adUnit.Geotarget__c}" />
					 </apex:column>
				</apex:pageBlockTable>
			</apex:pageBlockSectionItem>
		</apex:pageBlockSection>
	</apex:pageBlock>
</apex:form>

<apex:relatedList list="Cases__r" subject="{!Publisher_Site__c}" />
<apex:relatedList list="OpenActivities" subject="{!Publisher_Site__c}" />
<apex:relatedList list="ActivityHistories" subject="{!Publisher_Site__c}" />
<apex:relatedList list="NotesAndAttachments" subject="{!Publisher_Site__c}" />

<apex:pageBlock id="thePageBlock" title="Publisher Site Field History">  
            <apex:pageBlockTable value="{!Publisher_Site__c.Histories}" var="h">
                <apex:column headerValue="Date" >
                	<apex:outputText value="{0,date,MM/dd/yyyy HH:mm }">       
						<apex:param value="{!h.createddate}" />
					</apex:outputText>  
                </apex:column>
                <apex:column headerValue="What">{!h.field}</apex:column>
                <apex:column headerValue="From">{!h.oldvalue}</apex:column>
                <apex:column headerValue="To">{!h.newvalue}</apex:column>
                <apex:column headerValue="User">{!h.createdby.name}</apex:column>
            </apex:pageBlockTable>
</apex:pageBlock>       


</apex:detail>
 
LakshmanLakshman

It seems that you want to update the the class with your new object Audience_Direct__c instead of Publisher_Site__c, am I right?

 

Also there is another class AUWrapper, which you havent specified in the code, let me know this class so that I can update your code.

 

Regards,
Lakshman

PipPip

Thanks so much for replying!! I didnt even know AUwrapper was associated with this page.

 

I really just need it to be updated with the object Audience Direct and make those fields editable and edit/add like an opportunitylineitem. 

 

Instead of being an adunitlineitem it would be an audiencedirectlineitem. 

 

Here is the AUWrapper

 



1
2
3
4
5
6
7
8
9
10
11
12
13
public with sharing class AUWrapper 
{
  public String        wrapperID    {get; set;}
  public Ad_Unit__c       adUnit      {get; set;}
  public Boolean        isNew      {get; set;}
  
  public AUWrapper(Integer id)
  {
    wrapperID   = '' + id;
    adUnit    = new Ad_Unit__c();
    isNew    = true;
  }
}
PipPip

I would need help updating the class and the visualforce page. Would there be an easier way to create and keep it in the same format of what was already created? :smileyhappy:

LakshmanLakshman

Yes, there is a way. Give me some time, I am updating the class and page.

 

Regards,
Lakshman

sunny.dale5sunny.dale5

I would like to update my page and class to! its seems too plain..

PipPip

Hi Lakshman,

 

Do you think I should start from scratch and not update the class/page that was already created for another object?

LakshmanLakshman

We need to create a new one.

 

Regards,

Lakshman

sunny.dale5sunny.dale5

@pip: yes i agree with Lakshman! you have to start with scratch ..