• Jason Dunphy
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies
Is it possible to invoke a jquery dialog on a standard page (case is what I'm trying for) without using a onclick javascript button?  Ideally I'd like the dialog to appear on pageload based on a field value being met (i.e. fielda = true).  Similar to what you can do with a javascript alert on a standard page, but I want more flexibility with what I can present in window the popups (a window title and a ref link instead of just "an embeded page says" with text only).

Below is what would work using the button approach (that is well documented), but I'm looking to convert this so that it happens at pageload when certain critiera on the page is met.  Any ideas for making this happen, is it even possible on a standard page?

Thanks
{!REQUIRESCRIPT("//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js")}
{!REQUIRESCRIPT("//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js")}

var j$ = jQuery.noConflict();

var iframe_url = '{!URLFOR("/apex/testmodal")}';
var j$modalDialog = j$('<div></div>')
       .html('<iframe id="iframeContentId" src="' + iframe_url + '" frameborder="0" height="100%" width="100%" marginheight="0" marginwidth="0" scrolling="no" />')
       .dialog({
            autoOpen: true,
            title: 'Test Dialog',
            resizable: false,
            width: 400,
            height: 400,
            autoResize: true,
            modal: true,
            draggable: false
});

j$modalDialog.dialog('open');

 
I'm having a bit of trouble with creating a related record edit modal in conjunction with a datatable on my VF page.  And I'm hoping someone can help point me in the right direction to solve this on.  Any guidance would be greatly appriciated.

My two problems are:
1. I'm not properly getting the record from the corripsponding row selected (instead my modal always pulls the first row from my table).
2. Can't figure out how to properly insert the change.  I've tried a few different ways to set the change, but no luck.

Edit Modal

So when user's select the 'edit' button from my RelatedContacts table, the modal that always pops only reflects the first row data.  And I've tried, but failed, to incorporate an insert bit in the getRelatedContacts section of my controller so that any changes made in the modal get committed.

Script info from VF page:
<script type="text/javascript">
            
            </script>
            
            <head>
                <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw==" crossorigin="anonymous" />
                <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
                <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha256-KXn5puMvxCw+dAYznun+drMdG1IFl3agK0p/pqT9KAo= sha512-2e8qq0ETcfWRI4HJBzQiA3UoyFk6tbNyG+qSaIBZLyW9Xf3sWZHN/lxe9fTh1U45DpPf07yj94KsUHHWe4Yk1A==" crossorigin="anonymous"></script>
                <style>
                .container-fluid {
                margin-top: 10px;
                }
                </style>
            </head>

Specific Table and Modal from the VF page:
<apex:pageblockTable value="{!RelatedContacts}" var="rltContact" id="rctcs">
                                                <apex:facet name="header">Related Contacts</apex:facet>
                                                <apex:column >
                                                <apex:facet name="header">Name</apex:facet>
                                                <apex:outputText value="{!rltContact.Name}"/>
                                                </apex:column>
                                                <apex:column >
                                                <apex:facet name="header">Phone</apex:facet>
                                                <apex:outputText value="{!rltContact.Phone}"/>
                                                </apex:column>
                                                <apex:column >
                                                <apex:facet name="header">Account</apex:facet>
                                                <apex:outputText value="{!rltContact.account.name}" />
                                                </apex:column>
                                                <apex:column >
                                                    <button type="button" class="row-button" data toggle="modal" data-target="#myModal2" style="text-align: center;" >
                                                    <span class="glyphicon" /> Edit
                                                        </button>
                                                        <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                                            <div class="modal-dialog" role="document">
                                                                <div class="modal-content">
                                                                    <div class="modal-header">
                                                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                                                                        </button>
                                                                        <h4 class="modal-title" id="{!rltContact.Id}">Edit Contact</h4>
                                                                    </div>
                                                                    <div class="modal-body">
                                                                        <div class="form-group">
                                                                            <label>Name</label><br />
                                                                            <apex:OutputField value="{!rltContact.Name}"  styleClass="form-control"/>
                                                                            </div>
                                                                            <div class="form-group">
                                                                                <label>Phone</label><br />
                                                                                <apex:InputText value="{!rltContact.Phone}" html-placeholder="{case.ani__C}" styleClass="form-control"/>
                                                                                </div>
                                                                                <div class="form-group">
                                                                                    <label>Title</label><br />
                                                                                    <apex:InputText value="{!rltContact.Title}" styleClass="form-control"/>
                                                                                    </div>
                                                                                    
                                                                                </div>
                                                                                <div class="modal-footer">
                                                                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                                                    <apex:commandButton styleclass="btn btn-primary" value="Save" action="{!save}" reRender="contacts" onComplete="$('#myModal2').modal('hide');$('body').removeClass('modal-open');$('.modal-backdrop').remove();"/>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </apex:column>
                                                                </apex:pageblockTable>

Controller for VF Page:
public class contactsForServiceCloud {
    public case selectedAccount {get;set;}
    public Contact newCon {get;set;}

    public contactsForServiceCloud(ApexPages.StandardController stdCtrl) {
        selectedAccount = (
            case) stdCtrl.getRecord();
        selectedAccount.ANI__c = System.currentPageReference().getParameters().get('ani');
        selectedAccount.AccountId = System.currentPageReference().getParameters().get('accountId');


    }
    
        public List < Account > getSuggestedAccounts() {
            List < Account > accSugList = [SELECT Name, Phone_Reformatted__C From Account Where Phone_Reformatted__C !=null And Phone_Reformatted__C =: selectedAccount.ANI__c];
            return accSugList;


    }
    
        public List < Account > getAccountInfo() {
            List < Account > accList = [SELECT Name, ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, parent.name, acc_go_live__c From Account Where Id =: selectedAccount.AccountId];
            return accList;

    }

    public List < Contact > getContacts() {
            List < Contact > cntList = [SELECT Name, Phone, Contact.account.name From Contact Where Contact.Account.Id != null and Contact.phone != null and Contact.phone =: System.currentPageReference().getParameters().get('ani') limit 20];
            return cntList;

    }
    
    public List < Contact > getRelatedContacts() {

        IF(selectedAccount.AccountId != null) {
            Set < Id > cntAcctIds = new Set < Id > ();
            for (Account pId: [SELECT ParentID From Account Where Id =: selectedAccount.AccountId]) {
                cntAcctIds.add(pId.ParentId);
            }
            List < Contact > rltcntList = [SELECT Id, Name, Phone, Contact.account.name, Title From Contact Where Contact.Account.Id != null and ((contact.accountId =: cntAcctIds) or (contact.accountId =: selectedAccount.AccountId))];
            return rltcntList;
        }
        return null;

    }
        

    public List < Case > getOpenCases() {
        IF(selectedAccount.AccountId != null) {
            List < Case > opencsList = [SELECT CaseNumber, Subject, Status, Contact.name From Case Where accountid =: selectedAccount.accountid and Status = 'open'
                limit 20
            ];
            return opencsList;
        }
        return null;
    }
    
    public void addContact(){
    newCon.AccountId = selectedAccount.AccountId;
    newCon.Phone = selectedAccount.ANI__c;
    insert newCon;
    newCon = new Contact();
    }

    public pageReference refresh() {
        if (selectedAccount.AccountId != null) {
            pageReference pg = new pageReference(ApexPages.currentPage().getURL());
            pg.setRedirect(TRUE);
            return pg;
        } else {

            return null;
        }
    }
}
Hoping someone can point me the right direction (or just shed light on what newbie faults I’m making), as I’ve been trying to chip away at this and hit a roadblock.

My goal is to have a semi-dynamic VF page to help users quickly capture and set values before committing a new case.  

The init of the page is going to pop as a stand-alone and NO account or contact values will be known or available without user interaction.

After the user selects the account value an inline edit table (would settle for static table though) of all related contacts would appear on the page for the user to reference (instead of having them go through a contact lookup).

I stumbled across this post http://salesforcekings.blogspot.in/2014/05/getting-related-contact-records-as_27.html and manage to get a version of this working, but in my org an account can can many contacts it gets messy really quickly.

Here’s the code I have thus far, which noted below works, but everytime I try to tweak it so it returns a table of contacts I fail to do so:
 
<!-- Visualforce Page -->
<apex:page sidebar="true" StandardController="Case" extensions="contactsForServiceCloud">
    <apex:form >
     <apex:facet name="header">Titles can be overriden with facets</apex:facet>
        <apex:pageBlock title="Create A New Case">
            <apex:pageBlockSection title="My Case" columns="2">
             <apex:outputLabel value="Account Name"> &nbsp;&nbsp;
                
         <apex:inputField value="{!Case.AccountId}" required="false" id="lid">
         <br/><br/><br/>
         <apex:actionsupport event="onchange" rerender="check"/>
         </apex:inputField>
                
         </apex:outputLabel>
               <apex:inputField value="{!Case.ContactId}" />
                <apex:inputField value="{!Case.Description}"/>              
            </apex:pageBlockSection>
        </apex:pageBlock>   
        <center>
                       <apex:outputPanel id="check">
         <apex:outputLabel value="Contacts:" rendered="{!case.AccountId!=null}">
         <apex:selectCheckboxes value="{!selectedAccount}">
           <td> <apex:selectOptions value="{!items}"/></td>
        </apex:selectCheckboxes><br/>
        </apex:outputLabel>
        </apex:outputPanel> 
        </center>
        
        
<apex:commandButton action="{!save}" value="Save" id="theButton"/>
<apex:commandButton onclick="window.open('/003/e?retURL=%2F{!Case.Account}&accid={!Case.AccountId}&&retURL=/{!Case.AccountId}');" value="New Contact" />

           
    </apex:form>
</apex:page>
Apex Class:
public class contactsForServiceCloud
{
public case selectedAccount{get;set;}

 public contactsForServiceCloud(ApexPages.StandardController stdCtrl) {
selectedAccount=(case)stdCtrl.getRecord();
    }

     public List<SelectOption> getItems()
      {
 
      List<Contact> cntList=[SELECT Name From Contact Where ((Contact.account.ParentId=:selectedAccount.AccountID) Or (Contact.account.Id=:selectedAccount.AccountID))];
      List<SelectOption> options = new List<SelectOption>();
        
        for (Contact c:cntList) 
        {
            options.add(new SelectOption(c.Name,c.Name));
        }
        return options;
      }
      

}



Any suggestions would be greatly appreciated,

Thanks
Hoping someone might be able to help me out or at least streamline my research and point me to the right direction as I’m not really making quick progress.  I'm just learning apex and visualforce, looked around this forum and the docs, and just can't seem to find an example that matches my scenario.

I have a visual forcepage that will pop from the CTI and create a NEW case.  All I’m looking to do is make the contact input field dependent on the account input field that the user selects and then submit those to a new case.  This will be used when a contact or account match can't be found from the ANI passed in by the CTI.

The bare bones:
<apex:page sidebar="true" StandardController="Case" extensions="sampleExtension">
    <apex:form >
        <apex:pageBlock title="Create A New Case">
            <apex:pageBlockSection title="My Case" columns="2">
                
         <apex:inputField value="{!Case.AccountId}"
         <apex:inputField value="{Case:ContactId}"
         <apex:inputField value="{!Case.Description}"/>              
            </apex:pageBlockSection>
        </apex:pageBlock>  
<apex:commandButton action="{!save}" value="Save" id="theButton"/>
           
    </apex:form>



What is the best way to do this, SOQL in an extension?  I’ve pieced together some code and sample which returns some related contact vales of related contacts, but I'm not thrilled about the UX and it seems to also be breaking my save command.  I really just want it to be another pick list style input field.

Any help or guidance would be greatly appreciated.

Thanks
 
Hi,

I’m new to Salesforce apex and I'm trying to create the unit testing for a controller extension.  The extension just grabs basic values from the page the user is currently on and populates them on a new visual force creation page.  (e.g. user is on an order record, clicks create new visual force page and the account id and order id from the page carries over to the yet unsaved VF record).  I’ve been combing through posts and examples to come up with proper unit testing, but I haven’t found anything that seems to works for me yet.  I think what I might be getting thrown on is that my controller extension isn’t committing anything, just pre-populating values on the new page that the user will continue to edit and then save when they finish filling out all the applicable values.

Any help and guidance would be greatly appreciated.

Here's the VF page:
<apex:page sidebar="false" StandardController="Cust_Credit__c" extensions="CreditExtension">
    <apex:form >
        <apex:pageBlock title="Create A New Credit">
            <apex:pageBlockSection title="My Content Section" columns="2">
                <apex:inputField value="{!Cust_Credit__c.Credit_Memo_Account__c}"/>
                <apex:inputField value="{!Cust_Credit__c.Credit_Memo_Details__c}"/>
                <apex:inputField value="{!Cust_Credit__c.Credit_Memo_Item__c}" required="true"/>
                <apex:inputField value="{!Cust_Credit__c.Credit_Amount__c}"/>
                <apex:inputField value="{!Cust_Credit__c.Related_Order__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
            <apex:commandButton action="{!save}" value="Save" id="theButton"/>
    </apex:form>
</apex:page>

Here's the controller extension:
public class CreditExtension {
    Cust_Credit__c custCred {get;set;}

    public CreditExtension(ApexPages.StandardController stdController){
        custCred = (Cust_Credit__c)stdController.getRecord();
        custCred.Credit_Account__c = ApexPages.currentPage().getParameters().get('AccountId');
        custCred.Related_Order__c = ApexPages.currentPage().getParameters().get('OrderId');
    }
}
Here's the URL from the custom button that hits the controller extension/VF page:
/apex/Credit_Memo_Entry?AccountId={!Account.Id}&OrderId={!Order.Id}
And here's my poor attempt at a unit test:
@IsTest public with sharing class CreditMemoControllerTest {
     @IsTest(SeeAllData=true) public static void testCreditMemoControllerTest() {
        CreditExtension controller = new CreditExtension();
        controller.setAccountId('001C000001Iqyqa');    
        controller.setOrderId('801C00000008fYW');               
        System.assertEquals(controller.CreditExtension(),null);                           
    }    
}

Thanks

 
Hoping someone might be able to help me out or at least streamline my research and point me to the right direction as I’m not really making quick progress.  I'm just learning apex and visualforce, looked around this forum and the docs, and just can't seem to find an example that matches my scenario.

I have a visual forcepage that will pop from the CTI and create a NEW case.  All I’m looking to do is make the contact input field dependent on the account input field that the user selects and then submit those to a new case.  This will be used when a contact or account match can't be found from the ANI passed in by the CTI.

The bare bones:
<apex:page sidebar="true" StandardController="Case" extensions="sampleExtension">
    <apex:form >
        <apex:pageBlock title="Create A New Case">
            <apex:pageBlockSection title="My Case" columns="2">
                
         <apex:inputField value="{!Case.AccountId}"
         <apex:inputField value="{Case:ContactId}"
         <apex:inputField value="{!Case.Description}"/>              
            </apex:pageBlockSection>
        </apex:pageBlock>  
<apex:commandButton action="{!save}" value="Save" id="theButton"/>
           
    </apex:form>



What is the best way to do this, SOQL in an extension?  I’ve pieced together some code and sample which returns some related contact vales of related contacts, but I'm not thrilled about the UX and it seems to also be breaking my save command.  I really just want it to be another pick list style input field.

Any help or guidance would be greatly appreciated.

Thanks
 
Hi,

I’m new to Salesforce apex and I'm trying to create the unit testing for a controller extension.  The extension just grabs basic values from the page the user is currently on and populates them on a new visual force creation page.  (e.g. user is on an order record, clicks create new visual force page and the account id and order id from the page carries over to the yet unsaved VF record).  I’ve been combing through posts and examples to come up with proper unit testing, but I haven’t found anything that seems to works for me yet.  I think what I might be getting thrown on is that my controller extension isn’t committing anything, just pre-populating values on the new page that the user will continue to edit and then save when they finish filling out all the applicable values.

Any help and guidance would be greatly appreciated.

Here's the VF page:
<apex:page sidebar="false" StandardController="Cust_Credit__c" extensions="CreditExtension">
    <apex:form >
        <apex:pageBlock title="Create A New Credit">
            <apex:pageBlockSection title="My Content Section" columns="2">
                <apex:inputField value="{!Cust_Credit__c.Credit_Memo_Account__c}"/>
                <apex:inputField value="{!Cust_Credit__c.Credit_Memo_Details__c}"/>
                <apex:inputField value="{!Cust_Credit__c.Credit_Memo_Item__c}" required="true"/>
                <apex:inputField value="{!Cust_Credit__c.Credit_Amount__c}"/>
                <apex:inputField value="{!Cust_Credit__c.Related_Order__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
            <apex:commandButton action="{!save}" value="Save" id="theButton"/>
    </apex:form>
</apex:page>

Here's the controller extension:
public class CreditExtension {
    Cust_Credit__c custCred {get;set;}

    public CreditExtension(ApexPages.StandardController stdController){
        custCred = (Cust_Credit__c)stdController.getRecord();
        custCred.Credit_Account__c = ApexPages.currentPage().getParameters().get('AccountId');
        custCred.Related_Order__c = ApexPages.currentPage().getParameters().get('OrderId');
    }
}
Here's the URL from the custom button that hits the controller extension/VF page:
/apex/Credit_Memo_Entry?AccountId={!Account.Id}&OrderId={!Order.Id}
And here's my poor attempt at a unit test:
@IsTest public with sharing class CreditMemoControllerTest {
     @IsTest(SeeAllData=true) public static void testCreditMemoControllerTest() {
        CreditExtension controller = new CreditExtension();
        controller.setAccountId('001C000001Iqyqa');    
        controller.setOrderId('801C00000008fYW');               
        System.assertEquals(controller.CreditExtension(),null);                           
    }    
}

Thanks