• SFDC9999
  • NEWBIE
  • 5 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 12
    Questions
  • 15
    Replies
Hi,

I have 7 Record Types on Cases and 2 of those record types have to take the user to a Visual force page along with the recordtype selected and the rest of the 5 record types should take the user to a standard case page .
 
public with sharing class CaseOverrideController {

    private ApexPages.StandardController stdCntrl {get; set;}
    
    private Boolean isNew;
    private Boolean isEdit;
    private Boolean isView;

    public CaseOverrideController( ApexPages.StandardController sc ) {
        
        stdCntrl = sc;
        String pageURL = ApexPages.currentpage().geturl();

        if( stdCntrl.getId() == null ){
            this.isNew = true;
        }else{

            if( pageURL.containsIgnoreCase('/e') || pageURL.containsIgnoreCase('retURL') ){
                this.isEdit = true;
            }else{
                this.isView = true;
            }
        }
    }

    public PageReference redirectPage(){
        Schema.DescribeSObjectResult result = Case.sObjectType.getDescribe();
        String caseKeyPrefix = result.getKeyPrefix();

        Map<String , String> currentPageParam = ApexPages.Currentpage().getParameters();

        PageReference pr;
       

            if( this.isNew != null && this.isNew ){
                pr = new PageReference('/' + caseKeyPrefix + '/e'); 
   
            }else{
                
                if( [select RecordType.Name from Case where Id = :stdCntrl.getId()].RecordType.Name == 'Core Collection' ){
                    pr = Page.CC_CaseEdit;
                }else{
                    if( this.isEdit != null && this.isEdit ){
                        pr = Page.CC_CaseEdit;       
                    }else{
                        pr = new PageReference('/' + stdCntrl.getId() );
                    }
                }
            }
            
            if( stdCntrl.getId() != null ){
                pr.getParameters().put('id', stdCntrl.getId());
            }
        

        // Copy over parameters for redirect page
        if( !currentPageParam.isEmpty() ){
            pr.getParameters().putAll( currentPageParam );
            pr.getParameters().remove('save_new');
        }
        return pr;
    }
}
<apex:page showHeader="true" sidebar="true" StandardController="Case" extensions="CaseOverrideController" action="{!redirectPage}" />
I have got it to working a little bit but the If conditions are not right and does not satisy what i am trying to do. And for some reason my standard page keeps loading and never finish loading.

Tried so manby solutions and the pb with all other solutions is record type not setting on the Visual force page which this code does. Any help please

 
I have a Override page for Case , Which redirects to a Visual force page if a certain record type is selected and if not it redirects to a standard page. This is working perfectly for redireting to the necessary page . Howewer when  it is directed to the visual force page the record type which was selected is not passed to the visual force page and it is causing issues with the Picklist values based on the record type. Visual force page always shows the default record type instead of the selected record type.

Here is my override page 
 
<apex:page standardController="Case" extensions="caseRedirect" tabStyle="Case" showheader="true" action="{!redirect}" />
public with sharing class caseRedirect {

private ApexPages.StandardController controller;
public String retURL {get; set;}
public String Type {get; set;}
public String saveNewURL {get; set;}
public String rType {get; set;}
public String cancelURL {get; set;}
public String ent {get; set;}
public String confirmationToken {get; set;}
public String accountID {get; set;}
public String contactID {get; set;}

public caseRedirect(ApexPages.StandardController controller) {

    this.controller = controller;

    retURL = ApexPages.currentPage().getParameters().get('retURL');
    rType = ApexPages.currentPage().getParameters().get('RecordType');
    cancelURL = ApexPages.currentPage().getParameters().get('cancelURL');
    ent = ApexPages.currentPage().getParameters().get('ent');
    confirmationToken = ApexPages.currentPage().getParameters().get('_CONFIRMATIONTOKEN');
    saveNewURL = ApexPages.currentPage().getParameters().get('save_new_url');
    accountID = ApexPages.currentPage().getParameters().get('def_account_id');
    contactID = ApexPages.currentPage().getParameters().get('def_contact_id');

}

public PageReference redirect() {

    PageReference returnURL;

    // Redirect if Record Type corresponds to custom VisualForce page

    IF(rType == '012180000000DjD') {

        returnURL = new PageReference('/apex/CC_CaseEdit?Recordtype=012180000000DjD');

    }
  
    ELSE {

       returnURL = new PageReference('/500/e');

    }

    returnURL.getParameters().put('retURL', retURL);
    returnURL.getParameters().put('RecordType', rType);
    returnURL.getParameters().put('cancelURL', cancelURL);
    returnURL.getParameters().put('ent', ent);
    returnURL.getParameters().put('_CONFIRMATIONTOKEN', confirmationToken);
    returnURL.getParameters().put('save_new_url', saveNewURL);
    returnURL.getParameters().put('nooverride', '1');

    IF (accountID != null){

        returnURL.getParameters().put('def_account_id', accountID);

    }

    IF (contactID != null){

        returnURL.getParameters().put('def_contact_id', contactID);

    }

    returnURL.setRedirect(true);
    return returnURL;

}

}
When VF opens up the record type is always default record type instead of the record type i selected .What am i missing

Thanks 

 
Hi All,

I have a situation where i need to insert 2 fields from account and the few fields from contact(related to account) to a custom object . Is it possible using triggers?
 
Hi ,

I have a VF which is populating Month from the Apex code using the system's month. And i am using this in communites( chinnese lanaguage ). My complete coomminities is in chineese except this .Any help?

Thanks,
A
Hi,

I am trying to display a date field and it always displays in US format and it is causing an issue . Any insight please on this 
 
<apex:column styleClass="product_info_col">
                                   
                                        <span><a href="javascript:void(0)" 
                                            onclick="openProductDetailModal('{!$Site.Prefix}/apex/CCMTY_OrderProductDetailModal?id={!orderItem.PricebookEntry.Product2Id}&pricebookEntryId={!orderItem.PricebookEntryId}');">
                                            {!orderItem.PricebookEntry.Product2.Name}
                                            </a>
                                        </span>

                                     <span>{!$Label.CCMTY_OrderEntry_HeaderLabel_UnitPrice}: {!orderItem.unitPrice}</span>       

                                   <span>{!$Label.CCMTY_OrderEntry_HeaderLabel_EstimatedShipDate}:&nbsp;
                                   <apex:outputText value="{0,date,Long}">
                                   <apex:param value="{!orderItem.Estimated_Ship_Date__c}" /> 
                                   </apex:outputText></span>
                                   
                                   <span>{!$Label.CCMTY_OrderEntry_HeaderLabel_EstimatedDeliveryDate}:&nbsp;
                                   <apex:outputText value="{0,date,Long}">
                                   <apex:param value="{!orderItem.Order_Line_Estimated_Delivery_Date__c}" /> 
                                   </apex:outputText></span>
                                                            
                        <!--     <Apex:outputlabel value="{!$Label.CCMTY_OrderEntry_HeaderLabel_EstimatedDeliveryDate}" style="white-space:pre;"  escape="true"/> 
                                    <apex:outputField label="{!$Label.CCMTY_OrderEntry_HeaderLabel_EstimatedDeliveryDate}" value="{!orderItem.Order_Line_Estimated_Delivery_Date__c}"  /> -->
                                 </apex:column>

Thanks 
G
HI ,

I am deploying some code from sandbox which was developed by another developer. I deopled everything and one visual force page is not working and it gives me an error saying Page error occured while loading page . And this same page works in my sandbox and both the codes are exact same . Am wondering if i missed anything while deployment .

Here is peice of code which needs to work for Opening up the Visual force page.
 
<span><a href="javascript:void(0)" 
                                            onclick="openProductDetailModal('{!$Site.Prefix}/apex/CCMTY_OrderProductDetailModal?id={!orderItem.PricebookEntry.Product2Id}&pricebookEntryId={!orderItem.PricebookEntryId}');">
                                            {!orderItem.PricebookEntry.Product2.Name}
                                            </a>
                                        </span>


function openProductDetailModal(url){
        $("#productDetailModal .modal-body").html('<iframe width="100%" height="750" id="upload_file" frameborder="0" scrolling="no" allowtransparency="true" src="'+url+'"></iframe>');
        $('#productDetailModal').modal('show');
    }

Exact same code in both sandboxes and checked profile permissions and object permissions . everything exactly same . Any insight please 


Thanks 
G
Need to route the user to a visualforce page for creating multiple child records on save of parent record.

Summary
  • Three objects involved: Opportunity, Demographic, and Quota. 
  • One Opportunity has Many Demographics
  • One Demographic has Many Quotas
  • I've created a visualforce page where I add many Quotas to the Demographic at once. Currently this is launched from a custom button on the Demographic Detail Page.
    • Page Name = addQuotas
    • Page has a standard "add row"/"delete row" function to create a Quota record each row from custom controller
    • I pass multipe details from the parent Demographic onto each Quota row through an extension
  • I've created a visualforce page to override the standard new/edit Demographic layout so I can build a custom save button to route to the addQuotas page.
    • Page Name = addDemographic, uses a standard controller, no extensions at the moment
Question
What I want to have happen is when saving the Demographic, the user is immediately taken to the addQuotas page as if they had clicked the button on the detail page. I'm having difficulty making any of this work, trying custom buttons from the Opportunity and hacking the SaveURL, and I'm just not having luck saving the Demographic, grabbing the Id of that Demographic, and then going to the addQuotas page with that Demographic Id in tow. 

What do I add to the Save action on the addDemographic visualforce page to then route to the addQuotas page for THAT Demographic?

Basically, I want on Save of Demographic to automatically go here: /apex/addQuotas?id={!Demographic__c.Id}&retURL={!Demographic__c.Id}

Code and Pictures:
addDemographic page
<apex:page standardController="Demographic__c" tabStyle="Demographic__c">
     <apex:sectionHeader title="Edit Demographic" subtitle="New Demographic"/>
        <apex:form >
                <apex:pageBlock title="Edit Demograhic" mode="edit">
                    <apex:pageblockButtons >
                        <apex:commandButton action="{!save}" value="Add Quotas"/>
                    </apex:pageblockButtons>
                    <apex:pageblockSection title="Demographic Information" columns="1">
                        <apex:inputfield value="{!Demographic__c.Opportunity__c}"/>
                        <apex:inputfield value="{!Demographic__c.Qualification__c}"/>
                    </apex:pageblockSection> 
                </apex:pageBlock>
        </apex:form>

</apex:page>

addQuotas page:
<apex:page standardController="Demographic__c"
            extensions="EditableQuotaListExtension"
            showHeader="true" 
            sidebar="false"
            title="Edit Quota">
    <apex:form >
    <apex:pageMessages id="messages"/>
    <apex:pageBlock title="Edit Quotas">
      <apex:pageBlockButtons >
        <apex:commandButton value="Cancel" action="{!cancel}" />
        <apex:commandButton value="Save" action="{!save}"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection title="Demographic Information" collapsible="false">
      <apex:outputLink value="/{!Demographic__c.Id}" target="_blank">{!Demographic__c.Name}</apex:outputLink>
        <apex:pageBlockSectionItem >
          <apex:outputText value="{!Demographic__c.QualificationName__c}" />
          <apex:outputText value="{!Demographic__c.Qualification_Text__c}" />
        </apex:pageBlockSectionItem>
      </apex:pageBlockSection>
      <apex:pageBlockSection id="childList" columns="1" title="Quotas" collapsible="false">
        <apex:variable var="rowNum" value="{!ZERO}" />
        <apex:outputLabel value="No Quotas currently exist. Click below to Add." rendered="{!NOT(hasChildren)}"/>
        <apex:pageBlockTable value="{!children}" var="quota" rendered="{!hasChildren}">
        <apex:column headerValue="Condition">
          <apex:inputField value="{!quota.Condition__c}"/>
        </apex:column>
        <apex:column headerValue="Option">
          <apex:inputField value="{!quota.Condition_Option__c}"/>
        </apex:column>
        <apex:column headerValue="Description">
          <apex:inputField value="{!quota.Description__c}"/>
        </apex:column>
        <apex:column headerValue="Quota Amount">
          <apex:inputField value="{!quota.Quota_Amount__c}" />
        </apex:column>        
        <apex:column headerValue="%/#">
          <apex:inputField value="{!quota.Quota_Calculation_Type__c}"/>
        </apex:column>
        <apex:column headerValue="Demographic">
          <apex:inputField value="{!quota.Demographic__c}"/>
        </apex:column>
        <apex:column headerValue="Qualification">
          <apex:inputField value="{!quota.Qualification__c}"/>
        </apex:column>
          <apex:column headerValue=" ">
            <!-- This is the second half of the trick to keep track
                  of your row index for deletion. -->
            <apex:variable var="rowNum" value="{!rowNum + 1}" />
            <apex:commandLink value="Delete" action="{!removeFromList}" rerender="childList, messages" immediate="true">
              <apex:param name="removeIndex" assignTo="{!removeIndex}" value="{!rowNum}" />
            </apex:commandLink>
          </apex:column>
        </apex:pageBlockTable>
        <apex:commandButton value="Add Quota" action="{!addToList}" rerender="childList, messages" immediate="true" />
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

addQuotas Extenstion (grabbing details from Demographic parent):
public with sharing class EditableQuotaListExtension extends EditableQuotaList
{


 public Demographic__c mydemo {get; private set;}

  public EditableQuotaListExtension(ApexPages.StandardController stdController) 
  {
    super(stdController);

    this.mydemo = [SELECT Id,
                              Name,
                                Qualification__r.Name
                            FROM Demographic__c
                            WHERE Id =: stdController.getRecord().Id];
    
    this.childList = [SELECT Id,
                          Condition__c,
                          Description__c,
                          Quota_Amount__c,
                          Quota_Calculation_Type__c,
                          Condition_Option__c,
                          Qualification__c,
                          Demographic__c
                      FROM Quota__c
                      WHERE Demographic__c =: mysObject.Id];
  }

  /*
   * This method is necessary for reference on the Visualforce page, 
   * in order to reference non-standard fields.
   */
  public List<Quota__c> getChildren()
  {
    return (List<Quota__c>)childList;
  }


  public override sObject initChildRecord()
  {
    Quota__c child = new Quota__c();
    child.Demographic__c = mydemo.Id;
    child.Qualification__c = mydemo.Qualification__c;
    child.Quota_Amount__c = 100;
    child.Quota_Calculation_Type__c = '%';
    
    return child;
  }
}

View of the addQuotas page so you get the idea of the page:
User-added image


Thank you in advance!!

 

Hi I need little bit help for Test My TaskListview Controller

 

public class TaskListViewController { 
     
    public String objectId {get; set;}
    public Integer numLeft {get; set;}
    public Integer total {get; set;}    
    private Integer startNdx = 0;
    private static Integer PAGESIZE = 8;
    private List<Task> fullTaskList = new List<Task>();
    private List<Task> displayedTaskList = new List<Task>();
    
    
    public TaskListViewController() {

    }
    
    public PageReference refreshPage() {
        return null;
    }
   
    public List<Task> getTasks() {
        String ownerId = UserInfo.getUserId();
        if (fullTaskList.isEmpty())
        {
            fullTaskList = [SELECT Id, WhatId, WhoId, ActivityDate, subject,Activity_Type__c ,status, priority, Description,  ReminderDateTime, IsReminderSet,isClosed 
                            FROM Task 
                            WHERE isClosed = false 
                            AND OwnerId = :ownerId];
            numLeft = fullTaskList.size();
            total = numLeft;
            if(numLeft <> 0)
                this.objectId = ((Task) fullTaskList[0]).id;
         }
        
        displayedTaskList.clear();
        if(numLeft <> 0)
        {
        Integer endNdx = startNdx + PAGESIZE;
        if (endNdx > total)
            endNdx = total;
            
        for (Integer i=startNdx; i<endNdx; i++)
            displayedTaskList.add(fullTaskList.get(i));
         }           
        return displayedTaskList;
    }
 
    private void updateTaskStatus() {
        System.debug('before : ' + fullTaskList);
        Integer i = 0;
        for (i=0; i<fullTaskList.size(); i++) {
            Task t = fullTaskList.get(i);
            if (this.objectId.equals(t.id)) {
                System.debug('updating status of ' + t);                                
                Task tmp = [SELECT Id, WhatId, WhoId, ActivityDate, subject, status, priority, Description, ReminderDateTime, IsReminderSet, isClosed 
                            FROM Task 
                            WHERE id = :t.id];
                fullTaskList.set(i, tmp);
                System.debug('updated to ' + tmp);
                //this.updatedItemStatus = tmp.status;
                break;
            }
        }
        
        System.debug('after : ' + fullTaskList);               
    }
    
    private void nextTask() {
        for (Task t : fullTaskList) {
            if (!t.isClosed) {
                System.debug('found non-closed object with id ' + t.id);
                this.objectId = t.id;
                break;
            }
        }
    }
  

    public void previous() {
        startNdx -= PAGESIZE;
    }
    
    public void next() {
        startNdx += PAGESIZE;
    }    
    
    public void refreshNumbers() {
        updateTaskStatus();
        nextTask();
        this.numLeft = 0;
        for (Task t : fullTaskList) {
            if (!t.isClosed) {
                this.numLeft++;
            }
        }        
      }
    
    public Boolean getHasNext() {
        return total > (startNdx + PAGESIZE);
    }
    
    public Boolean getHasPrevious() {
        return startNdx > 0;
    }    

    public Integer getNum() {
        return total;
    } 
    public PageReference Cancel() {
    PageReference Activitiespage = Page.Activities;
           Activitiespage.setRedirect(true);
           return Activitiespage;
        return null;
    }
    public PageReference save(){       
        for (Task t : fullTaskList) {
           update t;
           PageReference Activitiespage = Page.Activities;
           Activitiespage.setRedirect(true);
           return Activitiespage;
        }
        return null;    
    }
    }

 

@isTest
 Private Class TestTaskListViewController{
 
 static testMethod void testTaskListViewController() {
                
        TaskListViewController t = new TaskListViewController();        
        t.getTasks();    
        t.refreshPage();
        t.previous();
        t.next();
        t.refreshNumbers();
        t.getHasNext();
        t.getHasPrevious();
        t.save();
        t.getNum();
        t.Cancel();
        
                             
    }   
 }

 Getting Around 68% Coverage.

 

I am thinking that if i create a other task and update the status i think my update thing will cover, how would i cover previuos and next page and the page refrence.

 

Thanks