• John Neilan 2
  • NEWBIE
  • 160 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 58
    Questions
  • 67
    Replies
Hello,

I have a bit of a unique situation.  Currently, I have an email template set up that uses a Visualforce page as the template.  The VF page is necessary because the template loops through Cases related to an Account that match a particular criteria.  I then have an Email Alert WFR set up to fire when a date is reached.  The WFR fires on the Account, and I have mutliple lookup fields on the Account to Contacts that match a particular type.  All this works fine, however, there is no tracking of the email via the Email Alert, so any email responses have to be linked back into SFDC manually.

My question is whether or not I can accomplish this same process using Apex code rather than a WFR Email Alert, and if using the code would then allow me to track responses for each Case listed in the email template, using something like the "ref: {!Case.Id}" code?  My template is below:

Email Template:
<messaging:emailTemplate recipientType="Contact"
  relatedToType="Account"
  subject="Notification - {!relatedTo.Name} - {!TODAY()}"
  replyTo="test@test.com">
  <messaging:htmlEmailBody >
    <html>
      <body>
        <STYLE type="text/css">
          TH {font-size: 11px; font-face: arial;background: #CCCCCC;
               border-width: 1;  text-align: center } 
          TD  {font-size: 11px; font-face: verdana } 
          TABLE {border: solid #CCCCCC; border-width: 1}
          TR {border: solid #CCCCCC; border-width: 1}
        </STYLE>
        <font face="arial" size="2">
          <p>Hi {!relatedTo.Contact_4__r.Name},</p>
          <p>We would like to inform you of the following issue(s) found on {!relatedTo.Name} and would appreciate your immediate attention to this matter.<br/></p>
          <table border="0" columns="2">
            <apex:variable value="{!1}" var="ViolationNum"/>
            <apex:repeat var="cx" value="{!relatedTo.Cases}">
            <apex:outputPanel rendered="{!IF(cx.Escalate_to_Client__c = TRUE && relatedTo.Client_Escalate_Date__c = cx.Client_Escalated__c,TRUE,FALSE)}">
                <tr>
                    <td colspan="2"><b><u>Violation #<apex:outputText value="{!FLOOR(ViolationNum)}"/></u></b></td>
                    <apex:variable var="ViolationNum" value="{!ViolationNum + 1}"/>
                </tr>
                <tr>
                    <td width="17%">Case Number:</td>
                    <td width="83%">{!cx.CaseNumber}</td>
                </tr>
                <tr>
                    <td width="17%">Violation Type:</td>
                    <td width="83%">{!cx.Type_of_Violation__c}</td>
                </tr>
                <tr>
                    <td width="17%">Description of Violation:</td>
                    <td width="83%">{!cx.Compliance_Violation_Description__c}</td>
                </tr>
                <br/><br/>
            </apex:outputPanel>
            </apex:repeat>
            </Table>

            Please respond to this email by 
                <b><apex:outputText value="{0, date, MMMM d','  yyyy}">
                    <apex:param value="{!CASE( MOD( TODAY() - DATE(1900, 1, 7), 7),0, TODAY() + 2,1, TODAY() + 2,2, TODAY() + 2,3, TODAY() + 2,4, TODAY() + 4,5, TODAY() + 4,6, TODAY() + 3,null)}"/>
                </apex:outputText></b>
            indicating whether the above has been resolved so that we may review and confirm complete resolution.<p/>

            Thank you for your prompt attention to this matter!<p/>
             
        </font>
      </body>
    </html>
  </messaging:htmlEmailBody> 
</messaging:emailTemplate>

 
Hello,

I am having trouble wrapping my head around something.  We are setting up a Web-To-Case integration where a Case will be created when an internal system receives an alert.  The Case will have an internal identifier field that is also populated on the Case record.  All that is fine, however, if multiple alerts occur for Cases with the same internal identifier, I need to create the case via web-to-case, search for any open cases with that internal identifier, add a new custom object record linked to the existing case, and then delete the new case.  The end result would be 1 open case per identifier, with potentially multiple custom object records.  Can anyone suggest how I can do this with a trigger or some other method?
I have a requirement where an internal system is using web-to-case to create new cases when fraud alerts occur. However, there could be multiple fraud alerts per client and we do not want a separate case for each, we want the alerts for the same client to be grouped in any existing open case (there will only be 1 fraud case open at a time). Is this possible using web-to-case? If not, does anyone know how we can accomplish this?
I have a Visualforce email template that is being used as part of a WFR Email Alert. I have multiple recipients in the email alert. How would I get my VF template to email each of these recipients?

VF Template:
 
<messaging:emailTemplate recipientType="Contact"
  relatedToType="Account"
  subject="Notification - {!relatedTo.Name} - {!TODAY()}"
  replyTo="test@test.com">
  <messaging:htmlEmailBody >
    <html>
      <body>
        <STYLE type="text/css">
          TH {font-size: 11px; font-face: arial;background: #CCCCCC;
               border-width: 1;  text-align: center } 
          TD  {font-size: 11px; font-face: verdana } 
          TABLE {border: solid #CCCCCC; border-width: 1}
          TR {border: solid #CCCCCC; border-width: 1}
        </STYLE>
        <font face="arial" size="2">
          <p>Hi {!recipient.Name},</p>
          <p>We would like to inform you of the following issue(s) found on {!relatedTo.Name}.&nbsp;We would appreciate your immediate attention to this matter.<br/></p>
          <table border="0" columns="2">
            <apex:variable value="{!1}" var="ViolationNum"/>
            <apex:repeat var="cx" value="{!relatedTo.Cases}">
            <apex:outputPanel rendered="{!IF(cx.Status = 'Escalated Internal - Past Due' && cx.Escalate_to_Client__c = TRUE,TRUE,FALSE)}">
                <tr>
                    <td colspan="2"><b><u>Violation #<apex:outputText value="{!FLOOR(ViolationNum)}"/></u></b></td>
                    <apex:variable var="ViolationNum" value="{!ViolationNum + 1}"/>
                </tr>
                <tr>
                    <td width="25%">Case Number</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.CaseNumber}</td>
                </tr>
                <tr>
                    <td width="25%">Site Name(s)</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Sample_URLs__c}</td>
                </tr>
                <tr>
                    <td width="25%">Violation Type</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Type_of_Violation__c}</td>
                </tr>
                <tr>
                    <td width="25%">Description of Violation</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Compliance_Violation_Description__c}</td>
                </tr>
                <br/><br/>
            </apex:outputPanel>
            </apex:repeat>
            </Table>

            Please respond to this email by 
                <b><apex:outputText value="{0, date, MMMM d','  yyyy}">
                    <apex:param value="{!CASE( MOD( TODAY() - DATE(1900, 1, 7), 7),0, TODAY() + 2,1, TODAY() + 2,2, TODAY() + 2,3, TODAY() + 2,4, TODAY() + 4,5, TODAY() + 4,6, TODAY() + 3,null)}"/>
                </apex:outputText></b>.<p/>

            Thank you for your prompt attention to this matter!<br/><p/>
        </font>
      </body>
    </html>
  </messaging:htmlEmailBody> 
</messaging:emailTemplate>

 
I have a custom field on the Opportunity which right now is a hyperlink for an embedded image (help question mark). The hyperlink works fine, but it opens a new tab in the browser to my VF page. Instead, I would like the field to display my visualforce page when the user hovers over the image in my custom field. Does anyone know if this is possible? I need to use this approach instead of the standard help text because I have over 1,000 characters to display.

Current Custom Field:
HYPERLINK("/apex/VF_LostHelpTxt",IMAGE("/img/alohaSkin/help_orange.png","",25,25))

 
I have a VF email template set on the Accounts object that compiles the related Cases to an Account that meet a certain criteria. I would like to send this template to any Contacts related to the Account that are marked as true via a custom checkbox field on the Contact record. Is there a way to do this with the VF template below?

VF Email Template:
 
<messaging:emailTemplate recipientType="Contact"
  relatedToType="Account"
  subject="Non-Compliance Notification - {!relatedTo.Name} - {!TODAY()}"
  replyTo="test@test.com">
  <messaging:htmlEmailBody >
    <html>
      <body>
        <STYLE type="text/css">
          TH {font-size: 11px; font-face: arial;background: #CCCCCC;
               border-width: 1;  text-align: center } 
          TD  {font-size: 11px; font-face: verdana } 
          TABLE {border: solid #CCCCCC; border-width: 1}
          TR {border: solid #CCCCCC; border-width: 1}
        </STYLE>
        <font face="arial" size="2">
          <p>Hi {!Recipient.Name},</p>
          <p>Text here......<br/></p>
          <table border="0" columns="2">
            <apex:variable value="{!1}" var="ViolationNum"/>
            <apex:repeat var="cx" value="{!relatedTo.Cases}">
            <apex:outputPanel rendered="{!IF(cx.Status = 'Escalated',TRUE,FALSE)}">
                <tr>
                    <td colspan="2"><b><u>Violation #<apex:outputText value="{!FLOOR(ViolationNum)}"/></u></b></td>
                    <apex:variable var="ViolationNum" value="{!ViolationNum + 1}"/>
                </tr>
                <tr>
                    <td width="25%">Site Name(s)</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Sample_URLs__c}</td>
                </tr>
                <tr>
                    <td width="25%">Sample URL</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Sample_URLs__c}</td>
                </tr>
                <tr>
                    <td width="25%">Violation Type</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Type_of_Violation__c}</td>
                </tr>
                <tr>
                    <td width="25%">Description of Violation</td>
                    <td width="75%">&nbsp;&nbsp;&nbsp;{!cx.Compliance_Violation_Description__c}</td>
                </tr>
                <br/><br/>
            </apex:outputPanel>
            </apex:repeat>
            </Table>

            Please respond to this email by 
                <apex:outputText value="{0, date, MMMM d','  yyyy}">
                    <apex:param value="{!TODAY()+7}"/>
                </apex:outputText>
           <br/>
        </font>
      </body>
    </html>
  </messaging:htmlEmailBody> 
</messaging:emailTemplate>

 
Hello,

I am trying to invoke an Apex method from a Process that will email a certain set of Contacts associated with an Account that gets marked via a custom field.  I have the class below, but nothing is happening when I change the Account.  The Process is fired, but nothing happens from the Apex.  Does anyone know why?
 
public class VF_ClassComplCustEmail {

    @InvocableMethod
    public static void SendEmailCompl(List<Id> acctId){

    EmailTemplate templateId = [SELECT Id
                                FROM EmailTemplate
                                WHERE Id = '00XL0000000IePcMAK'];
                                
    List<Contact> complCont = [SELECT Id, Non_Comp_Contact__c, Email
                               FROM Contact
                               WHERE Id in: acctId AND Non_Compl_Contact__c = TRUE];


    List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
        for(contact con : complCont)
        {
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setTemplateID(templateId.Id); 
                mail.setTargetObjectId(con.id);
                mail.setSaveAsActivity(false);
                allmsg.add(mail);
        }
    Messaging.sendEmail(allmsg,false);
    
    }
}

 
I am having an issue where I need to override the standard New/Edit/View buttons on Cases with Visualforce pages.  These pages are just re-directs as I need to have 1 Case record type that is replaced by custom VF pages.  All other record types should go to the standard URLs that come up when the standard buttons are clicked.  The issue I am having is that overriding the standard buttons also disables inline editing, which cannot happen.  Does anyone know of a way to allow inline editing when standard buttons are disabled?  I know how to do it on the custom VF pages, but not on the standard pages.  Below is one of the VF pages overriding the View button, but it does not allow inline editing:

VF Page (View Button Override):
<apex:page standardcontroller="Case" extensions="VF_Controller_CaseView" action="{!CaseRedirect}">
    <apex:detail inlineEdit="true" relatedList="true"/>
</apex:page>
Controller:
//Controller to Override Case detail view to allow for Account Services VF pages but maintain standard pgs for all other cases
public with sharing class VF_Controller_CaseView{

public Case c1;

    public VF_Controller_CaseView(ApexPages.StandardController controller){
        this.c1 = (Case)controller.getRecord();
    }


    public PageReference CaseRedirect() {
        
        Case recType = [SELECT Id, RecordType.Name
                        FROM Case
                        WHERE Id =: c1.Id];
        
        if(recType.RecordType.Name == 'AcctSvcs'){
            PageReference pageRef = new PageReference('/apex/VF_CaseView?id=' + recType.Id);
            return pageRef;
        }
        else{
            PageReference pageRef2 = new PageReference('/' + recType.Id + '?nooverride=1');
            return pageRef2;
        }
    }
}


 
Hello,

I have 3 fairly simple custom controllers that redirect users s to various pages based upon selection of record type when creating a new Case from an Account or the Case tab, editing it, and viewing it.  The underlyiung VF pages for these controllers are simple redirects that override the standard buttons. I am trying to develop a test class to cover the controllers.  so far I have 2 of the controllers covered 89% and 75%, but I cannot figure out why the other lines are not being covered.  For Controller 1, my test class covers everything except Lines 22 -24.  For Controller 2 my test class covers everything except lines 11 and 12.  Can anyone help me get to 100% coverage and explain why they are not being covered?

Controller 1:
public with sharing class VF_Controller_CaseAcctSvcsNew{

public Case c1;

    public VF_Controller_CaseAcctSvcsNew(ApexPages.StandardController controller){
        this.c1 = (Case)controller.getRecord();
    }

    public PageReference CaseRedirect() {
        if(ApexPages.currentPage().getParameters().get('RecordType') == '012L0000000DPwQ'){
            DateTime d = Date.Today();
            c1.OwnerId='00GL0000001SUhm';
            c1.Due_Date_Original__c = System.now() + 1;
            c1.Status = 'New';
            PageReference pageRef = new PageReference('/apex/VF_AcctSvcsNew');
            return pageRef;
        }
        else if(ApexPages.currentPage().getParameters().get('AccountId') == null){
            PageReference pageRef2 = new PageReference('https://cs8.salesforce.com/500/e?RecordType='+c1.RecordTypeId+'&ent=Case&nooverride=1');
            return pageRef2;
        }
        else{
            PageReference pageRef3 = new PageReference('https://cs8.salesforce.com/500/e?def_account_id='+c1.AccountId+'&RecordType='+c1.RecordTypeId+'&ent=Case&nooverride=1');
            return pageRef3;
        }
    }
}
Controller 2:
public class VF_Controller_CaseAcctSvcsEdit {

    public Case c1;

    public VF_Controller_CaseAcctSvcsEdit(ApexPages.StandardController controller) {
        this.c1 = (Case)controller.getRecord();
    }

    public PageReference AcctSvcsEditRedirect() {
        if (c1.RecordTypeId == '012L0000000DPwQ') {
            PageReference pageRef = new PageReference('/apex/VF_AcctSvcsEdit?id='+c1.Id);
            return pageRef;
        }
        else {
            PageReference pageRef = new PageReference('https://cs8.salesforce.com/' + c1.id + '/e?retURL=%2F' + c1.id + '&nooverride=1');
            return pageRef;
        }
    }
}

Test Class:
@IsTest (SeeAllData=true)
private class TestControllerAcctSvcsCaseNew{

    static testMethod void testASCcontroller1(){

        Account acct1 = TestCreateRecords.createAcct(0);
        insert acct1;
    
        Contact cont1 = TestCreateRecords.createContNew(acct1.Id);
        insert cont1;

        Case case1 = new Case();
            case1.AccountId = acct1.Id;
            case1.OwnerId = '00G57000005X4w4';
            case1.Due_Date_Original__c = System.now() + 1;
            case1.Status = 'New';
        insert case1;


        Test.setCurrentPageReference(new PageReference('Page.myPage1'));
        System.currentPageReference().getParameters().put('RecordType', '01257000000kg5H');

        ApexPages.StandardController cs1 = new ApexPages.standardController(case1);
        VF_Controller_CaseAcctSvcsNew cs1a = new VF_Controller_CaseAcctSvcsNew(cs1);

        cs1a.c1 = case1;
        cs1a.CaseRedirect();

        VF_Controller_CaseAcctSvcsEdit cs11a = new VF_Controller_CaseAcctSvcsEdit(cs1);

        cs11a.c1 = case1;
        cs11a.AcctSvcsEditRedirect();

 
//VF_Controller_CaseAcctSvcsNew - No associated Account
        Test.setCurrentPageReference(new PageReference('Page.myPage2'));
        System.currentPageReference().getParameters().put('RecordType', null);

        ApexPages.StandardController cs2 = new ApexPages.standardController(case1);
        VF_Controller_CaseAcctSvcsNew cs2a = new VF_Controller_CaseAcctSvcsNew(cs2);

        cs2a.c1 = case1;
        cs2a.CaseRedirect();
        
        VF_Controller_CaseAcctSvcsEdit cs2b = new VF_Controller_CaseAcctSvcsEdit(cs2);

        cs2b.c1 = case1;
        cs2b.AcctSvcsEditRedirect();


//VF_Controller_CaseAcctSvcsNew - All other conditions
        ApexPages.StandardController cs3 = new ApexPages.standardController(case1);
        VF_Controller_CaseAcctSvcsNew cs3a = new VF_Controller_CaseAcctSvcsNew(cs3);

        cs3a.c1 = case1;
        cs3a.CaseRedirect();


    }
}





 
Hello,

I am overriding my New Case button with a VF page. I am trying to pre-populate fields on Cases created with a certain record type with values from the Account (when the Case is created from the Account), but I'm not sure how to pull them into the controller. Can anyone help?

Controller:
//Controller to Override Case creation to allow for Custom VF pages for 1 record type but maintain standard pgs for all other cases
public with sharing class VF_Controller_CaseAcctSvcsNew{

public Case c1;

    public VF_Controller_CaseAcctSvcsNew(ApexPages.StandardController controller){
        this.c1 = (Case)controller.getRecord();
    }


    public PageReference CaseRedirect() {
        if(ApexPages.currentPage().getParameters().get('RecordType') == '012L0000000DPwQ'){
            DateTime d = Date.Today();
            c1.OwnerId='00GL0000001SUhm';
            c1.Use_Case__c = 'Ad Hoc';
            c1.Case_Reason__c = 'Screen';
            c1.Due_Date_AcctSvcs__c = System.now() + 24;
            c1.Status = 'New';
//            c1.Subject = 'Screen Request for ' + ApexPages.currentPage().getParameters().get('AccountId') + ' ' + d.format('MM/dd/yyyy');
            PageReference pageRef = new PageReference('/apex/VF_AcctSvcsNew');
            return pageRef;
        }
        else if(ApexPages.currentPage().getParameters().get('AccountId') == null){
            PageReference pageRef2 = new PageReference('https://cs8.salesforce.com/500/e?RecordType='+c1.RecordTypeId+'&ent=Case&nooverride=1');
            return pageRef2;
        }
        else{
            PageReference pageRef3 = new PageReference('https://cs8.salesforce.com/500/e?def_account_id='+c1.AccountId+'&RecordType='+c1.RecordTypeId+'&ent=Case&nooverride=1');
            return pageRef3;
        }
    }
}
Hello,

I have a WFR set up that is set up on a time-based event on the Account object.  When the rule fires, I want an email alert to go out to any Contact records associated to the Account that have a custom checkbox field checked off.  My email template is a Visualforce page.  Does anyone know of a way I can send out an email alert trhough a WFR to multiple Contacts with a checkbox?
Hello,

I am trying to see if I can pull Contacts into a Case when it is created.  When a Case is created under a certain record type, I want to be able to pull in any Contacts marked as Primary that are associated with the Account that the Case is also associated to.  Does anyone know if this is possible and have any examples of how to do it?  I need this because I am also setting up a WFR Email alert to send to all the primary contacts for an Account.  Thanks,
Does anyone know how I can pull Case related lists into a custom Visualforce page? I know I can use the syntax:
<apex:relatedList list="NotesAndAttachments"/>
in other pages, however, I cannot get it to work on Cases. I am looking to add the related lists for:
Emails
Related Cases
Solutions
Case Comments
Open Activities
Case History
Attachments


Any ideas?  Thanks.
Hello,

I am trying to redirect users to a VF page after the record type is chosen when creating a new Case.  If a particular Record Type is chosen, the use should be brought to a VF page, anything else should default to the normal behavior after a Record Type is selected.  I have the VF page below overriding the New bustton on Cases, and the controller to go with it.  The users are being re-directed to the VF page, but the other part is not working as it is still remaning on the VF page re-direct.  Can anyone help me get the default behavior in the controller?  Thanks,

VF Page:
<apex:page standardcontroller="Case" extensions="VF_Controller_CasePgLayout" action="{!CaseRedirect}"/>

Controller:
//Controller to Override Case creation
public with sharing class VF_Controller_CasePgLayout{

public Case c1;

    public VF_Controller_CasePgLayout(ApexPages.StandardController myController){
        this.c1 = (Case)myController.getRecord();
    }

    public PageReference CaseRedirect() {
        if(c1.RecordTypeId =='012L0000000DPwQ'){
            PageReference pageRef = new PageReference('/apex/VF_CaseDetail');
            return pageRef;
        }
        else{
            PageReference pageRef2 = new PageReference('/500/e?retURL=%2F'+c1.AccountId+'&def_account_id='+c1.AccountId+'&RecordType='+c1.RecordTypeId+'ent=Case');
            
            return pageRef2;
        }
    }
}

 
Hello,

I have what I think is a very simple request, but I'm struggling with it.  I have a custom field on the Case object called Account ID, which is a text field.  I also have a field called Primary Account, which is a lookup field.  I have a Google form integration that creates a Case when a form is submitted and populates the Account ID with the 15-character Account ID, input by the form submitter.  I want to create a trigger to take that value and populate the Primary Account lookup field with the Account associated with the ID.  Can anyone point me to code that can accomplish this?  Thanks,
Hello,

I have a pretty simple test class on a controller, which worked fine in my developer environment. However, I am now moving it to a sandbox and I'm running into an error:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountTrigger: execution of BeforeInsert caused by: System.NullPointerException: Argument cannot be null.
Class.TriggerHandlerAccount.mapRegions: line 94, column 1
Class.TriggerHandlerAccount.beforeInsert: line 19, column 1
Trigger.AccountTrigger: line 6, column 1:


I know it's being caused by a trigger class that was created by a vendor for my organization, but I can'f figure out what I need to change in my test classes to avoid the error. Can anyone help?

Test Class for Controller:
@Istest
private class TestControllerShortForm
{
    static testMethod void testSFController1()
    {    
        Account acct1 = TestCreateRecords.createAcct(0);
        insert acct1;

        Opportunity opp1 = TestCreateRecords.createOppNewSF(acct1.Id);
        insert opp1;

        Short_Form__c ESF1 = new Short_Form__c();
            ESF1.Sales_Representative__c = acct1.AM_owner__c;
            ESF1.Opportunity__c = opp1.Id;
            ESF1.Partner_Contact__c = '00337000006fBvQ';
            ESF1.Term_Length__c = 12;
            ESF1.Term_Metric__c = 'Months';
            ESF1.Additional_Terms__c = 'Test Test Test';

        ApexPages.StandardController SF1 = new ApexPages.standardController(opp1);
        VF_ShortFormController SFCont1 = new VF_ShortFormController(SF1);
        SFCont1.ESF.add(ESF1);
        SFCont1.ShortForm();
        SFCont1.save();

    }
}
Class Creating Records for Test Class:
// create and insert a new Account record.
    public static Account createAcct(Integer i){ 

    Account acct = new Account();
        acct.Name = 'Test' + i;
        acct.Language__c = 'English';
        acct.Industry = 'Automotive';
        acct.CurrencyIsoCode = 'USD';
        acct.Legal_Name__c = 'Test' + i;
        acct.Region__c = 'NA-US-NE';
        acct.BillingCity = 'New York';
        acct.BillingState = 'New York';
        acct.BillingCountry = 'United States';

    return acct;

    }


// create and insert a new Opportunity record that has the newly created Account record as its master record.
    public static Opportunity createOppNew (Id acctId){ 
        Opportunity opp2 = new Opportunity();
            opp2.AccountId = acctId;
            opp2.Name = 'Test Opportunity - ';
            opp2.StageName = System.Label.Eng_OppStage3;
            opp2.CloseDate = date.newinstance(2020,1,31);
            opp2.Amount = 1000;
            opp2.Region__c = 'NA-US-NE';
            opp2.Type = 'New Customer';
            opp2.Website_s__c = 'www.test.com; www.test2.com; www.test3.com';
        return opp2;
    }

// create and insert a new Opportunity record that has the newly created Account record as its master record. Used for Short Form.
    public static Opportunity createOppNewSF (Id acctId){ 
        Opportunity opp2a = new Opportunity();
            opp2a.AccountId = acctId;
            opp2a.Name = 'Test Opportunity - ';
            opp2a.StageName = System.Label.Eng_OppStage3;
            opp2a.CloseDate = date.newinstance(2020,1,31);
            opp2a.Amount = 1000;
            opp2a.Region__c = 'NA-US-NE';
            opp2a.Type = 'New Customer';
            opp2a.Website_s__c = 'www.test.com; www.test2.com; www.test3.com';
        return opp2a;
    }
}

Class Throwing Error:​
public with sharing class TriggerHandlerAccount {
    private boolean isExecuting = false;

    public TriggerHandlerAccount(boolean initIsExecuting) {
        isExecuting = initIsExecuting;
    }

    public void beforeInsert(List<Account> newAccounts) {
        setType(newAccounts);
        mapRegions(newAccounts);
        UpdateEnglishName(newAccounts, null);
    }

    public void beforeUpdate(List<Account> newAccounts, map<id, Account> oldAccountMap) {
        mapRegions(newAccounts);
        UpdateEnglishName(newAccounts, oldAccountMap);
    }

    public void afterInsert(List<Account> newAccounts) {
        updateRegionField(newAccounts, 'isInsert', newAccounts.size());
        accountHierarchyLeadSourceCalculation(new List<Account>(), newAccounts, 'isInsert', newAccounts.size());
    }


    private void UpdateEnglishName (List<Account> newAccounts, map<id, Account> oldAccountMap){
        for (Account account : newAccounts) {
            system.debug('oldAccountMap = ' + oldAccountMap);
            system.debug('oldAccountMap = ' + account.English_Account_Name__c);
            if ((oldAccountMap == null && account.English_Account_Name__c == null) ||
            (oldAccountMap != null && account.Name != oldAccountMap.get(account.id).Name && account.English_Account_Name__c == oldAccountMap.get(account.id).English_Account_Name__c))
            FillUpEnglishName(account);
        }
    }

    private void FillUpEnglishName (Account account) {
        if (account.Name == null || account.Name.trim() == '') return;
        String[] chars = account.Name.split('');
        // the 1st element in an Apex '' split is garbage; remove it:
        chars.remove(0);
        System.debug(chars);
        // change a char:
        string SC = SpecialCharacters__c.getInstance().Characters__c;
        boolean english = true;
        for (String c : chars) {
            if (!c.containsAny(SC))
                english = false;
        }
        system.debug('english = ' + english);
        if (english)
            account.English_Account_Name__c = account.Name;
    }


    private void setType(List<Account> newAccounts) {
        // If the Account is created with no Type but was converted from a Lead that had
        //    a Lead Type, set the Type from the Lead Type

        for (Account newAccount: newAccounts) {
            if (newAccount.Lead_Type__c != Null && newAccount.Type == Null) {
                newAccount.Type = newAccount.Lead_Type__c;
            }
        }
    }

    private void mapRegions(List<Account> newAccounts) {
        AccountRegionManager regionManager = new AccountRegionManager();
        Region_Mapper_Settings__c errorMessage = Region_Mapper_Settings__c.getInstance();
        for (Account newAccount: newAccounts) {
            String region = regionManager.getRegion(newAccount.BillingCountry, newAccount.BillingState);
            if (region != null) {
                newAccount.Region__c = region;
            } else {
                newAccount.addError(errorMessage.Invalid_Mapping_Message__c);
            }
        }
    }

    public static Boolean accountHierarchyLeadSourceCalculationEnable = true; 

     private void updateRegionField(List<Account> newAccounts, String triggerEvent, Integer triggerSize) {

        Boolean needUpdateRegion = false;
        map<Id , Account> accountsmap =  new map<Id, Account>();
        List<Account> accounts = new List<Account>();

         for(Integer i = 0; i < triggerSize; i++){
            Account tempaccount = new Account(id = newAccounts[i].id);
            if(triggerEvent == 'isInsert') 
                needUpdateRegion = newAccounts[i].Region__c == '' || newAccounts[i].Region__c == ' ' || newAccounts[i].Region__c == null;

            if (needUpdateRegion) 
            {
                accountsmap.put(newAccounts[i].OwnerId , newAccounts[i]);
            }
         }

         for(User u : [SELECT Id, Region__c FROM User WHERE Id IN :accountsmap.keyset()]){
                   Account tempaccount = new Account(id = accountsmap.get(u.id).id) ; 
                   tempaccount.Region__c = u.Region__c;
                   system.debug('Region to update: '+ tempaccount.Region__c);
                   accounts.add(tempaccount);
         }

         if (!accounts.isempty())
            update accounts;
     }
}

 
Hello,

Does anyone know if it is possible to call a Process from a Visualforce page button?  My situation is that I have a custom object with a Master-Detail relationship to the Opportunity object.  When the user creates a record of the custom object, I want to have a button that would create an associated Case when clicked.  In the past, I have done this via a URL hack, but I would like to use something more scalable like a Process but I'm not sure how to get the button to do this.  Any help is appreciated!
I am trying to populate a field in a Visualforce page for custom object using a controller extension. I would like to populate the field with one value if the User Role of the person creating the record is Sales and another value if they are Account Management. I'm not quite sure of the syntax I need to use to accomplish this in my controller. Can anyone assist?
 
public class VF_CampaignCaseCreateController{
public List<Campaign_Create_Request__c> CCR {get; set;}

    private final Opportunity opp;
    public VF_CampaignCaseCreateController(ApexPages.StandardController myController){
        CCR = new List<Campaign_Create_Request__c>();
            if (!Test.isRunningTest())
            {
            myController.addFields(new List<String>{'Id', 'OwnerId'});
            }
        opp=(Opportunity)myController.getrecord();
    }

    public Campaign_Create_Request__c CCR2 = new Campaign_Create_Request__c();
        public void CampaignCaseCreate(){

            CCR2.Opportunity__c = opp.Id;

            IF($UserRole.Name StartsWith('Sales')){
                CCR2.Sales_Rep__c = $UserRole.Id;
            }
            ELSE{
                CCR2.Sales_Rep__c = null;
            }   

            Opportunity o = [SELECT (SELECT Id, contactId
                                       FROM OpportunityContactRoles
                                       WHERE role = 'Signatory')
                            FROM Opportunity
                            WHERE id = :opp.id];
            CCR2.Primary_User__c = o.opportunityContactRoles.size() != 0 
                                    ? o.opportunityContactRoles[0].contactId  
                                    : null;

            CCR.add(CCR2);
        }
}

 
Hello,

I have a custom controller extension below which pre-populates the Opportunity ID and a Contact Role ID to a Visualforce page for a custom object that has a Master-Detail relationship to the Opportunity object.  I am now trying to create 2 buttons on the VF page that will populate a 3rd custom field, save the custom object record, and re-direct the user to another VF page.  However, when I try to save the code below I get the error:  

Error: VF_CampaignCaseCreateController Compile Error: Initial term of field expression must be a concrete SObject: List<Campaign_Create_Request__c> at line 37 column 9

I'm sure my syntax is incorrect for populating the 3rd field in each method, but I'm not sure how to fix it.
 
public class VF_CampaignCaseCreateController{
    
    public List<Campaign_Create_Request__c> CCR {get; set;}
    
        private final Opportunity opp;
        public VF_CampaignCaseCreateController(ApexPages.StandardController myController){
            CCR = new List<Campaign_Create_Request__c>();
                if (!Test.isRunningTest())
                {
                myController.addFields(new List<String>{'Id', 'OwnerId', 'Owner.Phone'});
                }
            opp=(Opportunity)myController.getrecord();
        }
    
        public Campaign_Create_Request__c CCR2 = new Campaign_Create_Request__c();
            public void CampaignCaseCreate(){
           
                CCR2.Opportunity__c = opp.Id;
    
                Opportunity o = [SELECT (SELECT Id, contactId
                                           FROM OpportunityContactRoles
                                           WHERE role = 'Signatory')
                                FROM Opportunity
                                WHERE id = :opp.id];
                CCR2.Primary_User__c = o.opportunityContactRoles.size() != 0 
                                        ? o.opportunityContactRoles[0].contactId  
                                        : null;
    
                CCR.add(CCR2);
            }
    
    
        public PageReference AdCamp() {
    
            insert CCR;
            CCR.Requested_Action__c = 'Create and Add';
    
               PageReference RetPage = new PageReference('/VF_CampaignCreate_Edit?id=' + CCR[0].id);
            RetPage.setRedirect(true);
            return RetPage; 
        }
    
        public PageReference Camp() {
    
            insert CCR;
            CCR.Requested_Action__c = 'Create Only';
    
               PageReference RetPage = new PageReference('/VF_CampaignCreate_Edit?id=' + CCR[0].id);
            RetPage.setRedirect(true);
            return RetPage; 
        }
    
    }

 
I have a small piece of Javascript that I am using in an embedded VF page on Opportunities. I would like to add a condition to check to see if the RecordType of the Opp is a certain group of values. The code I have below does not work. Can someone help me with the proper syntax for my Record Type line?
 
SFInitial.openWizard = function(){
            if(
                "{!Opportunity.StageName}" === "{!$Label.Eng_OppStage4}" &&
                "{!Opportunity.RecordType}.indexOf('Eng')" > "-1" &&
                "{!Opportunity.Includes__c}" !== "Yes" &&
                {!Opportunity.Stage_To_Contract__c}
            ){
                window.open(
                    "/apex/VFFormInit?Id={!Opportunity.Id}",
                    "newWindow2"
                );
            }

            return this;

 
Hello,

I am overriding my New Case button with a VF page. I am trying to pre-populate fields on Cases created with a certain record type with values from the Account (when the Case is created from the Account), but I'm not sure how to pull them into the controller. Can anyone help?

Controller:
//Controller to Override Case creation to allow for Custom VF pages for 1 record type but maintain standard pgs for all other cases
public with sharing class VF_Controller_CaseAcctSvcsNew{

public Case c1;

    public VF_Controller_CaseAcctSvcsNew(ApexPages.StandardController controller){
        this.c1 = (Case)controller.getRecord();
    }


    public PageReference CaseRedirect() {
        if(ApexPages.currentPage().getParameters().get('RecordType') == '012L0000000DPwQ'){
            DateTime d = Date.Today();
            c1.OwnerId='00GL0000001SUhm';
            c1.Use_Case__c = 'Ad Hoc';
            c1.Case_Reason__c = 'Screen';
            c1.Due_Date_AcctSvcs__c = System.now() + 24;
            c1.Status = 'New';
//            c1.Subject = 'Screen Request for ' + ApexPages.currentPage().getParameters().get('AccountId') + ' ' + d.format('MM/dd/yyyy');
            PageReference pageRef = new PageReference('/apex/VF_AcctSvcsNew');
            return pageRef;
        }
        else if(ApexPages.currentPage().getParameters().get('AccountId') == null){
            PageReference pageRef2 = new PageReference('https://cs8.salesforce.com/500/e?RecordType='+c1.RecordTypeId+'&ent=Case&nooverride=1');
            return pageRef2;
        }
        else{
            PageReference pageRef3 = new PageReference('https://cs8.salesforce.com/500/e?def_account_id='+c1.AccountId+'&RecordType='+c1.RecordTypeId+'&ent=Case&nooverride=1');
            return pageRef3;
        }
    }
}
Hello,

I am trying to redirect users to a VF page after the record type is chosen when creating a new Case.  If a particular Record Type is chosen, the use should be brought to a VF page, anything else should default to the normal behavior after a Record Type is selected.  I have the VF page below overriding the New bustton on Cases, and the controller to go with it.  The users are being re-directed to the VF page, but the other part is not working as it is still remaning on the VF page re-direct.  Can anyone help me get the default behavior in the controller?  Thanks,

VF Page:
<apex:page standardcontroller="Case" extensions="VF_Controller_CasePgLayout" action="{!CaseRedirect}"/>

Controller:
//Controller to Override Case creation
public with sharing class VF_Controller_CasePgLayout{

public Case c1;

    public VF_Controller_CasePgLayout(ApexPages.StandardController myController){
        this.c1 = (Case)myController.getRecord();
    }

    public PageReference CaseRedirect() {
        if(c1.RecordTypeId =='012L0000000DPwQ'){
            PageReference pageRef = new PageReference('/apex/VF_CaseDetail');
            return pageRef;
        }
        else{
            PageReference pageRef2 = new PageReference('/500/e?retURL=%2F'+c1.AccountId+'&def_account_id='+c1.AccountId+'&RecordType='+c1.RecordTypeId+'ent=Case');
            
            return pageRef2;
        }
    }
}

 
Hello,

I have a VF page at the Account level.  The page includes 3 radio buttons.  I am trying to populate 1 of 3 checkbox fields on the Account depending upon the value the user selects in the radio buttons.  I have my page set up to render sections basd upon the radio button selected, and that works great.  However, I cannot figure out how to populate the appropriate checkbox field when the specific radio button is selected.  Can anyone help?
 
<apex:page standardController="Account" tabStyle="Account" id="thePage">

<script>
    function TypeSelect(variable)
    {
        var choice = variable.value;
        if(choice == 'Amp'){
            document.getElementById('layoutAmp').style.display = 'block';
            document.getElementById('layoutEng').style.display = 'none';
            document.getElementById('layoutAge').style.display = 'none';
            document.getElementById('{!$Component.thePage.theForm.AmpVal}').value = true;
        }
        else if(choice == 'Eng'){
            document.getElementById('layoutAmp').style.display = 'none';
            document.getElementById('layoutEng').style.display = 'block';
            document.getElementById('layoutAge').style.display = 'none';
            document.getElementById('{!$Component.thePage.theForm.EngVal}').value = true;
        }
        else{
            document.getElementById('layoutAmp').style.display = 'none';
            document.getElementById('layoutEng').style.display = 'block';
            document.getElementById('{!$Component.thePage.theForm.geVal}').value = true';
        }
    }   
</script>

<style>
    input[type=radio] {margin-left: 100px;}
    .radioClass {margin-left: 25%;}
</style>


<apex:form id="theForm">
    <apex:actionRegion >
        <div class="sectBody">
            <Table width="90%" border="0" cellpadding="0" cellspacing="0" columns="5">
                 <tr>
                     <td colspan="5" class="fieldLabel">
                     <apex:selectRadio layout="lineDirection" styleClass="radioClass" onclick="TypeSelect(this);">
                      <apex:selectOption itemLabel="Amp" itemValue="Amp"></apex:selectOption>
                            <apex:selectOption itemLabel="Eng" itemValue="Eng"></apex:selectOption>
                            <apex:selectOption itemLabel="Age" itemValue="Age"></apex:selectOption>
                     </apex:selectRadio>
                     <apex:actionSupport event="onchange" reRender="checkBox"/>
               </td>
          </tr>\    
     </Table><br/><br/>
        </div>


	<div id="checkBox">
    	<apex:inputField id="AmpVal" value="{!Account.Amp_Account__c}" />
    	<apex:inputField id="EngVal" value="{!Account.Eng_Account__c}" />
        <apex:inputField id="AgeVal" value="{!Account.Age_Account__c}" />
    </div>

 
Hello,

I have a bit of a unique situation.  Currently, I have an email template set up that uses a Visualforce page as the template.  The VF page is necessary because the template loops through Cases related to an Account that match a particular criteria.  I then have an Email Alert WFR set up to fire when a date is reached.  The WFR fires on the Account, and I have mutliple lookup fields on the Account to Contacts that match a particular type.  All this works fine, however, there is no tracking of the email via the Email Alert, so any email responses have to be linked back into SFDC manually.

My question is whether or not I can accomplish this same process using Apex code rather than a WFR Email Alert, and if using the code would then allow me to track responses for each Case listed in the email template, using something like the "ref: {!Case.Id}" code?  My template is below:

Email Template:
<messaging:emailTemplate recipientType="Contact"
  relatedToType="Account"
  subject="Notification - {!relatedTo.Name} - {!TODAY()}"
  replyTo="test@test.com">
  <messaging:htmlEmailBody >
    <html>
      <body>
        <STYLE type="text/css">
          TH {font-size: 11px; font-face: arial;background: #CCCCCC;
               border-width: 1;  text-align: center } 
          TD  {font-size: 11px; font-face: verdana } 
          TABLE {border: solid #CCCCCC; border-width: 1}
          TR {border: solid #CCCCCC; border-width: 1}
        </STYLE>
        <font face="arial" size="2">
          <p>Hi {!relatedTo.Contact_4__r.Name},</p>
          <p>We would like to inform you of the following issue(s) found on {!relatedTo.Name} and would appreciate your immediate attention to this matter.<br/></p>
          <table border="0" columns="2">
            <apex:variable value="{!1}" var="ViolationNum"/>
            <apex:repeat var="cx" value="{!relatedTo.Cases}">
            <apex:outputPanel rendered="{!IF(cx.Escalate_to_Client__c = TRUE && relatedTo.Client_Escalate_Date__c = cx.Client_Escalated__c,TRUE,FALSE)}">
                <tr>
                    <td colspan="2"><b><u>Violation #<apex:outputText value="{!FLOOR(ViolationNum)}"/></u></b></td>
                    <apex:variable var="ViolationNum" value="{!ViolationNum + 1}"/>
                </tr>
                <tr>
                    <td width="17%">Case Number:</td>
                    <td width="83%">{!cx.CaseNumber}</td>
                </tr>
                <tr>
                    <td width="17%">Violation Type:</td>
                    <td width="83%">{!cx.Type_of_Violation__c}</td>
                </tr>
                <tr>
                    <td width="17%">Description of Violation:</td>
                    <td width="83%">{!cx.Compliance_Violation_Description__c}</td>
                </tr>
                <br/><br/>
            </apex:outputPanel>
            </apex:repeat>
            </Table>

            Please respond to this email by 
                <b><apex:outputText value="{0, date, MMMM d','  yyyy}">
                    <apex:param value="{!CASE( MOD( TODAY() - DATE(1900, 1, 7), 7),0, TODAY() + 2,1, TODAY() + 2,2, TODAY() + 2,3, TODAY() + 2,4, TODAY() + 4,5, TODAY() + 4,6, TODAY() + 3,null)}"/>
                </apex:outputText></b>
            indicating whether the above has been resolved so that we may review and confirm complete resolution.<p/>

            Thank you for your prompt attention to this matter!<p/>
             
        </font>
      </body>
    </html>
  </messaging:htmlEmailBody> 
</messaging:emailTemplate>

 
Hello,

I am having trouble wrapping my head around something.  We are setting up a Web-To-Case integration where a Case will be created when an internal system receives an alert.  The Case will have an internal identifier field that is also populated on the Case record.  All that is fine, however, if multiple alerts occur for Cases with the same internal identifier, I need to create the case via web-to-case, search for any open cases with that internal identifier, add a new custom object record linked to the existing case, and then delete the new case.  The end result would be 1 open case per identifier, with potentially multiple custom object records.  Can anyone suggest how I can do this with a trigger or some other method?
Hello,

I am trying to invoke an Apex method from a Process that will email a certain set of Contacts associated with an Account that gets marked via a custom field.  I have the class below, but nothing is happening when I change the Account.  The Process is fired, but nothing happens from the Apex.  Does anyone know why?
 
public class VF_ClassComplCustEmail {

    @InvocableMethod
    public static void SendEmailCompl(List<Id> acctId){

    EmailTemplate templateId = [SELECT Id
                                FROM EmailTemplate
                                WHERE Id = '00XL0000000IePcMAK'];
                                
    List<Contact> complCont = [SELECT Id, Non_Comp_Contact__c, Email
                               FROM Contact
                               WHERE Id in: acctId AND Non_Compl_Contact__c = TRUE];


    List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
        for(contact con : complCont)
        {
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setTemplateID(templateId.Id); 
                mail.setTargetObjectId(con.id);
                mail.setSaveAsActivity(false);
                allmsg.add(mail);
        }
    Messaging.sendEmail(allmsg,false);
    
    }
}

 
Hello,

I am trying to see if I can pull Contacts into a Case when it is created.  When a Case is created under a certain record type, I want to be able to pull in any Contacts marked as Primary that are associated with the Account that the Case is also associated to.  Does anyone know if this is possible and have any examples of how to do it?  I need this because I am also setting up a WFR Email alert to send to all the primary contacts for an Account.  Thanks,
Hello,

I am trying to redirect users to a VF page after the record type is chosen when creating a new Case.  If a particular Record Type is chosen, the use should be brought to a VF page, anything else should default to the normal behavior after a Record Type is selected.  I have the VF page below overriding the New bustton on Cases, and the controller to go with it.  The users are being re-directed to the VF page, but the other part is not working as it is still remaning on the VF page re-direct.  Can anyone help me get the default behavior in the controller?  Thanks,

VF Page:
<apex:page standardcontroller="Case" extensions="VF_Controller_CasePgLayout" action="{!CaseRedirect}"/>

Controller:
//Controller to Override Case creation
public with sharing class VF_Controller_CasePgLayout{

public Case c1;

    public VF_Controller_CasePgLayout(ApexPages.StandardController myController){
        this.c1 = (Case)myController.getRecord();
    }

    public PageReference CaseRedirect() {
        if(c1.RecordTypeId =='012L0000000DPwQ'){
            PageReference pageRef = new PageReference('/apex/VF_CaseDetail');
            return pageRef;
        }
        else{
            PageReference pageRef2 = new PageReference('/500/e?retURL=%2F'+c1.AccountId+'&def_account_id='+c1.AccountId+'&RecordType='+c1.RecordTypeId+'ent=Case');
            
            return pageRef2;
        }
    }
}

 
Hello,

I have what I think is a very simple request, but I'm struggling with it.  I have a custom field on the Case object called Account ID, which is a text field.  I also have a field called Primary Account, which is a lookup field.  I have a Google form integration that creates a Case when a form is submitted and populates the Account ID with the 15-character Account ID, input by the form submitter.  I want to create a trigger to take that value and populate the Primary Account lookup field with the Account associated with the ID.  Can anyone point me to code that can accomplish this?  Thanks,
Hello,

I have a pretty simple test class on a controller, which worked fine in my developer environment. However, I am now moving it to a sandbox and I'm running into an error:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountTrigger: execution of BeforeInsert caused by: System.NullPointerException: Argument cannot be null.
Class.TriggerHandlerAccount.mapRegions: line 94, column 1
Class.TriggerHandlerAccount.beforeInsert: line 19, column 1
Trigger.AccountTrigger: line 6, column 1:


I know it's being caused by a trigger class that was created by a vendor for my organization, but I can'f figure out what I need to change in my test classes to avoid the error. Can anyone help?

Test Class for Controller:
@Istest
private class TestControllerShortForm
{
    static testMethod void testSFController1()
    {    
        Account acct1 = TestCreateRecords.createAcct(0);
        insert acct1;

        Opportunity opp1 = TestCreateRecords.createOppNewSF(acct1.Id);
        insert opp1;

        Short_Form__c ESF1 = new Short_Form__c();
            ESF1.Sales_Representative__c = acct1.AM_owner__c;
            ESF1.Opportunity__c = opp1.Id;
            ESF1.Partner_Contact__c = '00337000006fBvQ';
            ESF1.Term_Length__c = 12;
            ESF1.Term_Metric__c = 'Months';
            ESF1.Additional_Terms__c = 'Test Test Test';

        ApexPages.StandardController SF1 = new ApexPages.standardController(opp1);
        VF_ShortFormController SFCont1 = new VF_ShortFormController(SF1);
        SFCont1.ESF.add(ESF1);
        SFCont1.ShortForm();
        SFCont1.save();

    }
}
Class Creating Records for Test Class:
// create and insert a new Account record.
    public static Account createAcct(Integer i){ 

    Account acct = new Account();
        acct.Name = 'Test' + i;
        acct.Language__c = 'English';
        acct.Industry = 'Automotive';
        acct.CurrencyIsoCode = 'USD';
        acct.Legal_Name__c = 'Test' + i;
        acct.Region__c = 'NA-US-NE';
        acct.BillingCity = 'New York';
        acct.BillingState = 'New York';
        acct.BillingCountry = 'United States';

    return acct;

    }


// create and insert a new Opportunity record that has the newly created Account record as its master record.
    public static Opportunity createOppNew (Id acctId){ 
        Opportunity opp2 = new Opportunity();
            opp2.AccountId = acctId;
            opp2.Name = 'Test Opportunity - ';
            opp2.StageName = System.Label.Eng_OppStage3;
            opp2.CloseDate = date.newinstance(2020,1,31);
            opp2.Amount = 1000;
            opp2.Region__c = 'NA-US-NE';
            opp2.Type = 'New Customer';
            opp2.Website_s__c = 'www.test.com; www.test2.com; www.test3.com';
        return opp2;
    }

// create and insert a new Opportunity record that has the newly created Account record as its master record. Used for Short Form.
    public static Opportunity createOppNewSF (Id acctId){ 
        Opportunity opp2a = new Opportunity();
            opp2a.AccountId = acctId;
            opp2a.Name = 'Test Opportunity - ';
            opp2a.StageName = System.Label.Eng_OppStage3;
            opp2a.CloseDate = date.newinstance(2020,1,31);
            opp2a.Amount = 1000;
            opp2a.Region__c = 'NA-US-NE';
            opp2a.Type = 'New Customer';
            opp2a.Website_s__c = 'www.test.com; www.test2.com; www.test3.com';
        return opp2a;
    }
}

Class Throwing Error:​
public with sharing class TriggerHandlerAccount {
    private boolean isExecuting = false;

    public TriggerHandlerAccount(boolean initIsExecuting) {
        isExecuting = initIsExecuting;
    }

    public void beforeInsert(List<Account> newAccounts) {
        setType(newAccounts);
        mapRegions(newAccounts);
        UpdateEnglishName(newAccounts, null);
    }

    public void beforeUpdate(List<Account> newAccounts, map<id, Account> oldAccountMap) {
        mapRegions(newAccounts);
        UpdateEnglishName(newAccounts, oldAccountMap);
    }

    public void afterInsert(List<Account> newAccounts) {
        updateRegionField(newAccounts, 'isInsert', newAccounts.size());
        accountHierarchyLeadSourceCalculation(new List<Account>(), newAccounts, 'isInsert', newAccounts.size());
    }


    private void UpdateEnglishName (List<Account> newAccounts, map<id, Account> oldAccountMap){
        for (Account account : newAccounts) {
            system.debug('oldAccountMap = ' + oldAccountMap);
            system.debug('oldAccountMap = ' + account.English_Account_Name__c);
            if ((oldAccountMap == null && account.English_Account_Name__c == null) ||
            (oldAccountMap != null && account.Name != oldAccountMap.get(account.id).Name && account.English_Account_Name__c == oldAccountMap.get(account.id).English_Account_Name__c))
            FillUpEnglishName(account);
        }
    }

    private void FillUpEnglishName (Account account) {
        if (account.Name == null || account.Name.trim() == '') return;
        String[] chars = account.Name.split('');
        // the 1st element in an Apex '' split is garbage; remove it:
        chars.remove(0);
        System.debug(chars);
        // change a char:
        string SC = SpecialCharacters__c.getInstance().Characters__c;
        boolean english = true;
        for (String c : chars) {
            if (!c.containsAny(SC))
                english = false;
        }
        system.debug('english = ' + english);
        if (english)
            account.English_Account_Name__c = account.Name;
    }


    private void setType(List<Account> newAccounts) {
        // If the Account is created with no Type but was converted from a Lead that had
        //    a Lead Type, set the Type from the Lead Type

        for (Account newAccount: newAccounts) {
            if (newAccount.Lead_Type__c != Null && newAccount.Type == Null) {
                newAccount.Type = newAccount.Lead_Type__c;
            }
        }
    }

    private void mapRegions(List<Account> newAccounts) {
        AccountRegionManager regionManager = new AccountRegionManager();
        Region_Mapper_Settings__c errorMessage = Region_Mapper_Settings__c.getInstance();
        for (Account newAccount: newAccounts) {
            String region = regionManager.getRegion(newAccount.BillingCountry, newAccount.BillingState);
            if (region != null) {
                newAccount.Region__c = region;
            } else {
                newAccount.addError(errorMessage.Invalid_Mapping_Message__c);
            }
        }
    }

    public static Boolean accountHierarchyLeadSourceCalculationEnable = true; 

     private void updateRegionField(List<Account> newAccounts, String triggerEvent, Integer triggerSize) {

        Boolean needUpdateRegion = false;
        map<Id , Account> accountsmap =  new map<Id, Account>();
        List<Account> accounts = new List<Account>();

         for(Integer i = 0; i < triggerSize; i++){
            Account tempaccount = new Account(id = newAccounts[i].id);
            if(triggerEvent == 'isInsert') 
                needUpdateRegion = newAccounts[i].Region__c == '' || newAccounts[i].Region__c == ' ' || newAccounts[i].Region__c == null;

            if (needUpdateRegion) 
            {
                accountsmap.put(newAccounts[i].OwnerId , newAccounts[i]);
            }
         }

         for(User u : [SELECT Id, Region__c FROM User WHERE Id IN :accountsmap.keyset()]){
                   Account tempaccount = new Account(id = accountsmap.get(u.id).id) ; 
                   tempaccount.Region__c = u.Region__c;
                   system.debug('Region to update: '+ tempaccount.Region__c);
                   accounts.add(tempaccount);
         }

         if (!accounts.isempty())
            update accounts;
     }
}

 
Hello,

Does anyone know if it is possible to call a Process from a Visualforce page button?  My situation is that I have a custom object with a Master-Detail relationship to the Opportunity object.  When the user creates a record of the custom object, I want to have a button that would create an associated Case when clicked.  In the past, I have done this via a URL hack, but I would like to use something more scalable like a Process but I'm not sure how to get the button to do this.  Any help is appreciated!
I am trying to populate a field in a Visualforce page for custom object using a controller extension. I would like to populate the field with one value if the User Role of the person creating the record is Sales and another value if they are Account Management. I'm not quite sure of the syntax I need to use to accomplish this in my controller. Can anyone assist?
 
public class VF_CampaignCaseCreateController{
public List<Campaign_Create_Request__c> CCR {get; set;}

    private final Opportunity opp;
    public VF_CampaignCaseCreateController(ApexPages.StandardController myController){
        CCR = new List<Campaign_Create_Request__c>();
            if (!Test.isRunningTest())
            {
            myController.addFields(new List<String>{'Id', 'OwnerId'});
            }
        opp=(Opportunity)myController.getrecord();
    }

    public Campaign_Create_Request__c CCR2 = new Campaign_Create_Request__c();
        public void CampaignCaseCreate(){

            CCR2.Opportunity__c = opp.Id;

            IF($UserRole.Name StartsWith('Sales')){
                CCR2.Sales_Rep__c = $UserRole.Id;
            }
            ELSE{
                CCR2.Sales_Rep__c = null;
            }   

            Opportunity o = [SELECT (SELECT Id, contactId
                                       FROM OpportunityContactRoles
                                       WHERE role = 'Signatory')
                            FROM Opportunity
                            WHERE id = :opp.id];
            CCR2.Primary_User__c = o.opportunityContactRoles.size() != 0 
                                    ? o.opportunityContactRoles[0].contactId  
                                    : null;

            CCR.add(CCR2);
        }
}

 
Hello,

I have a custom controller extension below which pre-populates the Opportunity ID and a Contact Role ID to a Visualforce page for a custom object that has a Master-Detail relationship to the Opportunity object.  I am now trying to create 2 buttons on the VF page that will populate a 3rd custom field, save the custom object record, and re-direct the user to another VF page.  However, when I try to save the code below I get the error:  

Error: VF_CampaignCaseCreateController Compile Error: Initial term of field expression must be a concrete SObject: List<Campaign_Create_Request__c> at line 37 column 9

I'm sure my syntax is incorrect for populating the 3rd field in each method, but I'm not sure how to fix it.
 
public class VF_CampaignCaseCreateController{
    
    public List<Campaign_Create_Request__c> CCR {get; set;}
    
        private final Opportunity opp;
        public VF_CampaignCaseCreateController(ApexPages.StandardController myController){
            CCR = new List<Campaign_Create_Request__c>();
                if (!Test.isRunningTest())
                {
                myController.addFields(new List<String>{'Id', 'OwnerId', 'Owner.Phone'});
                }
            opp=(Opportunity)myController.getrecord();
        }
    
        public Campaign_Create_Request__c CCR2 = new Campaign_Create_Request__c();
            public void CampaignCaseCreate(){
           
                CCR2.Opportunity__c = opp.Id;
    
                Opportunity o = [SELECT (SELECT Id, contactId
                                           FROM OpportunityContactRoles
                                           WHERE role = 'Signatory')
                                FROM Opportunity
                                WHERE id = :opp.id];
                CCR2.Primary_User__c = o.opportunityContactRoles.size() != 0 
                                        ? o.opportunityContactRoles[0].contactId  
                                        : null;
    
                CCR.add(CCR2);
            }
    
    
        public PageReference AdCamp() {
    
            insert CCR;
            CCR.Requested_Action__c = 'Create and Add';
    
               PageReference RetPage = new PageReference('/VF_CampaignCreate_Edit?id=' + CCR[0].id);
            RetPage.setRedirect(true);
            return RetPage; 
        }
    
        public PageReference Camp() {
    
            insert CCR;
            CCR.Requested_Action__c = 'Create Only';
    
               PageReference RetPage = new PageReference('/VF_CampaignCreate_Edit?id=' + CCR[0].id);
            RetPage.setRedirect(true);
            return RetPage; 
        }
    
    }

 
Hello,

I have a VF page at the Account level.  The page includes 3 radio buttons.  I am trying to populate 1 of 3 checkbox fields on the Account depending upon the value the user selects in the radio buttons.  I have my page set up to render sections basd upon the radio button selected, and that works great.  However, I cannot figure out how to populate the appropriate checkbox field when the specific radio button is selected.  Can anyone help?
 
<apex:page standardController="Account" tabStyle="Account" id="thePage">

<script>
    function TypeSelect(variable)
    {
        var choice = variable.value;
        if(choice == 'Amp'){
            document.getElementById('layoutAmp').style.display = 'block';
            document.getElementById('layoutEng').style.display = 'none';
            document.getElementById('layoutAge').style.display = 'none';
            document.getElementById('{!$Component.thePage.theForm.AmpVal}').value = true;
        }
        else if(choice == 'Eng'){
            document.getElementById('layoutAmp').style.display = 'none';
            document.getElementById('layoutEng').style.display = 'block';
            document.getElementById('layoutAge').style.display = 'none';
            document.getElementById('{!$Component.thePage.theForm.EngVal}').value = true;
        }
        else{
            document.getElementById('layoutAmp').style.display = 'none';
            document.getElementById('layoutEng').style.display = 'block';
            document.getElementById('{!$Component.thePage.theForm.geVal}').value = true';
        }
    }   
</script>

<style>
    input[type=radio] {margin-left: 100px;}
    .radioClass {margin-left: 25%;}
</style>


<apex:form id="theForm">
    <apex:actionRegion >
        <div class="sectBody">
            <Table width="90%" border="0" cellpadding="0" cellspacing="0" columns="5">
                 <tr>
                     <td colspan="5" class="fieldLabel">
                     <apex:selectRadio layout="lineDirection" styleClass="radioClass" onclick="TypeSelect(this);">
                      <apex:selectOption itemLabel="Amp" itemValue="Amp"></apex:selectOption>
                            <apex:selectOption itemLabel="Eng" itemValue="Eng"></apex:selectOption>
                            <apex:selectOption itemLabel="Age" itemValue="Age"></apex:selectOption>
                     </apex:selectRadio>
                     <apex:actionSupport event="onchange" reRender="checkBox"/>
               </td>
          </tr>\    
     </Table><br/><br/>
        </div>


	<div id="checkBox">
    	<apex:inputField id="AmpVal" value="{!Account.Amp_Account__c}" />
    	<apex:inputField id="EngVal" value="{!Account.Eng_Account__c}" />
        <apex:inputField id="AgeVal" value="{!Account.Age_Account__c}" />
    </div>

 
Hello,

I have a VF page on the Account. I have set up 3 radio selections using apex:selectRadio and a Script. I would now like to populate a custom field (Type__c) with the radio selection the user chose. Does anyone know how I can do this? Thanks,
 
<apex:page standardController="Account" tabStyle="Account">

<script>

    function TypeSelect(variable)
    {
        var choice = variable.value;
        if(choice == 'Amp'){
            document.getElementById('layoutAmp').style.display = 'block';
            document.getElementById('layoutEng').style.display = 'none';
            document.getElementById('layoutAge').style.display = 'none';
        }
        else if(choice == 'Eng'){
            document.getElementById('layoutAmp').style.display = 'none';
            document.getElementById('layoutEng').style.display = 'block';
            document.getElementById('layoutAge').style.display = 'none';
        }
        else{
            document.getElementById('layoutAmp').style.display = 'none';
            document.getElementById('layoutEng').style.display = 'none';
            document.getElementById('layoutAge').style.display = 'block';
        }
    }   
</script>

<style>
    input[type=radio] {margin-left: 100px;}
    .radioClass {margin-left: 25%;}
</style>


<apex:form >

    <apex:actionRegion >

            <Table width="90%" border="0" cellpadding="0" cellspacing="0" columns="5">
                <tr>
                    <td colspan="5" class="fieldLabel">
                        <apex:selectRadio layout="lineDirection" styleClass="radioClass" onclick="TypeSelect(this);">
                           <apex:selectOption itemLabel="Amplify" itemValue="Amplify"></apex:selectOption>
                           <apex:selectOption itemLabel="Engage" itemValue="Engage"></apex:selectOption>
                           <apex:selectOption itemLabel="Agency" itemValue="Agency"></apex:selectOption>
                        </apex:selectRadio>
                        <apex:actionSupport event="onchange" reRender="Detail"/>
                    </td>
                </tr>
            </Table>

 
Hello,

I have a Visualforce page with a custom button that calls JavaScript to execute a script. When I click the button, I get a 404 Error (Not Found) error. Apparently, this is due to an SFDC resource called "logo180.png". It seems this is a known issue that occurs by design to prevent malware. However, it prevents by button from working on my VF page. Does anyone know how I can avoid this?
 
<apex:page standardController="Engage_Short_Form__c">

<script type="text/javascript" src="/apex/dsfs__DocuSign_JavaScript"></script>
<script type="text/javascript">
    function sendViaDocuSign() {
        var CRL = ''; 
        var DST = ''; 
        var CES = '';
        CRL = 'Email~{!JSENCODE(Engage_Short_Form__c.Partner_Email__c)};FirstName~{!JSENCODE(Engage_Short_Form__c.Partner_Contact_First_Name__c)};LastName~{!JSENCODE(Engage_Short_Form__c.Partner_Contact_Last_Name__c)};Role~Signer1,Email~jneilan@outbrain.com;FirstName~John;LastName~Neilan;Role~Signer 2'; 
        DST = '0E9AB63C-62C0-4D01-B91A-E58849B7B573'; 
        CES = 'Insertion Order signature request for {!JSENCODE(Engage_Short_Form__c.Partner_Legal_Name__c)}';
        window.location.href = "/apex/dsfs__DocuSign_CreateEnvelope?DSEID=0&STB=1&SourceID={!Engage_Short_Form__c.Id}&LA=0&CRL="+CRL+"&DST="+DST+"&CES="+CES; 
    }
</script>



   <apex:form >

            <center><button class="btn" onclick="sendViaDocuSign()">Send via DocuSign</button></center>

 
Does anyone know how to debug a Comandbutton in a VF page?  I have a page that has a JavaScript script with a window.location.href element.  The Commandbutton is mean to call this script and direct the user to the URL in the href element.  Everythign save properly, but all the button does when pressed is refresh the page.  Does anyone know how I can figure out what is actually happening when I press the button and why it's not calling the window.location.href element of the script?
I have created an embedded Visualforce page to replace the "New" button on the Account object. The page calls a Flow, in which the users is able to check off checkboxes. The finish location of the Flow is designed to be 1 of 2 locations, dependent upon the user's selection(s). However, when I click the New button, I get the following error:

Visualforce Error
System.NullPointerException: Attempt to de-reference a null object
Class.VF_AcctNewCreate.__sfdc_TypeOutput: line 26, column 1
Class.VF_AcctNewCreate.__sfdc_SFId: line 15, column 1


Can anyone help explain why?

VF Page:
<apex:page standardController="Account" Extensions="VF_AcctNewCreate">
    <flow:interview name="Account_Create_Flow" interview="{!myFlow}" finishLocation="{!SFId}" />
</apex:page>
Controller:
public class VF_AcctNewCreate{

    private final Account acct;
    public VF_AcctNewCreate(ApexPages.StandardController myController){
//        acc = new List<Account>();
        acct=(Account)myController.getrecord();
    }

public Flow.Interview.Account_Create_Flow myFlow { get; set; }


// Factor your PageReference as a full GET/SET
public PageReference SFId {
  get {
  PageReference prRef = new PageReference('/' + TypeOutput);
  prRef.setRedirect(true);
  return prRef;
  }
  set { SFid = value; }
  }

// Factor your Flow output variable pull as a full GET / SET
public String TypeOutput {
  get {
    String strTemp = '';
    String CT = myFlow.CustType;
    String ID = myFlow.AccountId;
//    String CT = string.valueOf(myFlow.getVariableValue('CustType'));
//    String ID = string.valueOf(myFlow.getVariableValue('AccountId'));

    if(CT == 'Engage') {
      strTemp = '/' + ID;
    }
  else{
    strTemp = '/apex/AccountCreate?id=' + ID;
  }

  return strTemp;
  }

  set { TypeOutput = value; }
} 
}