• Ashley@WCEL
  • NEWBIE
  • 35 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 10
    Replies

Hello all.

 

I have an interface class called ReceiptBatch with two implementations: ReceiptBatch_charitable and ReceiptBatch_convertExisting. Most of the time I will use _charitable.  _convertExisting is a temporary implementation which will be used only by the admin (me) for a very short period of time to convert existing records to the new format.

 

I am trying to create a way to stealthily change the implementation used when accessing the visualforce page. My current attempt is to pass a URL query parameter when accessing the page, as in /apex/ReceiptBatch?rtype=convert. If that parameter exists in the URL then the controller extension will instantiate the _convertExisting implementation, otherwise it will default to the _charitable implementation.

 

Here's a summary of my current logic.

 

  1. The visualforce page uses StandardSetController to select a list of Opportunities for processing
  2. In the controller extension's constructor, check for the querystring parameter. If it exists, assign to a public variable which is bound to a hidden field on the form to maintain the parameter between page posts
  3. If the hidden field contains a value, then use that to instatiate the appropriate implementation, otherwise instantiate the default

Using the logs, I have verified that the parameter is being read from the query string and saved to the hidden field but it doesn't carry through to the final form submission and the processing is always completed using the default implementation. How can I get that parameter to persist to the final form submission? Any help is greatly appreciated.

 

Here's the code. I have underlined the parts most relevant to this question.

 

Visualforce Page:

<apex:page standardController="Opportunity" extensions="ReceiptBatch_controller" recordSetVar="opportunities" action="{!validateOpps}">
    
    <apex:form >
        <apex:pageBlock rendered="{!cleanOpps.size > 0}">
            <p style="background-color:green;color:white;padding:3px;"><b>Receipts may be generated for the following opportunities</b></p><br/>
            <apex:pageBlockTable value="{!cleanOpps}" var="c" id="cleanList">
                <apex:column value="{!c.CharitableReceipt__c}"/>
                <apex:column value="{!c.Account.Name}"/>
                <apex:column value="{!c.Name}"/>
                <apex:column value="{!c.Amount}"/>
                <apex:column value="{!c.CloseDate}"/>
                <apex:column value="{!c.IsWon}"/>
            </apex:pageBlockTable>

            Address the receipt to: 
            <apex:selectList multiselect="false" size="1" value="{!addresseeType}">
                <apex:selectOptions value="{!addresseeTypeList}"></apex:selectOptions>
            </apex:selectList>
            <apex:inputHidden value="{!ReceiptType}"/>
            <apex:commandButton action="{!issueNew}" value="Yes, create receipts for these opportunities"/>
        </apex:pageBlock>
</apex:form>
    
    <apex:pageBlock rendered="{!dirtyOpps.size > 0}">
        <p style="background-color:red;color:white;padding:3px;"><b>The following opportunities are invalid because:</b> {!ValidationMessage}<br/>
        You may correct any errors and rebuild your selection below</p><br/>
        
        <apex:pageBlockTable value="{!dirtyOpps}" var="d" id="dirtyList">
            <apex:column value="{!d.CharitableReceipt__c}"/>
            <apex:column value="{!d.Account.Name}"/>
            <apex:column value="{!d.Name}"/>
            <apex:column value="{!d.Amount}"/>
            <apex:column value="{!d.CloseDate}"/>
            <apex:column value="{!d.IsWon}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>   

    <apex:pageBlock >
        <apex:listViews type="Opportunity"/>
    </apex:pageBlock>  
    
</apex:page>

 

Controller Extension:

public with sharing class ReceiptBatch_controller{
    
    private ApexPages.StandardSetController itsStandardSetController;
    private List<Opportunity> itsSelectedOpps;
    private List<Opportunity> itsCleanOpps;
    private List<Opportunity> itsDirtyOpps;
    private List<CharitableReceipt__c> itsNewReceipts;
    private String itsValidationMessage;
    private ReceiptBatch_interface rbatch;

    public String receiptType{get;set;}
    public String addresseeType{get;set;}
    
    public List<SelectOption> addresseeTypeList{
        get{
            List<SelectOption> a = new List<SelectOption>();
            a.add(new SelectOption('Account','Account'));
            a.add(new SelectOption('Contact','Contact'));
            a.add(new SelectOption('Household','Household'));
            return a;
        }
    }
    
    public List<Opportunity> cleanOpps{
        get{return itsCleanOpps;}
        private set;
    }
    
    public List<Opportunity> dirtyOpps{
        get{return itsDirtyOpps;}
        private set;
    }  
    
    public String validationMessage{
        get{return itsValidationMessage;}
        private set;
    }
    
    public List<CharitableReceipt__c> newReceipts{
        get{return itsNewReceipts;}
        private set;
    }
    
    public ReceiptBatch_controller(ApexPages.StandardSetController sC){
        itsStandardSetController = sC;
        
        if (ApexPages.currentPage().getParameters().get('rtype') != null){
            receiptType = ApexPages.currentPage().getParameters().get('rtype');
        }
        
        if(receiptType == 'convert'){
rbatch = new ReceiptBatch_convertExisting();
} else if(receiptType == 'charitable'){ rbatch = new Receiptbatch_charitable(); } else { rbatch = new Receiptbatch_charitable(); } } public void validateOpps(){ itsSelectedOpps = itsStandardSetController.getSelected(); rbatch.setOpportunities(itsSelectedOpps); itsCleanOpps = rbatch.getCleanOpportunities(); itsDirtyOpps = rbatch.getDirtyOpportunities(); itsValidationMessage = rbatch.getValidationMessage(); } public void issueNew(){ rbatch.setAddresseeType(addresseeType); rbatch.issueReceipts(); itsNewReceipts = rbatch.getNewReceipts(); } }

 

 

 

Hello all. First time poster here who has relied heavily on these forums to learn Apex. Thank you!

 

Here's a problem that I hope might generate some discussion.

 

My goal was to take a list of Opportunities and group them by Account, not using a group by clause, rather, creating a list of lists such that each sublist contains opportunities for a unique AccountID. Given a list of opportunities (Opp1...Opp5), the end result should look something like this:

 

AccountA:

   Opp1

   Opp2

AccountB:

   Opp2

   Opp3

   Opp4

AccountC:

   Opp5

 

My first attempted solution is as follows where opps is passed as the function parameter. I had hoped this would return a list of Accounts with the relevant Opportunities in the relationship, but it did not work. The Account list is created as expected but the Opportunities relationship is empty.

 

 

Set<Id> addressees = new Set<Id>();
for(Opportunity o:opps){
  addressees.add(o.Id);
}
List<Account> a = [Select Id, Name, (Select Id, Name, Amount, CloseDate, IsWon, CharitableReceipt__c From Account.Opportunities Where Opportunity.Id in:opps) From Account where Id in :addressees];
return a;

 

 

In the end, I solved the problem using a for loop but it is not as elegant as a single SOQL statement. I'm curious if my original solution is workable.

 

public List<List<Opportunity>> groupOpportunities(List<Opportunity> opps){
        
Set<Id> accts = new Set<Id>();
List<List<Opportunity>> groupedOpps = new List<List<Opportunity>>();
        
//create an account control sets
for(Opportunity o:opps){
   accts.add(o.AccountId);
}
        
//add a new opp list for each account in the control set
for(Id i:accts){
   List<Opportunity> tempOpps = new List<Opportunity>();
   for(Opportunity o:opps){
      if (o.AccountId == i){tempOpps.add(o);}
   }
   groupedOpps.add(tempOpps);
}
        
return groupedOpps;

}

 

Hi,

 

First of all I have no Apex experience at all, and up until now havent needed any, so be kind! I have my sandbox built and have done some reading up on Apex language (last time I programmed  was PASCAL at college!)

 

I need to populate a custom lookup field on our Lead object based on it referencing a field on a custom object. As Leads can't be a child of a master-Child relationship, I've now realised the only way to do this will be an Apex trigger.

 

I've created a relationship between the Lead and custom object and now need the lookup field (CCLookup) on the Lead to use the value from Campaign Code (also on Lead) look up the value of the Field 'Campaign Code_CC' on my custom object and return the value of the custom object Name:

 

Campaign code on Lead: 1234

Campaign Code on custom Object: 1234

Name ID of Custom object: Campaign 1234

Lookup up field returns value of: Campaign1234

 

If no campaign code that matches exists on the custom object, the lookup field can remain blank.

 

Anyone willing to help!?

 

Antony

 

 

Hello all.

 

I have an interface class called ReceiptBatch with two implementations: ReceiptBatch_charitable and ReceiptBatch_convertExisting. Most of the time I will use _charitable.  _convertExisting is a temporary implementation which will be used only by the admin (me) for a very short period of time to convert existing records to the new format.

 

I am trying to create a way to stealthily change the implementation used when accessing the visualforce page. My current attempt is to pass a URL query parameter when accessing the page, as in /apex/ReceiptBatch?rtype=convert. If that parameter exists in the URL then the controller extension will instantiate the _convertExisting implementation, otherwise it will default to the _charitable implementation.

 

Here's a summary of my current logic.

 

  1. The visualforce page uses StandardSetController to select a list of Opportunities for processing
  2. In the controller extension's constructor, check for the querystring parameter. If it exists, assign to a public variable which is bound to a hidden field on the form to maintain the parameter between page posts
  3. If the hidden field contains a value, then use that to instatiate the appropriate implementation, otherwise instantiate the default

Using the logs, I have verified that the parameter is being read from the query string and saved to the hidden field but it doesn't carry through to the final form submission and the processing is always completed using the default implementation. How can I get that parameter to persist to the final form submission? Any help is greatly appreciated.

 

Here's the code. I have underlined the parts most relevant to this question.

 

Visualforce Page:

<apex:page standardController="Opportunity" extensions="ReceiptBatch_controller" recordSetVar="opportunities" action="{!validateOpps}">
    
    <apex:form >
        <apex:pageBlock rendered="{!cleanOpps.size > 0}">
            <p style="background-color:green;color:white;padding:3px;"><b>Receipts may be generated for the following opportunities</b></p><br/>
            <apex:pageBlockTable value="{!cleanOpps}" var="c" id="cleanList">
                <apex:column value="{!c.CharitableReceipt__c}"/>
                <apex:column value="{!c.Account.Name}"/>
                <apex:column value="{!c.Name}"/>
                <apex:column value="{!c.Amount}"/>
                <apex:column value="{!c.CloseDate}"/>
                <apex:column value="{!c.IsWon}"/>
            </apex:pageBlockTable>

            Address the receipt to: 
            <apex:selectList multiselect="false" size="1" value="{!addresseeType}">
                <apex:selectOptions value="{!addresseeTypeList}"></apex:selectOptions>
            </apex:selectList>
            <apex:inputHidden value="{!ReceiptType}"/>
            <apex:commandButton action="{!issueNew}" value="Yes, create receipts for these opportunities"/>
        </apex:pageBlock>
</apex:form>
    
    <apex:pageBlock rendered="{!dirtyOpps.size > 0}">
        <p style="background-color:red;color:white;padding:3px;"><b>The following opportunities are invalid because:</b> {!ValidationMessage}<br/>
        You may correct any errors and rebuild your selection below</p><br/>
        
        <apex:pageBlockTable value="{!dirtyOpps}" var="d" id="dirtyList">
            <apex:column value="{!d.CharitableReceipt__c}"/>
            <apex:column value="{!d.Account.Name}"/>
            <apex:column value="{!d.Name}"/>
            <apex:column value="{!d.Amount}"/>
            <apex:column value="{!d.CloseDate}"/>
            <apex:column value="{!d.IsWon}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>   

    <apex:pageBlock >
        <apex:listViews type="Opportunity"/>
    </apex:pageBlock>  
    
</apex:page>

 

Controller Extension:

public with sharing class ReceiptBatch_controller{
    
    private ApexPages.StandardSetController itsStandardSetController;
    private List<Opportunity> itsSelectedOpps;
    private List<Opportunity> itsCleanOpps;
    private List<Opportunity> itsDirtyOpps;
    private List<CharitableReceipt__c> itsNewReceipts;
    private String itsValidationMessage;
    private ReceiptBatch_interface rbatch;

    public String receiptType{get;set;}
    public String addresseeType{get;set;}
    
    public List<SelectOption> addresseeTypeList{
        get{
            List<SelectOption> a = new List<SelectOption>();
            a.add(new SelectOption('Account','Account'));
            a.add(new SelectOption('Contact','Contact'));
            a.add(new SelectOption('Household','Household'));
            return a;
        }
    }
    
    public List<Opportunity> cleanOpps{
        get{return itsCleanOpps;}
        private set;
    }
    
    public List<Opportunity> dirtyOpps{
        get{return itsDirtyOpps;}
        private set;
    }  
    
    public String validationMessage{
        get{return itsValidationMessage;}
        private set;
    }
    
    public List<CharitableReceipt__c> newReceipts{
        get{return itsNewReceipts;}
        private set;
    }
    
    public ReceiptBatch_controller(ApexPages.StandardSetController sC){
        itsStandardSetController = sC;
        
        if (ApexPages.currentPage().getParameters().get('rtype') != null){
            receiptType = ApexPages.currentPage().getParameters().get('rtype');
        }
        
        if(receiptType == 'convert'){
rbatch = new ReceiptBatch_convertExisting();
} else if(receiptType == 'charitable'){ rbatch = new Receiptbatch_charitable(); } else { rbatch = new Receiptbatch_charitable(); } } public void validateOpps(){ itsSelectedOpps = itsStandardSetController.getSelected(); rbatch.setOpportunities(itsSelectedOpps); itsCleanOpps = rbatch.getCleanOpportunities(); itsDirtyOpps = rbatch.getDirtyOpportunities(); itsValidationMessage = rbatch.getValidationMessage(); } public void issueNew(){ rbatch.setAddresseeType(addresseeType); rbatch.issueReceipts(); itsNewReceipts = rbatch.getNewReceipts(); } }

 

 

 

Because of particular integration I have to leave certain line items out of the quote based on a checkbox. Because of this I can't use the default quote templates unless anyone else knows how to exclude quotelineitems from a quote. What I did was model it after Jeff Douglas attaching a pdf to an object. I have a custom button called 'Create PDF'.  The button goes to the VF page below. On it is a commandlink which references the viewPDF method in the QuoteConsultingExtension to view the PDF before saving. This works great and I can view the PDF no problem with all the quote fields.

However when I click the savePDF button. I get "SObject row was retrieved via SOQL without querying the requested field:" on all the quote standard fields. I even tried to write my own SOQL query which references all the default quote fields and it then throws an error SObject row was retrieved via SOQL without querying the requested field: User.LastName when I'm not even referencing User.LastName on my VF page.  This is crazy?? Can anyone help me with this or provide a better solution?

 

Thanks heaps

 

Dahveed

 

<apex:page standardController="Quote" showHeader="true"  extensions="QuoteConsultingExtension" >
  <apex:sectionHeader title="Create and attach a quote for signing" subtitle="Attach a PDF" 
    description="You must attach a PDF quote for use with docusign"/>
  <apex:form >
    <apex:pageBlock title="PDF Input">
 
      <apex:pageBlockButtons >
      <apex:commandLink  action="{!viewPDF}" value="View PDF" target="_blank" />
      <apex:commandButton action="{!savePDF}" value="Save"/>
      <apex:commandButton action="{!Cancel}" value="Cancel"/>
      </apex:pageBlockButtons>
      <apex:pageMessages />
 
      <apex:pageBlockSection >
 
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="File Name" for="pdfName"/>
   <!--       <apex:inputText value="{!pdfName}" id="pdfName"/> -->
        </apex:pageBlockSectionItem>
 
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Account ID" for="id"/>
  <!--        <apex:inputText value="{!parentId}" id="id"/> -->
        </apex:pageBlockSectionItem>
 
      </apex:pageBlockSection>
 
    </apex:pageBlock>
  </apex:form>

 

public class QuoteConsultingExtension {
    
    private List<QuoteLineItem> conLineItems;
    private decimal conTotal;
    public final Quote myQuote;
   
    
    public QuoteConsultingExtension(ApexPages.StandardController stdController) {
        this.myQuote = (Quote)stdController.getRecord();

    }

    
    public List<QuoteLineItem> consultingLineItems{
        get{
            if(conLineItems == null)
                conLineItems = new List<QuoteLineItem>();
            
            conLineItems = [SELECT Id,Product_CodeF__c, Product_NameF__c,Quantity,
                            ListPrice,Discount,UnitPrice,TotalPrice, 
                            isConsultingF__c, isGlobalProductF__c 
                            FROM QuoteLineItem 
                            WHERE isConsultingF__c = true AND isGlobalProductF__c = false];                                                        
            
            return conLineItems;
        
        }
        set;
        
     }
     
    public decimal consultingTotal{
         get{    
             conTotal=0;
             for(QuoteLineItem qli: conLineItems){
                 conTotal += qli.Quantity * qli.UnitPrice;   
             }
         return conTotal;
         }  
         set;
    } 
    public PageReference viewPDF() {
        string quoteId = ApexPages.currentPage().getParameters().get('id');
        PageReference thePDF = Page.Consulting_Services_Quote;
        thePDF.getParameters().put('id',quoteId);
        thePDF.setRedirect(true);
        return thePDF;
    
    }     
    public PageReference savePDF() { 
        string qId = ApexPages.currentPage().getParameters().get('id');
        System.debug(qId);
        PageReference thePDF = Page.Consulting_Services_Quote;
        thePDF.getParameters().put('id',qId);
        thePDF.setRedirect(true);
                
        quotedocument qd = new quotedocument();
        qd.document = thePDF.getContentAsPDF();
        qd.quoteId = qId;
        insert qd;
    
        PageReference quotePage = new PageReference('/'+ qId);
        quotePage.setRedirect(true);
        return quotePage;
    }
     
}

 

Hello all. First time poster here who has relied heavily on these forums to learn Apex. Thank you!

 

Here's a problem that I hope might generate some discussion.

 

My goal was to take a list of Opportunities and group them by Account, not using a group by clause, rather, creating a list of lists such that each sublist contains opportunities for a unique AccountID. Given a list of opportunities (Opp1...Opp5), the end result should look something like this:

 

AccountA:

   Opp1

   Opp2

AccountB:

   Opp2

   Opp3

   Opp4

AccountC:

   Opp5

 

My first attempted solution is as follows where opps is passed as the function parameter. I had hoped this would return a list of Accounts with the relevant Opportunities in the relationship, but it did not work. The Account list is created as expected but the Opportunities relationship is empty.

 

 

Set<Id> addressees = new Set<Id>();
for(Opportunity o:opps){
  addressees.add(o.Id);
}
List<Account> a = [Select Id, Name, (Select Id, Name, Amount, CloseDate, IsWon, CharitableReceipt__c From Account.Opportunities Where Opportunity.Id in:opps) From Account where Id in :addressees];
return a;

 

 

In the end, I solved the problem using a for loop but it is not as elegant as a single SOQL statement. I'm curious if my original solution is workable.

 

public List<List<Opportunity>> groupOpportunities(List<Opportunity> opps){
        
Set<Id> accts = new Set<Id>();
List<List<Opportunity>> groupedOpps = new List<List<Opportunity>>();
        
//create an account control sets
for(Opportunity o:opps){
   accts.add(o.AccountId);
}
        
//add a new opp list for each account in the control set
for(Id i:accts){
   List<Opportunity> tempOpps = new List<Opportunity>();
   for(Opportunity o:opps){
      if (o.AccountId == i){tempOpps.add(o);}
   }
   groupedOpps.add(tempOpps);
}
        
return groupedOpps;

}

 

Can anyone suggest, how ca we delete apex class from production.

please provide step-step process to delete it from prod. through Force.com Eclipse.

  • October 29, 2010
  • Like
  • 1
I tried many things on how to customize this but find nothing effective. I want to put a text message on the Page Layout I created, how can I do that? Anyone who know how to configure this? Please help me again.