• stollmeyera
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 39
    Questions
  • 80
    Replies

I have a VF table that displays on an Opportunity, but pulls in all of the contacts related to the parent Account of that Opportunity.  In that same table I have inline editing, but I can't seem to find a way to save these edits.  Below is my page:

<apex:page standardController="Opportunity" extensions="AccountContacts" tabstyle="Contact" showHeader="false" sidebar="false">
    <apex:form >
        <center>
            <apex:commandButton value="Save" style="width:140pt; heigth:30pt;" action="{!save}"/>
            <apex:commandButton value="Cancel" action="cancel"/>
        </center>
        <apex:pageBlock >
            <apex:pageBlockTable value="{!contacts}" var="c" title="Contacts" cellpadding="20px" >
                <apex:column headerValue="Name">
                    <apex:outputLink value="/{!c.ID}" target="_parent">{!c.FirstName} {!c.LastName}</apex:outPutlink>
                </apex:column>
                <apex:column headerValue="Phone">
                    <apex:outputField value="{!c.Phone}"> 
                        <apex:inlineEditSupport event="ondblclick" showOnedit="update"/> 
                    </apex:outputField>
                </apex:column>
                <apex:column headerValue="Email">
                    <apex:outputField value="{!c.Email}"> 
                        <apex:inlineEditSupport event="ondblclick" showOnedit="update"/> 
                    </apex:outputField>
                </apex:column>
                <apex:column headerValue="Role">
                    <apex:outputField value="{!c.Role__c}"> 
                        <apex:inlineEditSupport event="ondblclick" showOnedit="update"/> 
                    </apex:outputField>
                </apex:column>
                <apex:column headerValue="Role2">
                    <apex:outputField value="{!c.Secondary_Role__c}"> 
                        <apex:inlineEditSupport event="ondblclick" showOnedit="update"/> 
                    </apex:outputField>
                </apex:column>
                <apex:column headerValue="Role3">
                    <apex:outputField value="{!c.Tertiary_Role__c}"> 
                        <apex:inlineEditSupport event="ondblclick" showOnedit="update"/> 
                    </apex:outputField>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Below is my extension:

 

public class AccountContacts{
    ApexPages.StandardController controller;
    private final Opportunity opp;
    public AccountContacts(ApexPages.StandardController controller) {
        opp=(Opportunity)controller.getrecord();
        this.controller = controller;
    }

    // Create the list for existing contacts
    public List<Contact> getContacts() {
        List<Opportunity> opps = [Select ID, AccountID
                                  FROM Opportunity
                                  WHERE ID =:ApexPages.currentPage().getParameters().get('ID')
                                  limit 1];
        string ActID = opps[0].AccountID;
        List<Contact> contacts = [select id, AccountID, FirstName, LastName, Phone, Email, Question_Answer__c, Role__c, Secondary_Role__c,Tertiary_Role__c, Create_Profile__c
                    from Contact
                    Where AccountID =:ActID
                    ORDER BY LastName];
        return contacts;
    }
    
    public PageReference save() {
        controller.save();
        PageReference contPage = new PageReference('/apex/accountcontacts?id=' + opp.ID);
        contPage.setRedirect(true);
        return contPage;
    }
}

 

I have tried adding a simple "update contacts;" to my PageReference to no avail.

 

How can i get the Save function to save the contacts as well?

I am working on a VF page to display Account contacts in the Opportunity.  Within my class I have written a SOQL query to pull these contacts, but for some reason I can't reference the Opportunity.AccountID.  Within my query I am simply stating:

 

[select id, AccountID, FirstName, LastName, Phone, Email, Question_Answer__c, Role__c, Secondary_Role__c,Tertiary_Role__c, Create_Profile__c from Contact Where AccountID = :ApexPages.currentPage().getParameters().get('AccountID') ORDER BY LastName];

 

When I debug, the AccountID is passing as a null value.  

 

Any suggestions on how I can gather the Opportunity AccountID and use it within my select statement?

I've looked around for a couple hours trying to figure this out but have been unable.  I am trying to pass a variable from javascript to my VF extension. The exact variable is 'sforce.console.isInConsole()' to determine if my users are accessing the page via the Console or not.  Below is the javascript I have included within my VF page:

 

<script type="text/javascript" >
    document.getElementById('{!$Component.Console}').value = sforce.console.isInConsole();
</script>

 

Below is the inputHidden field:

<apex:inputHidden id="Console" value="{!ConsoleVal}" />

 

Lastly, below is what I have included within my APEX class:

public String ConsoleVal {get; set;}

 

 

All resources I have found lead me to believe that this should work.  However, the ConsoleVal variable is null when I look at the debug logs, so there is a disconnect...  What am I missing?

I created a VF page for my users to help them take ownership of Accounts/Opps as SF doesn't handle it all that well for the way my org works.  To allow my users to use this new page, I created a custom formula field to replace the standard Opportunity Owner field.  When the click CHANGE on this custom field, it takes them to my VF page, which does all of the steps for them.

 

The issue I have is with users utilizing the Console view.  When they click the CHANGE button it redirects them away from console.  The way around this was to change the _target of the HYPERLINK in the formula field to _blank, thus opening in a new tab/window.  This is not clean at all from a usability standpoint as a single user may end up with dozens of tabs/windows open.

 

Are there any suggestions on a way to optimize this for console, while still making it a friendly experience for users not using the console?

 

In a perfect world, console users would stay on the same screen and the VF page would load within the Opportunity "Full View" frame of the console (the bottom left frame of the bellow image).  Once they save the VF page, the frame then loads with the Opp record.  All the while, users not on the console will experience this all within the same tab/window.

 

(Hope this is all clear...)

 

Console Example

 

 

I have a VF page with a custom extension that works great.  However, when a validation error is triggered on Save, the actual error message does not show.  Instead, the user is either taken back to the standard record detail page, or they are taken to an ugly Visualforce Error screen that says something like this:

 

Visualforce Error


System.DmlException: Update failed. First exception on row 0 with id 006W0000002LwCGIA0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, INSERT VALIDATION RULE ERROR MESSAGE HERE.: [] 


Class.CloseOppRedirect2.SavePage: line 65, column 1

 

 

I have included the <apex:messages> component to my VF page, so I am unsure what else I am missing.  Below is my code:

 

 

 VF Page:

 

<apex:page standardController="Opportunity" title="Close Opportunity - {!Opportunity.Account.Name}" apiVersion="23.0" extensions="CloseOppRedirect2">
    
    <apex:sectionHeader title="Close Sale" subtitle="Step 2 of 4"/>
    <apex:form >
        <apex:pageblock mode="Edit" >
        <b><apex:messages style="color:red"/></b>
        </apex:outputPanel>
            <apex:pageblocksection showHeader="true" columns="2" title="Sale Info" >
                <apex:inputField label="Company Name" Value="{!act.Name}" />
                <br/>
                <br/>
                <apex:inputField Value="{!Opportunity.closedate}" />
                <apex:inputField Value="{!Opportunity.Business_Type__c}" style="{!if(opportunity.Business_Type__c = null,"color:red; font-weight:bold", null)}" required="true" />
                <apex:inputField Value="{!Opportunity.Stagename}" />
                <apex:inputField Value="{!Opportunity.Constant_Contact__c}" style="{!if(opportunity.Constant_Contact__c = null,"color:red; font-weight:bold", null)}" required="true" />
                <apex:inputField Value="{!Opportunity.Reason_Won__c}" required="true" />
                <apex:inputField Value="{!Opportunity.Sale_Notes__c}"  style="width:125pt; height:50pt"/>
                <apex:inputField label="Site ID" Value="{!Opportunity.ZZSiteID__c}"/>
                <apex:pageblockSectionItem helpText="If there is no referral or you do not know the name of the business, put 'None'"  >
                    <apex:outputLabel value="MB Client Referred By" />
                    <apex:inputField value="{!act.Referred_By_MB_Client__c}" required="{!if(Opportunity.LeadSource = "Another Client", "true", "false")}" />
                </apex:pageblockSectionItem>
            </apex:pageblocksection>
            
            <apex:pageblocksection showHeader="true" columns="1" title="Outstanding Issues" rendered="{!IF(OR(Opportunity.Account.ValidationPhone__c = "True", Opportunity.Account.ValidationAmpersand__c="True") = true, "True", "False")}">
            <h4>Please make sure to remove any ampersands from the Account fields and remove all letters from Phone fields before closing</h4>
                <apex:inputField Value="{!act.Phone}" rendered="{!Opportunity.Account.ValidationPhone__c}" />
                <apex:inputField Value="{!act.Phone_2__c}" rendered="{!Opportunity.Account.ValidationPhone__c}" />
                <apex:inputField Value="{!act.Email__c}" rendered="{!IF(CONTAINS(act.Email__c, "&") = true, "True", "False")}"/>
                <apex:inputField Value="{!act.Website}" rendered="{!IF(CONTAINS(act.Website, "&") = true, "True", "False")}"/>
                <apex:inputField Value="{!act.BillingStreet}" rendered="{!IF(CONTAINS(act.BillingStreet, "&") = true, "True", "False")}"/>
                <apex:inputField Value="{!act.BillingCity}" rendered="{!IF(CONTAINS(act.BillingStreet, "&") = true, "True", "False")}" />
                <apex:inputField Value="{!act.BillingState}" rendered="{!IF(CONTAINS(act.BillingStreet, "&") = true, "True", "False")}" />
                <apex:inputField Value="{!act.BillingCountry}" rendered="{!IF(CONTAINS(act.BillingStreet, "&") = true, "True", "False")}" />
            </apex:pageblocksection>
            
            <apex:pageblocksection showHeader="true" columns="2" title="Miscellaneous" >
                <apex:inputField label="Are they interested in ID Solutions?" Value="{!Opportunity.ID_Solutions__c}" required="true"/>
                <apex:inputField Value="{!Opportunity.Site_Template__c}" />
                <apex:inputField label="Did they request a conversion?" Value="{!Opportunity.Requested_Conversion__c}" required="true" />
                <apex:inputField Value="{!Opportunity.PAC_Services__c}" />
            </apex:pageblocksection>
            
            <apex:pageblocksection showHeader="true" columns="1"  title="Product Details">
            <a href="https://na4.salesforce.com/{!Opportunity.ID}#{!LEFT(Opportunity.ID, 15)}_RelatedLineItemList_target" target="_blank"><h2>**Click Here to Change**</h2></a>
                <apex:outputfield Value="{!Opportunity.Amount}" />
                <apex:outputField Value="{!Opportunity.Hosting__c}" />
                <apex:outputField Value="{!Opportunity.Hardware__c}" />
                <apex:outputField Value="{!Opportunity.Support__c}" />
                <apex:outputField Value="{!Opportunity.Setup__c}" />
            </apex:pageblocksection>

            <apex:pageblocksection title="Assign Trade Show (if applicable)" rendered="false" />

                <apex:pageblockTable value="{!campaigns}" var="c" rendered="false" >
                    <apex:column title="Copy/Paste into below field" headerValue="Active Trade Shows - Copy/Paste into below field" value="{!c.Name}" />
                </apex:pageblockTable>
            
            <apex:pageblocksection showHeader="true" columns="1">
                <apex:inputfield label="Trade Show" Value="{!Opportunity.CampaignID}" />
            </apex:pageblocksection>

        </apex:pageBlock>
             <center>
             
             <html>
                <head>
                    <script type="text/javascript">
                    function goBack()
                      {
                      window.history.back()
                      }
                    </script>
                </head>
                <body>
                <input type="button" class="btn" value="Back" onclick="goBack()" />
                </body>
            </html>
                <apex:commandButton value="Next Step" action="{!SavePage}" style="width:20%" />
                <apex:commandbutton value="Cancel" action="{!cancel}" />
            </center>
    </apex:form>
</apex:page>

 

 

Below is my Extension:

 

public class CloseOppRedirect2{

    //Get the Account Fields
    public Account act {get; set;}
    
    ApexPages.StandardController controller;
    List<Opportunity> opps = new List<Opportunity>();
    public CloseOppRedirect2(ApexPages.StandardController controller){
        Opportunity o = (Opportunity)controller.getRecord();
        o.StageName = '5 - Closed Won';
        o.CloseDate = Date.today();
        this.controller = controller;
        
        o = [Select ID,
                    AccountID,
                    Account.Name,
                    Account.Phone,
                    Account.Phone_2__c,
                    Account.BillingCity, 
                    Account.BillingStreet, 
                    Account.BillingState, 
                    Account.BillingCountry,
                    Account.Website,
                    Account.Email__c,
                    Account.Referred_By_MB_Client__c
                    from Opportunity where ID=:controller.getRecord().Id limit 1];
        
        act = o.Account;
        
        if(o.ID != null){
            opps.add(o);
        }
        
     }
     
     
    public PageReference SavePage() {
    
        Opportunity o = (Opportunity)controller.getRecord();
        update act;
        if(act.Referred_By_MB_Client__c == 'None' && o.LeadSource == 'Another Client'){
            o.LeadSource = 'Word of Mouth';
            opps.remove(0);
            opps.add(o);
        }
            update opps;
                
        controller.save();
        
        List<Opportunity> opp = [Select AccountID, Reason_Won__c, Hosting__c from Opportunity where ID =:ApexPages.CurrentPage().getParameters().get('id')];
        if(opp.size() > 0 && opp[0].Hosting__c > 0){
            PageReference SavePage= new PageReference('/apex/closeopp3?id='+opp[0].AccountID);
            SavePage.setRedirect(true);
            return SavePage;
        }
        else{
            if(opp.size() > 0 && opp[0].Hosting__c == 0){
                PageReference SavePage= new PageReference('/' +opp[0].ID);
                SavePage.setRedirect(true);
                return SavePage;
            }
            else{
                return null;
            }
        }
        
   }
        
}

 

Any help is greatly appreciated.  

I am currently construting a dupe checker on the phone field on lead insert.  One of the thingsi did was created a field for a stripped phone number, so it only contains numbers and no characters/symbols (performed on line 15 below).  However, this field still contains the Extension if the user defined that number in the Phone field.  That means that a user may go in and define a duplicate phone number on a new lead, which won't get caught because the duplicate lead has a phone extension on it.  Because of this, i would like to add a StartsWith condition to my select statement.  Code below:

 

1 trigger DupeBlockLeadPhone on Lead (before insert) {
2
3    Map<String, Lead> leadMapPhone1 = new Map<String, Lead>();
4    
5    for (Lead lead : System.Trigger.new) {
6    
7        // Make sure the phone is not null
8        if (lead.Phone != null && ){
9    
10            // Make sure another new lead isn't also a duplicate  
11           if (leadMapPhone1.containsKey(lead.Phone)) {
12                lead.Phone.addError('Another new lead has the ' + 'same Phone address.');
13            } else {
14                string strphone = lead.phone;
15                strphone = strphone.replaceAll('\\D', '');
16                leadMapPhone1.put(strphone, lead);
17            }
18        }
19    }
20	
21	//Search the system for matching phone numbers
22	for (Lead lead : [SELECT StrippedPhone__c, Company, Name FROM Lead
23                      WHERE StrippedPhone__c IN :leadMapPhone1.KeySet() AND IsConverted = false]) {
24        Lead newLead = leadMapPhone1.get(lead.StrippedPhone__c);
25        newLead.Phone.addError('A lead with this Phone ' + 'already exists.' + '<br/>' + '<a href="https://na4.salesforce.com/' 
26                               + lead.ID + '" target="_blank">' 
27                               + lead.Name + ' - ' 
28                               + lead.Company + '</a>');
29        System.Debug('Existing Phone ' + lead.StrippedPhone__c);
30        System.Debug('New Phone ' + leadMapPhone1.keySet());
31    }
32 }

Line 23 is where I need to put the StartsWith condition.  The way I want it to read is:  SELECT FROM LEAD WHERE the Phone in leadMapPhone1 StartsWith the existing lead.Phone.

 

I am not well versed in APEX; any ideas?

We currently integrate our Salesforce org with Eloqua, a marketing SAAS.  Eloqua is currently configured to grab updates from Leads and Contacts in our org when the last modified date is changed.  This is a pretty simple concept: If a user updates the email address in Salesforce, the Last Modified Date is changed and Eloqua is triggered to grab those new fields.  


My marketing team is requesting that Eloqua get triggered based off of the Last Activity Date instead of the Last Modifed Date.  Because this can't be done with the current build of Eloqua, the idea is to create a custom field on the Lead/Contact and, whenever a task is added to it, have this field change, thus updating the Last Modified date.  

 

Ultimately, I don't like this idea.  If we ever need to come back to the Last Modified Date, there is no data integrity.  However, I would really appreciate hearing others thoughts on this matter.  Any input is appreciated. 

I have a controller extension for a VF page that I got 60% coverage on.  The only part that I am having issues covering is a query of campaigns.  Below is my Class:

 

 1	  public class TradeShowLeads1 {
 2	  
 3	   //Create list for leads
 4	   private final Lead ld;
 5	   List<Lead> lds = new List<Lead>();
 6	   List<CampaignMember> CamMems = new List<CampaignMember>();
 7	   Campaign c1 = [Select ID, Primary_Market__c, Name from Campaign where Campaign_Form__c = 'Form 1' LIMIT 1];
 8	  
 9	   public TradeShowLeads1 (ApexPages.StandardController controller) {
 10	   ld=(Lead)controller.getrecord();
 11	   ld.LeadSource = 'Trade Show';
 12	   ld.Industry = c1.Primary_Market__c;
 13	   ld.Lead_Type__c = 'Inbound';
 14	   }
 15	  
 16	   //create list for Campaign
 17	   Campaign campaign;
 18	   List<Campaign> campaigns;
 19	  
 20	   public List<Campaign> getCampaigns() {
 21	   if(campaigns == null) {
 22	   campaigns = new List<Campaign>();
 23	   campaign=null;
 24	   List<Campaign> campaigns2 = new List<Campaign>();
 25	   campaigns2 = [Select Name from Campaign where Campaign_Form__c = 'Form 1' LIMIT 1];
 26	   for(Campaign campaign:campaigns2) {
 27	   campaigns.add(campaign);
 28	   }
 29	   }
 30	   return campaigns;
 31	   }
 32	  
 33	   public PageReference TradeShowLeads1() {
 34	   if(ld.get('Id') == null){
 35	   lds.add(ld);
 36	   CampaignMember mem = new CampaignMember (campaignid=c1.id, leadid=ld.id);
 37	   CamMems.add(mem);
 38	   }
 39	  
 40	   insert lds;
 41	   insert CamMems;
 42	   PageReference RedirectLead = new PageReference('/apex/tradeshow1');
 43	   redirectLead.setRedirect(true);
 44	   return RedirectLead;
 45	  
 46	  
 47	   }
 48	  
 49	  
 50	  
 51	  }

 

Below is my test class:

 

public class TestTradeShowExtension1 {

    static testMethod void testTradeShow1() {
    
        //create the Lead
        Lead testL = new Lead(LastName = 'test',
                              Company = 'test',
                              Industry = 'test',
                              LeadSource = 'Online Search',
                              Lead_Type__c = 'inbound',
                              Contact_Method__c = 'Phone');
        insert testL;
        
        //create Campaign
        Campaign testC = new Campaign(Name = 'test',
                                      StartDate = Date.today(),
                                      Primary_Market__c = 'Fitness');
        insert testC;
        
        
        //create standard controller for lead
        ApexPages.StandardController stdCon = new ApexPages.StandardController(testL);
        
        //create controller extension with stdCon
        TradeShowLeads1 ext = new TradeShowLeads1(stdCon);
        
        //assert campaign member was created
        
        //assert the pagereference worked
        ext.TradeShowLeads1();

     }
}

 

When I run the test I am missing coverage on lines 20 - 30 and lines 35-37.  Any help would be greatly appreciated.  

I have the below trigger in my Org.  It automatically submits an approval to the manager when specific leads are marked as Lead Status - Disqualified.  

 

trigger LeadSubmitApproval on Lead (after update) {
 
ID RepID= [Select ID from Profile where Name = 'MINDBODY Sales Representative' Limit 1].id;
ID SarahID= [Select ID from Profile where Name = 'International Associate Manager' Limit 1].id;

    for (Integer i = 0; i < Trigger.new.size(); i++) {
 
        if (Trigger.old[i].Status != 'Disqualified' && 
        	Trigger.new[i].Status == 'Disqualified' && 
        	(UserInfo.getProfileID() == RepID || UserInfo.getProfileId() == SarahID) && 
        	(Trigger.new[i].Lead_Type__c == 'Inbound' || Trigger.new[i].LeadSource == 'Trade Show')) {

            // create the new approval request to submit
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted DQ Lead for approval. Please approve.');
            req.setObjectId(Trigger.new[i].Id);
            
            // submit the approval request for processing
            Approval.ProcessResult result = Approval.process(req);
            System.assert(result.isSuccess());
            
            // display if the reqeust was successful
            System.debug('Submitted for approval successfully: '+result.isSuccess());
 
        }
 
    }
 
}

 

 

It has been working great for a few months, but has all of the sudden it is throwing the below error:

 

Apex script unhandled trigger exception by user/organization: 00560000001Np28/00D60000000J1xm 

LeadSubmitApproval: execution of AfterUpdate

caused by: System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process.: []

 

Trigger.LeadSubmitApproval: line 19, column 45

 

Can anyone help me understand why this all of the sudden started throwing errors ??  (Line 19, col 45 is highlighted in red above)

I have a VG page that shows all existing contacts on an Account, as well as allows you to add new contacts to the Account; it does so through a pageblockTable and some extensions.  I need a way to add an Update button next to each one of the lineitems on the pageblockTable to allow the user to make a change to one Contact and then quicksave it separate from the rest.  

 

Is this possible?

I am working with an integration between Salesforce and another third party software.  Needless to say the third party software has a bad database design that causes issues with sending over multiple API calls at once time.  Because of this I need a way to delay triggers so they fire asynchronous.  Is there anyway to do this within the Trigger?  If not, is there anyway to do this with the save method within an extension/controller?

I have a VF page that allows my users to add and edit contacts and associate them with an Account all from one area.  One of the fields under that screen is a simple checkbox called "Map?".  If they click that button and save the page, a trigger fires in SF to create an XML file and send it over an API to create a profile in a third party software.  

 

The problem I am having is if a user has more than one contact on the VF page, whether they be adding two contact or working with two existing contacts (or any combination of that), the trigger only fires for one of the contacts.  Ex: I go to my VF page and I have two existing contacts.  I populate some required fields and click the "Map?" button for those two contacts.  I then click an Add New button and add a row for a brand new contact, while also clicking the "Map" button.  When I save the page, the two existing contacts are updated with "Map?" equal to true.  Additionally, the third contact is added and updated with "Map?" equal to true.

 

At this point I have a trigger in SF that, upon "Map?" equaling true, is supposed to populate an XML file and send it over an API to the third party program.  Even though all three contacts are updated with "Map?" equal to true, the trigger is only firing once.  It isn't erroring for the other two, it is just not firing at all for them...

 

I would be more than happy to provide the code, but I'd rather spare the space if anyone has some quick advice.  Thank you in advance.

I have setup a VF edit page to show all of the contacts related to the selected account in a pageblockTable.  On this page I have a checkbox built in to not be visible and to automatically be checked, like the below:

 

<apex:inputcheckbox value="{!c.Create_Profile__c}" selected="true" style="visbility:hidden"/>

What I want to happen is this aforementioned Create_Profile__c field to be unchekced initially.  However, once the user accesses this VF page it will automatically check the box upon save, without them having to consciously do this  Unfortunately this is not happening right now.  Even though I have added the attribute for "selected=true", it is not actually checking this box (side note: this same attribute works fine with a pageblockSection).

 

Can I not use the "selected" attribute on a inputcheckbox when using a pageblockTable?

When there is an open task assigned to a lead, and that lead is taken over by another user, the open task automatically gets assigned to that new owner.  I've looked around and there is nothing available from the "clicks" side of things to prevent this.  Has anyone else faced this problem and, if so, found a way to address it through code?

I have two VF pages in a wizard.  The idea is when the user hits Save on the first page, it grabs a field I have titled OppID__c from the Account and redirects the user to the second VF page ("/apex/closeopp2?id=" + OppID).  The redirect works great, but the extension doesn't actually save any of the fields entered on the first page of the wizard.  Code below:

 

public class CloseOppRedirect{

    private final Account a;
    public CloseOppRedirect(ApexPages.StandardController controller){
        this.a = (Account)controller.getRecord();
     }            
    
    //hoping that this will get me the OppID
    public PageReference save() {
        
    Account a = [select ID, OppID__c from Account where ID =:ApexPages.currentPage().getParameters().get('id')];
        String Oppid = a.OppID__c;
        
        PageReference contPage = new PageReference('/apex/closeopp2?id=' + Oppid);
        contPage.setRedirect(true);
        return contPage;
        
    }
 }

 

I am super new to APEX so any help would be greatly appreciated.  

I have one VF page for a parent record and a second VF page for the child record.  I would like the two pages to link together on save.  That is, I input values on page1, upon hitting save it saves the values and then redirects me to my second page.  Considering it is a simple redirect, I really don't feel I need to write a controller, correct?

I am in the process of writing a controller extension and am having a lot of difficulty.  Using the Opp as the standard controller, I am trying to allow a user to update input fields for a child Opportunity and parent Account.  I then need to override the save method to save the Account first and then the Opportunity second.  Does anyone have an example of a similar extension that I can use as a reference?

I am trying to create a VF page that allows me to update an Opportunity and Account record at the same time (or maybe in two steps, either way I don't care).  I have heard that creating a custom button would work and I have played with a class, but can't get anything to function properly.  How would it be possible to do this?

I have a VF page with the Opportunity as the standard controller.  Within this page I have referenced the related Account with some input fields.  You can see this below in a small snippet I took:

 

................<apex:inputField Value="{!Opportunity.Reason_Won__c}" required="true" />
                <apex:inputField Value="{!Opportunity.Sale_Notes__c}"  style="width:125pt; height:50pt"/>
            </apex:pageblocksection>
            
            <apex:pageblocksection showHeader="true" columns="2" title="2 - Account Info" rendered="{!if(Opportunity.Amount=0, false, true)}">
                <apex:inputField Value="{!Opportunity.LeadSource}"  required="true"/>
 	 <apex:inputField Value="{!Opportunity.Account.Industry}" required="true" /> .................

 

 

The whole idea here is to allow my users to perform an operation that requires them to populate fields under the Account and Opportunity.  Unfortunately, what happens when they save the page is it only updates the Opportunity fields while disregarding any changes made to the Account fields.  In otherworsd, I may have selected "Fitness" for the Account.Industry inputField.  However, upon saving the page the Industry field is left blank under the Account.  Is this by design?  If so, how would I manipulate it with APEX to allow me to pass these changes to the Account?

I have gone to the end of the world and back searching for an answer to this, but no luck.  I added an image as a public static resource and am trying to render it in a PDF file.  When I do nothing shows up.  I know for a fact it is not a broken URL as it shows up just fine when I render as a normal visualforce page; the issue only seems to be happening when I render as PDF.  I have  tried two different methods to get the image to display, referenced below:

 

<apex:image style="align='left'" id="mblogo" value="{!$Resource.mblogo}" width="276" height="63"/>
<img align="left" src="{!$Resource.mblogo}"/>

 

 Regardless of what I do, the image does not display on the resulting PDF file.  Any suggestiions?

I am working on a VF page to display Account contacts in the Opportunity.  Within my class I have written a SOQL query to pull these contacts, but for some reason I can't reference the Opportunity.AccountID.  Within my query I am simply stating:

 

[select id, AccountID, FirstName, LastName, Phone, Email, Question_Answer__c, Role__c, Secondary_Role__c,Tertiary_Role__c, Create_Profile__c from Contact Where AccountID = :ApexPages.currentPage().getParameters().get('AccountID') ORDER BY LastName];

 

When I debug, the AccountID is passing as a null value.  

 

Any suggestions on how I can gather the Opportunity AccountID and use it within my select statement?

I've looked around for a couple hours trying to figure this out but have been unable.  I am trying to pass a variable from javascript to my VF extension. The exact variable is 'sforce.console.isInConsole()' to determine if my users are accessing the page via the Console or not.  Below is the javascript I have included within my VF page:

 

<script type="text/javascript" >
    document.getElementById('{!$Component.Console}').value = sforce.console.isInConsole();
</script>

 

Below is the inputHidden field:

<apex:inputHidden id="Console" value="{!ConsoleVal}" />

 

Lastly, below is what I have included within my APEX class:

public String ConsoleVal {get; set;}

 

 

All resources I have found lead me to believe that this should work.  However, the ConsoleVal variable is null when I look at the debug logs, so there is a disconnect...  What am I missing?

I created a VF page for my users to help them take ownership of Accounts/Opps as SF doesn't handle it all that well for the way my org works.  To allow my users to use this new page, I created a custom formula field to replace the standard Opportunity Owner field.  When the click CHANGE on this custom field, it takes them to my VF page, which does all of the steps for them.

 

The issue I have is with users utilizing the Console view.  When they click the CHANGE button it redirects them away from console.  The way around this was to change the _target of the HYPERLINK in the formula field to _blank, thus opening in a new tab/window.  This is not clean at all from a usability standpoint as a single user may end up with dozens of tabs/windows open.

 

Are there any suggestions on a way to optimize this for console, while still making it a friendly experience for users not using the console?

 

In a perfect world, console users would stay on the same screen and the VF page would load within the Opportunity "Full View" frame of the console (the bottom left frame of the bellow image).  Once they save the VF page, the frame then loads with the Opp record.  All the while, users not on the console will experience this all within the same tab/window.

 

(Hope this is all clear...)

 

Console Example

 

 

I have a VF page with a custom extension that works great.  However, when a validation error is triggered on Save, the actual error message does not show.  Instead, the user is either taken back to the standard record detail page, or they are taken to an ugly Visualforce Error screen that says something like this:

 

Visualforce Error


System.DmlException: Update failed. First exception on row 0 with id 006W0000002LwCGIA0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, INSERT VALIDATION RULE ERROR MESSAGE HERE.: [] 


Class.CloseOppRedirect2.SavePage: line 65, column 1

 

 

I have included the <apex:messages> component to my VF page, so I am unsure what else I am missing.  Below is my code:

 

 

 VF Page:

 

<apex:page standardController="Opportunity" title="Close Opportunity - {!Opportunity.Account.Name}" apiVersion="23.0" extensions="CloseOppRedirect2">
    
    <apex:sectionHeader title="Close Sale" subtitle="Step 2 of 4"/>
    <apex:form >
        <apex:pageblock mode="Edit" >
        <b><apex:messages style="color:red"/></b>
        </apex:outputPanel>
            <apex:pageblocksection showHeader="true" columns="2" title="Sale Info" >
                <apex:inputField label="Company Name" Value="{!act.Name}" />
                <br/>
                <br/>
                <apex:inputField Value="{!Opportunity.closedate}" />
                <apex:inputField Value="{!Opportunity.Business_Type__c}" style="{!if(opportunity.Business_Type__c = null,"color:red; font-weight:bold", null)}" required="true" />
                <apex:inputField Value="{!Opportunity.Stagename}" />
                <apex:inputField Value="{!Opportunity.Constant_Contact__c}" style="{!if(opportunity.Constant_Contact__c = null,"color:red; font-weight:bold", null)}" required="true" />
                <apex:inputField Value="{!Opportunity.Reason_Won__c}" required="true" />
                <apex:inputField Value="{!Opportunity.Sale_Notes__c}"  style="width:125pt; height:50pt"/>
                <apex:inputField label="Site ID" Value="{!Opportunity.ZZSiteID__c}"/>
                <apex:pageblockSectionItem helpText="If there is no referral or you do not know the name of the business, put 'None'"  >
                    <apex:outputLabel value="MB Client Referred By" />
                    <apex:inputField value="{!act.Referred_By_MB_Client__c}" required="{!if(Opportunity.LeadSource = "Another Client", "true", "false")}" />
                </apex:pageblockSectionItem>
            </apex:pageblocksection>
            
            <apex:pageblocksection showHeader="true" columns="1" title="Outstanding Issues" rendered="{!IF(OR(Opportunity.Account.ValidationPhone__c = "True", Opportunity.Account.ValidationAmpersand__c="True") = true, "True", "False")}">
            <h4>Please make sure to remove any ampersands from the Account fields and remove all letters from Phone fields before closing</h4>
                <apex:inputField Value="{!act.Phone}" rendered="{!Opportunity.Account.ValidationPhone__c}" />
                <apex:inputField Value="{!act.Phone_2__c}" rendered="{!Opportunity.Account.ValidationPhone__c}" />
                <apex:inputField Value="{!act.Email__c}" rendered="{!IF(CONTAINS(act.Email__c, "&") = true, "True", "False")}"/>
                <apex:inputField Value="{!act.Website}" rendered="{!IF(CONTAINS(act.Website, "&") = true, "True", "False")}"/>
                <apex:inputField Value="{!act.BillingStreet}" rendered="{!IF(CONTAINS(act.BillingStreet, "&") = true, "True", "False")}"/>
                <apex:inputField Value="{!act.BillingCity}" rendered="{!IF(CONTAINS(act.BillingStreet, "&") = true, "True", "False")}" />
                <apex:inputField Value="{!act.BillingState}" rendered="{!IF(CONTAINS(act.BillingStreet, "&") = true, "True", "False")}" />
                <apex:inputField Value="{!act.BillingCountry}" rendered="{!IF(CONTAINS(act.BillingStreet, "&") = true, "True", "False")}" />
            </apex:pageblocksection>
            
            <apex:pageblocksection showHeader="true" columns="2" title="Miscellaneous" >
                <apex:inputField label="Are they interested in ID Solutions?" Value="{!Opportunity.ID_Solutions__c}" required="true"/>
                <apex:inputField Value="{!Opportunity.Site_Template__c}" />
                <apex:inputField label="Did they request a conversion?" Value="{!Opportunity.Requested_Conversion__c}" required="true" />
                <apex:inputField Value="{!Opportunity.PAC_Services__c}" />
            </apex:pageblocksection>
            
            <apex:pageblocksection showHeader="true" columns="1"  title="Product Details">
            <a href="https://na4.salesforce.com/{!Opportunity.ID}#{!LEFT(Opportunity.ID, 15)}_RelatedLineItemList_target" target="_blank"><h2>**Click Here to Change**</h2></a>
                <apex:outputfield Value="{!Opportunity.Amount}" />
                <apex:outputField Value="{!Opportunity.Hosting__c}" />
                <apex:outputField Value="{!Opportunity.Hardware__c}" />
                <apex:outputField Value="{!Opportunity.Support__c}" />
                <apex:outputField Value="{!Opportunity.Setup__c}" />
            </apex:pageblocksection>

            <apex:pageblocksection title="Assign Trade Show (if applicable)" rendered="false" />

                <apex:pageblockTable value="{!campaigns}" var="c" rendered="false" >
                    <apex:column title="Copy/Paste into below field" headerValue="Active Trade Shows - Copy/Paste into below field" value="{!c.Name}" />
                </apex:pageblockTable>
            
            <apex:pageblocksection showHeader="true" columns="1">
                <apex:inputfield label="Trade Show" Value="{!Opportunity.CampaignID}" />
            </apex:pageblocksection>

        </apex:pageBlock>
             <center>
             
             <html>
                <head>
                    <script type="text/javascript">
                    function goBack()
                      {
                      window.history.back()
                      }
                    </script>
                </head>
                <body>
                <input type="button" class="btn" value="Back" onclick="goBack()" />
                </body>
            </html>
                <apex:commandButton value="Next Step" action="{!SavePage}" style="width:20%" />
                <apex:commandbutton value="Cancel" action="{!cancel}" />
            </center>
    </apex:form>
</apex:page>

 

 

Below is my Extension:

 

public class CloseOppRedirect2{

    //Get the Account Fields
    public Account act {get; set;}
    
    ApexPages.StandardController controller;
    List<Opportunity> opps = new List<Opportunity>();
    public CloseOppRedirect2(ApexPages.StandardController controller){
        Opportunity o = (Opportunity)controller.getRecord();
        o.StageName = '5 - Closed Won';
        o.CloseDate = Date.today();
        this.controller = controller;
        
        o = [Select ID,
                    AccountID,
                    Account.Name,
                    Account.Phone,
                    Account.Phone_2__c,
                    Account.BillingCity, 
                    Account.BillingStreet, 
                    Account.BillingState, 
                    Account.BillingCountry,
                    Account.Website,
                    Account.Email__c,
                    Account.Referred_By_MB_Client__c
                    from Opportunity where ID=:controller.getRecord().Id limit 1];
        
        act = o.Account;
        
        if(o.ID != null){
            opps.add(o);
        }
        
     }
     
     
    public PageReference SavePage() {
    
        Opportunity o = (Opportunity)controller.getRecord();
        update act;
        if(act.Referred_By_MB_Client__c == 'None' && o.LeadSource == 'Another Client'){
            o.LeadSource = 'Word of Mouth';
            opps.remove(0);
            opps.add(o);
        }
            update opps;
                
        controller.save();
        
        List<Opportunity> opp = [Select AccountID, Reason_Won__c, Hosting__c from Opportunity where ID =:ApexPages.CurrentPage().getParameters().get('id')];
        if(opp.size() > 0 && opp[0].Hosting__c > 0){
            PageReference SavePage= new PageReference('/apex/closeopp3?id='+opp[0].AccountID);
            SavePage.setRedirect(true);
            return SavePage;
        }
        else{
            if(opp.size() > 0 && opp[0].Hosting__c == 0){
                PageReference SavePage= new PageReference('/' +opp[0].ID);
                SavePage.setRedirect(true);
                return SavePage;
            }
            else{
                return null;
            }
        }
        
   }
        
}

 

Any help is greatly appreciated.  

We change the owner of our opportunities when the owner changes from one certain stage to another, but need to have the previous owner for a report. I want to put the name of the previous owner in a custom lookup field that I created when the stage changes from "App In" to something else. I'm really a beginner with triggers, can anyone help? I've tried doing it with workflows and it doesn't allow me to do it. I'm thinking I need an apex trigger.

 

Any ideas?

I have a controller extension for a VF page that I got 60% coverage on.  The only part that I am having issues covering is a query of campaigns.  Below is my Class:

 

 1	  public class TradeShowLeads1 {
 2	  
 3	   //Create list for leads
 4	   private final Lead ld;
 5	   List<Lead> lds = new List<Lead>();
 6	   List<CampaignMember> CamMems = new List<CampaignMember>();
 7	   Campaign c1 = [Select ID, Primary_Market__c, Name from Campaign where Campaign_Form__c = 'Form 1' LIMIT 1];
 8	  
 9	   public TradeShowLeads1 (ApexPages.StandardController controller) {
 10	   ld=(Lead)controller.getrecord();
 11	   ld.LeadSource = 'Trade Show';
 12	   ld.Industry = c1.Primary_Market__c;
 13	   ld.Lead_Type__c = 'Inbound';
 14	   }
 15	  
 16	   //create list for Campaign
 17	   Campaign campaign;
 18	   List<Campaign> campaigns;
 19	  
 20	   public List<Campaign> getCampaigns() {
 21	   if(campaigns == null) {
 22	   campaigns = new List<Campaign>();
 23	   campaign=null;
 24	   List<Campaign> campaigns2 = new List<Campaign>();
 25	   campaigns2 = [Select Name from Campaign where Campaign_Form__c = 'Form 1' LIMIT 1];
 26	   for(Campaign campaign:campaigns2) {
 27	   campaigns.add(campaign);
 28	   }
 29	   }
 30	   return campaigns;
 31	   }
 32	  
 33	   public PageReference TradeShowLeads1() {
 34	   if(ld.get('Id') == null){
 35	   lds.add(ld);
 36	   CampaignMember mem = new CampaignMember (campaignid=c1.id, leadid=ld.id);
 37	   CamMems.add(mem);
 38	   }
 39	  
 40	   insert lds;
 41	   insert CamMems;
 42	   PageReference RedirectLead = new PageReference('/apex/tradeshow1');
 43	   redirectLead.setRedirect(true);
 44	   return RedirectLead;
 45	  
 46	  
 47	   }
 48	  
 49	  
 50	  
 51	  }

 

Below is my test class:

 

public class TestTradeShowExtension1 {

    static testMethod void testTradeShow1() {
    
        //create the Lead
        Lead testL = new Lead(LastName = 'test',
                              Company = 'test',
                              Industry = 'test',
                              LeadSource = 'Online Search',
                              Lead_Type__c = 'inbound',
                              Contact_Method__c = 'Phone');
        insert testL;
        
        //create Campaign
        Campaign testC = new Campaign(Name = 'test',
                                      StartDate = Date.today(),
                                      Primary_Market__c = 'Fitness');
        insert testC;
        
        
        //create standard controller for lead
        ApexPages.StandardController stdCon = new ApexPages.StandardController(testL);
        
        //create controller extension with stdCon
        TradeShowLeads1 ext = new TradeShowLeads1(stdCon);
        
        //assert campaign member was created
        
        //assert the pagereference worked
        ext.TradeShowLeads1();

     }
}

 

When I run the test I am missing coverage on lines 20 - 30 and lines 35-37.  Any help would be greatly appreciated.  

I have the below trigger in my Org.  It automatically submits an approval to the manager when specific leads are marked as Lead Status - Disqualified.  

 

trigger LeadSubmitApproval on Lead (after update) {
 
ID RepID= [Select ID from Profile where Name = 'MINDBODY Sales Representative' Limit 1].id;
ID SarahID= [Select ID from Profile where Name = 'International Associate Manager' Limit 1].id;

    for (Integer i = 0; i < Trigger.new.size(); i++) {
 
        if (Trigger.old[i].Status != 'Disqualified' && 
        	Trigger.new[i].Status == 'Disqualified' && 
        	(UserInfo.getProfileID() == RepID || UserInfo.getProfileId() == SarahID) && 
        	(Trigger.new[i].Lead_Type__c == 'Inbound' || Trigger.new[i].LeadSource == 'Trade Show')) {

            // create the new approval request to submit
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted DQ Lead for approval. Please approve.');
            req.setObjectId(Trigger.new[i].Id);
            
            // submit the approval request for processing
            Approval.ProcessResult result = Approval.process(req);
            System.assert(result.isSuccess());
            
            // display if the reqeust was successful
            System.debug('Submitted for approval successfully: '+result.isSuccess());
 
        }
 
    }
 
}

 

 

It has been working great for a few months, but has all of the sudden it is throwing the below error:

 

Apex script unhandled trigger exception by user/organization: 00560000001Np28/00D60000000J1xm 

LeadSubmitApproval: execution of AfterUpdate

caused by: System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process.: []

 

Trigger.LeadSubmitApproval: line 19, column 45

 

Can anyone help me understand why this all of the sudden started throwing errors ??  (Line 19, col 45 is highlighted in red above)