• hitesh90
  • PRO
  • 4247 Points
  • Member since 2012
  • Sr. Technical Analyst
  • Jade Global Software Pvt. Ltd.


  • Chatter
    Feed
  • 128
    Best Answers
  • 1
    Likes Received
  • 2
    Likes Given
  • 2
    Questions
  • 636
    Replies

I do have a page with /apex/AccountPrioritySort?id={!Account_Plan__c.Id}&type=AP. Please find my code as below

Visual Force Page

<apex:page standardController="Account_Plan__c" extensions="accountprioritysort1" tabStyle="Account" id="thePage">
    <apex:form id="theForm" >
        <apex:pageBlock title="Editing Top 5 Account Priorities" mode="edit">
            <apex:messages />
                <apex:pageBlockButtons location="top">
                    <apex:commandButton value="Update Sorted Account Priorities" action="{!SaveAction}"/>
                    <apex:commandButton value="Cancel" action="{!Cancel}"/>
                </apex:pageBlockButtons>
            
                <apex:pageBlockTable value="{!actPList}" var="item">
                    <apex:column value="{!item.Account_Priorities__c}"/>
                    <apex:column headervalue="# (Top 5 Priorities)">
                        <apex:inputField value="{!item.Field1__c}"/>
                    </apex:column>
                </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

APEX Class

public with sharing class accountprioritysort1 {    

    public ApexPages.StandardController stdController {get; set;}
    public Account_Plan__c AccPri { get; set; }
    public list<Company_Priorities__c> actPList  { get; set; }
    public integer aField { get; set;}
    
    public accountprioritysort1 (ApexPages.StandardController stdController){
        System.debug('Is it in the Constructor');
        this.stdController = stdController;
        this.AccPri = (Account_Plan__c)this.stdController.getRecord();
        actPList = [select Field1__c,Account_Priorities__c from Company_Priorities__c where Account_Plan__c =: AccPri.Id
                ORDER BY Field1__c ASC ];
    }
    
    public PageReference SaveAction(){
        update actPList;
        PageReference page = new PageReference('/apex/AccountPrioritySort?id='+AccPri.id);
        page.setRedirect(true);
        return page;
    }
    
    public PageReference CancelAction(){
            PageReference page = new PageReference('/apex/AccountPrioritySort?id='+AccPri.id);
            page.setRedirect(true);
            return page;
        }
    }


/apex/AccountPrioritySort?id={!Account_Plan__c.Id}&type=AP

Now i want to pass this 


1. The value (which is as type=AP) from the Parameter Type in the Apex Controller

2. How can render by using the type variable to between Account Priorities and Risk in the VF page and Controller. This type should be used to decide what data needs to be saved i.e. should the risk code execute or Account priorities code execute.
 

Can any one help on this code.

 

Hi All,

I have written test class for one of my VF Page & covered upto 73% but i failed to cover morethan 75%. Here is my VF Page & Apex Classes
 
<apex:page controller="DataTableEditRemoveController">
<apex:form id="form" >
<apex:pageBlock title="Accounts">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockTable value="{!accs}" var="acc">
<apex:column >
<apex:outputLink title="" value="/{!acc.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
<apex:commandLink action="{!DeleteAccount}" onclick="return confirm('Are you sure?')" value="Del">
    <apex:param value="{!acc.Id}" name="accountid" assignTo="{!SelectedAccountId}"/>
</apex:commandLink>
</apex:column>
<apex:column value="{!acc.Name}"/>
<apex:column value="{!acc.BillingStreet}"/>
<apex:column value="{!acc.BillingCity}"/>
<apex:column value="{!acc.BillingPostalCode}"/>
<apex:column value="{!acc.BillingCountry}"/>    
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>      
</apex:page>

Here is Controller
 
public class DataTableEditRemoveController {

    public String getRow() {
        return null;
    }

public List<Account> accs { get; set; }

//used to get a hold of the account record selected for deletion
public string SelectedAccountId { get; set; }

public DataTableEditRemoveController() {
//load account data into our DataTable
LoadData();
}

@Testvisible
private void LoadData() {
system.debug('Enter In the Constructor*****');
accs = [Select id, name, BillingStreet, BillingCity, BillingPostalCode, BillingCountry from Account limit 20];
}

public PageReference DeleteAccount()
{
System.debug('SelectedAccountId: '+SelectedAccountId);
accs = [select id,name, BillingStreet, BillingCity, BillingPostalCode, BillingCountry from Account where id=:SelectedAccountId];
System.debug('SIZEOFACC: '+accs.size());
if(accs.size()>0 && accs[0]!= null){
delete accs;
System.debug('DELSIZEOFACC: '+accs.size());
SelectedAccountId = null;

}

//refresh the data
LoadData();
    return null;
}


}

Here is 29 th line is not covered ...............


Here is My Test Class
 
@istest
public class DataTableEditRemoveController_Test{
static testmethod void Method_Test(){

    Account acc = new Account();
    acc.name = 'Test';
    acc.Fax = '555555';
    acc.BillingStreet = 'Korlagunta';
    acc.BillingCity = 'Tirupati';
    acc.BillingPostalCode = 'Tiruapti';
    acc.BillingCountry = 'INDIA';
    insert acc;
    
   // Delete acc;
  system.debug('ACCID******'+acc.id);  
    Test.starttest();
    pagereference pageref = page.Edit_Del_Hyperlink_Fun;
    Test.SetCurrentPageReference(pageref);
    pageref.getParameters().put('SelectedAccountId', String.valueOf(acc.Id));
  string STRID = apexpages.currentpage().getparameters().put('SelectedAccountId',acc.id);
   System.assertEquals(STRID, acc.Id, 'ID\'s should match');
   system.debug('PARAMID******'+apexpages.currentpage().getparameters().put('SelectedAccountId',acc.id)); 
    DataTableEditRemoveController contrll = new DataTableEditRemoveController ();
    contrll.LoadData();
    contrll.DeleteAccount();
    list<Account> a =[select id,name, BillingStreet, BillingCity, BillingPostalCode, BillingCountry from Account where id=:STRID];
    system.debug('LSTACCID******'+a.size());
    Delete a;
    Test.stoptest();

I have checked the debugs, SelectedAccountId its coming in test class but not in main controller..........I am struck here .......Please give me your valuable suggestions.......

Adv Thnx
VSK98
how to write the testclass to below class , knidly help me .
public class CurrentRecordIdDemoController{
public String currentRecordId {get;set;}
public String parameterValue {get;set;}
public Account acc{get;set;}

    public CurrentRecordIdDemoController(ApexPages.StandardController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        acc = [select id ,name, AccountNumber, Type, Industry from Account where id =: currentRecordId ];
        parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
    }
}

Cheers!
chanti
Visualforce Page 1: 
<apex:page standardController="Account" recordSetVar="accountList"
           extensions="DynamicCustomizableListHandler">
    <br/>
    <apex:form >

    <!-- View selection widget, uses StandardController methods -->
    <apex:pageBlock >
        <apex:outputLabel value="Select Account Views: " for="viewsList"/>
        <apex:selectList id="viewsList" size="1" value="{!filterId}">
            <apex:actionSupport event="onchange" rerender="theTable"/>
            <apex:selectOptions value="{!listViewOptions}"/>
        </apex:selectList>
    </apex:pageblock>

    <!-- This list of accounts has customizable columns -->
    <apex:pageBlock title="Accounts" mode="edit">
        <apex:pageMessages />
        <apex:panelGroup id="theTable">
            <apex:pageBlockTable value="{!accountList}" var="acct">
                <apex:column value="{!acct.Name}"/>
                <!-- This is the dynamic reference part -->
                <apex:repeat value="{!displayFields}" var="f">
                    <apex:column value="{!acct[f]}"/>
                </apex:repeat>
            </apex:pageBlockTable>
        </apex:panelGroup>
    </apex:pageBlock>

    <br/>
    <apex:commandButton value="Customize List" action="{!customize}"/>

    </apex:form>
</apex:page>

Apex Class:
public class DynamicCustomizableListHandler {

    // Resources we need to hold on to across requests
    private ApexPages.StandardSetController controllerr;
    private PageReference savePage;

    // This is the state for the list "app"
    private Set<String> unSelectedNames = new Set<String>();
    private Set<String> selectedNames = new Set<String>();
    private Set<String> inaccessibleNames = new Set<String>();

    public DynamicCustomizableListHandler(ApexPages.StandardSetController controller) {
        this.controllerr = controller;
        loadFieldsWithVisibility();
    }

    // Initial load of the fields lists
    private void loadFieldsWithVisibility() {
        Map<String, Schema.SobjectField> fields = 
            Schema.SobjectType.Account.fields.getMap();
        for (String s : fields.keySet()) {
            if (s != 'Name') {  // name is always displayed 
                unSelectedNames.add(s);
            }
            if (!fields.get(s).getDescribe().isAccessible()) {
                inaccessibleNames.add(s);
            }
        }
    }

    // The fields to show in the list
    // This is what we generate the dynamic references from
    public List<String> getDisplayFields() { 
        List<String> displayFields = new List<String>(selectedNames);
        displayFields.sort();
        return displayFields;
    }
    
    // Nav: go to customize screen
    public PageReference customize() {
        savePage = ApexPages.currentPage();
        return Page.CustomizeDynamicList;
    }

    // Nav: return to list view
    public PageReference show() {
        // This forces a re-query with the new fields list
        controllerr.reset();
        controllerr.addFields(getDisplayFields());
        return savePage; 
    }

    // Create the select options for the two select lists on the page
    public List<SelectOption> getSelectedOptions() { 
        return selectOptionsFromSet(selectedNames);
    }
    public List<SelectOption> getUnSelectedOptions() { 
        return selectOptionsFromSet(unSelectedNames);
    }
    
    private List<SelectOption> selectOptionsFromSet(Set<String> opts) {
        List<String> optionsList = new List<String>(opts);
        optionsList.sort();
        List<SelectOption> options = new List<SelectOption>();
        for (String s : optionsList) {
            options.add(new 
                SelectOption(s, decorateName(s), inaccessibleNames.contains(s)));
        }
        return options;
    }

    private String decorateName(String s) {
        return inaccessibleNames.contains(s) ? '*' + s : s;
    }

    // These properties receive the customization form postback data
    // Each time the [<<] or [>>] button is clicked, these get the contents
    // of the respective selection lists from the form
    public transient List<String> selected   { get; set; }
    public transient List<String> unselected { get; set; }

    // Handle the actual button clicks. Page gets updated via a
    // rerender on the form
    public void doAdd() {
        moveFields(selected, selectedNames, unSelectedNames);
    }
    public void doRemove() {
        moveFields(unselected, unSelectedNames, selectedNames);
    }
    
    private void moveFields(List<String> items, 
            Set<String> moveTo, Set<String> removeFrom) {
        for (String s: items) {
            if( ! inaccessibleNames.contains(s)) {
                moveTo.add(s);
                removeFrom.remove(s);
            }
        }
    }
}

Visualforce Page 2: 
<apex:page standardController="Account" recordSetVar="ignored"
           extensions="DynamicCustomizableListHandler">
    <br/>
    <apex:form >

    <apex:pageBlock title="Select Fields to Display" id="selectionBlock">
        <apex:pageMessages />
        <apex:panelGrid columns="3">
            <apex:selectList id="unselected_list" required="false" 
                value="{!selected}" multiselect="true" size="20" style="width:250px">
                <apex:selectOptions value="{!unSelectedOptions}"/>
            </apex:selectList>
            <apex:panelGroup >
                <apex:commandButton value=">>" 
                    action="{!doAdd}" rerender="selectionBlock"/>
                <br/>
                <apex:commandButton value="<<" 
                    action="{!doRemove}" rerender="selectionBlock"/>
            </apex:panelGroup>
            <apex:selectList id="selected_list" required="false" 
                value="{!unselected}" multiselect="true" size="20" style="width:250px">
                <apex:selectOptions value="{!selectedOptions}"/>
            </apex:selectList>
        </apex:panelGrid>
        <em>Note: Fields marked <strong>*</strong> are inaccessible to your account</em>
    </apex:pageBlock>
    
    <br/>
    <apex:commandButton value="Show These Fields" action="{!show}"/>

    </apex:form>

</apex:page>

------------------------- The above code is working fine and the below code is not woking as expected, both are same code ----------------------
Anyone can expalin what's the mistake. And i'm getting the error as "System.SObjectException: SObject row was retrieved via SOQL without querying the requested field"

Visualforce Page 
<apex:page standardController="Account" recordSetVar="accountList" extensions="DynamicCustomizableListHandler"> <br />
  
  <apex:form >
      <!-- View selection widget, uses StandaredController method  -->
      <apex:pageBlock >
          <apex:outputLabel value="Select Account Views: " for="viewList"/>
          <apex:selectList id="viewList" size="1" value="{!filterId}">
              <apex:actionSupport event="onchange" reRender="theTable"/>
              <apex:selectOptions value="{!listViewOptions}"/>
          </apex:selectList>
      </apex:pageBlock>
      
      <!-- This list of accounts has customizable coloumns -->
      <apex:pageBlock title="Accounts" mode="edit">
          <apex:pageMessages />
          <apex:panelGroup id="theTable">
              <apex:pageBlockTable value="{!accountList}" var="acct">
                  <apex:column value="{!acct.Name}"/>
                  <!-- This is dynamic reference part -->
                  <apex:repeat value="{!displayFields}" var="f">
                      <apex:column value="{!acct[f]}"/>
                  </apex:repeat>
              </apex:pageBlockTable>
          </apex:panelGroup>
      </apex:pageBlock>
      <br />
      <apex:commandButton value="Customize List" action="{!customize}"/>
  </apex:form>
</apex:page>

Apex Class
public class DynamicCustomizableListHandler {

    // Resources we need to hold on to across requests
    private ApexPages.StandardSetController controllerr;
    private PageReference savePage;
    
    // This is the stage for the list "app"
    private Set<String> unSelectedNames = new Set<String>();
    private Set<String> selectedNames = new Set<String>();
    private Set<String> inaccessibleNames = new Set<String>();
    
    public DynamicCustomizableListHandler(ApexPages.StandardSetController controller) {
        this.controllerr = controller;
        loadFieldsWithVisibility();
    }
    
    // Initial load of the fields list
    private void loadFieldsWithVisibility() {
        Map<String, Schema.SobjectField> fields = Schema.SobjectType.Account.fields.getMap();
        for(String s : fields.keySet()) {
            if(s != 'Name') { // name is always display
                unSelectedNames.add(s);
            }
            if(!fields.get(s).getDescribe().isAccessible()) {
                inaccessibleNames.add(s);
            }
        }
    }
    
    // The fields to show in the list
    // This is what we generate the dynamic reference from
    public List<String> getDisplayFields() {
        List<String> displayFields = new List<String>(selectedNames);
        displayFields.sort();
        return displayFields;
    }
    
    // Nav: go to customize screen
    public PageReference customize() {
        savePage = ApexPages.currentPage();
        return Page.CustomizeDynamicList;
    }
    
    // Nav: return to list view
    public PageReference show() {
        // This force a re-query with the new field list
        controllerr.reset();
        controllerr.addFields(getDisplayFields());
        return savePage;
    }
    
    // Create the select options for the two select lists on the page
    public List<SelectOption> getSelectedOptions() {
        return selectOptionsFromSet(selectedNames);
    }
    
    public List<SelectOption> getUnSelectedOptions() {
        return selectOptionsFromSet(unSelectedNames);
    }
    
    private List<SelectOption> selectOptionsFromSet(Set<String> opts) {
        List<String> optionsList = new List<String>(opts);
        optionsList.sort();
        List<SelectOption> options = new List<SelectOption>();
        for(String s : optionsList) {
            options.add(new SelectOption(s, decorateName(s), inaccessibleNames.contains(s)));
        }
        return options;
    }
    
    private String decorateName(String s) {
        return inaccessibleNames.contains(s) ? '*' + s : s;
    }
    
    // These properties receive the customization from postback data
    // Each time the [<<] or [>>] button are clicked, these get the contents of the respective selection lists from the form
    public transient List<String> selected { get; set; }
    public transient List<String> unselected { get; set; }
    
    // Handle the actual button clicks, Page gets updated via a rerender a form
    public void doAdd() {
        moveFields(selected, selectedNames, unSelectedNames);
    }
    
    public void doRemove() {
        moveFields(unselected, unSelectedNames, selectedNames);
    }
    
    private void moveFields(List<String> items, Set<String> moveTo, Set<String> removeFrom) {
        for(String s : items) {
            if(! inaccessibleNames.contains(s)) {
                moveTo.add(s);
                removeFrom.remove(s);
            }   
        }
    }
}

Visualforce Page
<apex:page standardController="Account" recordSetVar="ignored" extensions="DynamicCustomizableListHandler">
  <br />
  <apex:form >
      <apex:pageBlock title="Select Fields To Display" id="selectionBlock">
          <apex:pageMessages />
          <apex:panelGrid columns="3">
              <apex:selectList id="unselected_list" required="false" value="{!selected}" multiselect="true" size="20" style="width:250px">
                  <apex:selectOptions value="{!unSelectedOptions}"/>
              </apex:selectList>
              <apex:panelGroup >
                  <apex:commandButton value=">>" action="{!doAdd}" rerender="selectionBlock"/>
                  <br />
                  <apex:commandButton value="<<" action="{!doRemove}" reRender="selectionBlock"/>
              </apex:panelGroup>
              <apex:selectList id="selected_list" required="false" value="{!unselected}" multiselect="true" size="20" style="width:250px">
                  <apex:selectOptions value="{!SelectedOptions}"/>
              </apex:selectList>
          </apex:panelGrid>
          <em>Note: Fields marked <strong>*</strong> are inaccessible to your account</em>
      </apex:pageBlock>
      <br />
      <apex:commandButton value="Show These Fields" action="{!show}"/>
  </apex:form>
</apex:page>

 
I'm not sure if I'm going insane or not, but started about a month ago and now on this challenge and I cannot find where they are saying to go to... I'm thinking I'm not in Salesforce Classic view, is there a way to change to that?  


This is my home page.


User-added image
trigger deleteoppafter on Opportunity (after delete) {
if(trigger.isafter && trigger.isdelete){
    list<task> t=new list<task>();
    t=[select whatid from task];
         for(opportunity opp1:trigger.old){
             for(task tt:t){
             if(opp1.id==tt.whatid){
                 t.add(tt);
                 delete t;
                
             }
                 
             }
         }
}
}

i am getting the following error:
Illegeal assignment from list to list.

Please help..!!
Hi Experts,
Many times am getting this error on visualforce page and test calss ,When we will getting list has no errors ?what kind of situation ? how to we can resolved, kindly do the needful


Thank you,
Chanti
Hi All,

I am new Salesforce Lightning experience. I am trying to call an external JavaScript by loading it as a Static resource and calling it in my Lightning application using the following syntax but I am unable to get it work.

<aura:application >
       <ltng:require scripts="{!$Resource.SDFCTestJS}" afterScriptsLoaded="{!c.afterScriptsLoaded}"/>
</aura:application>

Please suggest how can I get it work.

P.S : I read a solution that we can load Javascript by creating a Helper class and call it from our Component. Can anyone suggest a way so that I don't need to create helper everytime I call a component as I am going to have many; a way that I can include the JS directly from the above.

Thanks in advance.

Warm Regards,
Shubham
SFDC
 
Hello

I opened a ticket with support on this and they are stumped, they sent me here. Seems like a simple question. I have a picklist in accounts. What I want to do is when an user is opening a case for that account, I want the value of the picklist to appear in the new case form. It will show the sensitivity of the customer and the support team will know right away how to address the problems. I tried to use formula fields but they do not support picklist values. Any thoughts would be appreciated.
 
HI All.

I'm only getting 70% coverage and I'm not sure how to cover the variables.

These are the lines not covered.

     Line 16 qty = o.Total_Roundtables__c;
            17 orderId = o.Id;
            18 eventId = o.Event__c;
            19 eventName = o.Event__r.Name;

            31 r=new Roundtables__c (Order__c=orderId, Status__c ='Unallocated', Event__c = eventId);
            32 rList.add(r);

Can anyone help?

Here's my trigger
trigger CreateRoundtables on Order (after insert, after update) {

    public double qty;
    public id orderId;
    public id eventId;
    public string eventName;


    
    Id orderRecType = Schema.SObjectType.Order.getRecordTypeInfosByName().get('Order').getRecordTypeId(); 
    
    List <OrderItem> oi = [Select id, Roundtables__c from OrderItem where Roundtables__c>0 ];
    system.debug(oi);
    for(order o:trigger.new){
        if(o.BU__c=='MTB' && o.Total_Roundtables__c >= 1 && O.Attendee_Type__c =='Sponsor' && o.Status == 'Approved'){
         	qty = o.Total_Roundtables__c;
            orderId = o.Id;
            eventId = o.Event__c;
            eventName = o.Event__r.Name;
            system.debug('Order ID '+ orderId);
            system.debug('Event Name '+ eventName);
        }
    }
    
    List <Roundtables__c> curRT = [Select id, Order__c from Roundtables__c where Order__c =: orderId];
    List <Roundtables__c> rList = new list <Roundtables__c>();
    Roundtables__c r;
    
    if(curRT.size() <> qty){
    for(Integer m=1;m<=qty;m++){
        r=new Roundtables__c (Order__c=orderId, Status__c ='Unallocated', Event__c = eventId);
        rList.add(r);
    }
    }
	insert rList;
}

Here's the test class
@istest (SeeAllData = true) 
public class CreateRoundTableTEST {
	
    static testMethod void TESTcreateRoundTables(){
        
        //Insert Test Accounts
		Account acc = new Account();
        acc.Type='Other';
        acc.name='test ';
        acc.NumberOfEmployees=10;
        acc.BillingStreet='BillingStreet'; 
        acc.BillingCity = 'BillingCity';
        acc.BillingState = 'BillingState';
        acc.BillingCountry = 'BillingCountry'; 
        acc.BillingPostalCode = 'BillingPostalCode';
        acc.NumberOfEmployees = 50; 
        insert acc;
        
        Account acc2 = new Account();
        acc2.Type='AX Company';
        acc2.name='test 1';
        acc2.BillingStreet='BillingStreet1'; 
        acc2.BillingCity = 'BillingCity';
        acc2.BillingState = 'BillingState';
        acc2.BillingCountry = 'BillingCountry'; 
        acc2.BillingPostalCode = 'BillingPostalCode';
        acc2.NumberOfEmployees = 50; 
        insert acc2;
   
        Project__c testProject = new Project__c();
        testProject.name = 'test Project';
        testProject.Project_Code__c = 'SUM123';
        insert testProject;
   
        //Insert Test Event
        Event__c testEvent = new Event__c();
        testEvent.name='testEvent';
        testEvent.Start_Date__c =system.today();
        testEvent.End_Date__c=system.today().addDays(2);
        testEvent.name='testEvent';
        testEvent.AX_Company__c = acc2.Id;
        testEvent.project__c = testProject.Id;
        Insert testEvent;
        
        //Insert Test Contacts
        Contact con = new contact();
        con.lastname='test';
        con.accountid=acc.id;
        con.FirstName = 'FirstName';
        con.MailingStreet = 'MailingStreet'; 
        con.MailingCity = 'MailingCity';
        con.MailingState = 'MailingState';
        con.MailingCountry = 'MailingCountry';
        con.MailingPostalCode = 'MailingPostalCode';  
        con.IsOpen4All__c=false;      
        insert con;
        
        Contact con2 = new contact();
        con2.lastname='test';
        con2.accountid=acc.id;
        con2.FirstName = 'FirstName';
        con2.MailingStreet = 'MailingStreet'; 
        con2.MailingCity = 'MailingCity';
        con2.MailingState = 'MailingState';
        con2.MailingCountry = 'MailingCountry';
        con2.MailingPostalCode = 'MailingPostalCode';  
        con2.IsOpen4All__c=false;      
        insert con2;
        
        //insert Test Campaign
        Campaign testCampaign1       = new Campaign();
        testCampaign1.name           = 'TestCampaign';
        testCampaign1.Member_Type__c = 'Delegate';
        testCampaign1.Type = 'Call List';
        insert testCampaign1;

       test.startTest();
         Id standardPriceBookId = Test.getStandardPricebookId();
        order o1 = new order();
        o1.accountid=acc.id;
        o1.EffectiveDate= system.today();
        o1.Attendee_Type__c='Sponsor';
        o1.pricebook2id=standardPriceBookId;
        o1.Primary_Campaign_Source__c=testCampaign1.id;
        o1.Price_List__c='test';
        o1.Status='Draft';
        o1.Sold_On_Date__c= system.today();
        o1.Main_POC__c=con2.id;
        o1.Event__c = testEvent.id;
        insert o1;
        
         Id dealOrderId = [Select Id, DeveloperName FROM RecordType where SobjectType = 'Order' and DeveloperName = 'Deal' limit 1].Id;

        o1.recordtypeid=dealOrderId;
        update o1;

        Product2 pd = new Product2(Name='MTB Prod',isActive=true, Number_of_Roundtables__c =2);
        pd.IsActive = true;
        insert pd;
        
        //Id standardPriceBookId = Test.getStandardPricebookId();
        
        PricebookEntry pbe = new PricebookEntry(Pricebook2Id=standardPriceBookId, Product2Id=pd.Id, UnitPrice=99, isActive=true);
        insert pbe;
        
        OrderItem ordPd = new OrderItem(PriceBookEntryId=pbe.Id, OrderId=o1.Id, Quantity=1, UnitPrice=99);
        insert ordPd;
        o1.status='Approved';
        update o1;
        
        
       test.stopTest();
    }
}


 
public class contactpopulate {
    public void onbeforeinsert(list<contact>TriggerNew)
        {
          onduplicateEmailandphone(TriggerNew);
        }
   void onduplicateEmailandphone(list<Contact>TriggerNew)
   {
        set<string> Set1= New set<string>();
        set<string> Set2= New set<string>();
    
        For(contact con:TriggerNew)
        {
            if(con.Phone!=null)
            {
                Set1.add(con.Phone);
            }
                if(con.Email!=null)
                {
                    Set2.add(con.Email);
                }
            }
        map<id,contact> map1= New map<id,contact>();
        map<id,contact> map2= New map<id,contact>();
        for(contact obj:[select id,name,Phone,Email from contact where Phone in: Set1 OR Email in: Set2])
        {
            map1.put(obj.phone,obj);
            map2.put(obj.Email,obj);
            
        }
    for(contact con:TriggerNew)
    {
        if(con.Phone !=null && map1.get(con.Phone)!=null)
           {
               con.adderror('duplicate phone found please enter new phone');
               
           }
        if(con.Email!=null&& map2.get(con.Email)!=null)
           {
               con.adderror('duplicate email found please enter new email');
           }
    }
    }
}
User-added image

I'd like to write a trigger that will modify the opportunity when an approval is approved. The snapshot shows an approval for discounts. When the discount is too high for a particular opportunity it is flagged for approval. Once the approver approves the opportunity I'd like a few fields to be autofilled. What object do I need to attach this trigger to, if this is indded possible? I would assume that some object exists for the approval. 

​In the Eclipse Force.com IDE I don't see any object for approval when writing new triggers. Your thoughts/assistance are much appreciated!
 
I currently have a trigger that checks a box when an attachment is added to a custom object called "Contracts__c". I would like to expand this Trigger to only check the box if the actual attatched document includes certain keywords. Is this possible? Here is my current code:

trigger CountAttachment on Attachment (before insert, before delete)
{
if(trigger.isinsert){
List<Contracts__c> co = [select id from Contracts__c where id =: Trigger.New[0].ParentId];
If(co.size()>0)        
{            
co[0].Contract_Attached__c = True;            
update co;        
}
}


if(trigger.isdelete){

List<Contracts__c> co = [select id from Contracts__c where id =: Trigger.old[0].ParentId];        
If(co.size()>0)        
{            
co[0].Contract_Attached__c = false;            
update co;        
}
}
}
Hi
Can you help me  how to write custom  Form validation using  "setCustomValidity" (Jquery or Javascript).
for Examle if the field value(Name) is empty when click submit button it should be  disply on Name field  " please enter the Name " ..

Thanks,
Hi,

This is the first Apex trigger I've deployed into production. It creates a renewal opportunity when an original opportunity gets set to closed won. I'm looking for your feedback as to whether it is properly bulkified. When using the data loader I've run into some errors that suggests it's not. Here's a copy of the trigger: 
 
trigger CreateRenewalOppty on Opportunity (before update) {
    
    List<Opportunity> renewals = new List<Opportunity>();
    
    for (Opportunity opp : trigger.new) {
     Opportunity oldOpp = Trigger.oldMap.get(opp.Id);
        Boolean oldOppIsWon = oldOpp.StageName.equals('Closed Won');
        Boolean newOppIsWon = opp.StageName.equals('Closed Won');
        Date myDate = System.today();
        String acctName = [SELECT Account.Name
                          FROM Opportunity
                          WHERE ID IN: trigger.new
                          Limit 1].Account.Name;
        
        
                
        
        if (!oldOppIsWon &&
           newOppisWon &&
           helperClass.firstRun &&
           (opp.Business__c == 'Site' ||
            opp.Business__c == 'District')) {
                Opportunity renewal = new Opportunity();
                renewal.Name = acctName + ' ' + myDate.year() + '-1';
                renewal.CloseDate = opp.CloseDate + 365;
                renewal.StageName = 'Qualified Renewal';
                renewal.AccountId = opp.AccountId;
                renewal.Type = 'Renewal Business';
                renewal.Business__c = opp.Business__c;
               renewal.Term_Expiration_Date__c = opp.Term_Expiration_Date__c;
                renewal.Term_Start_Date__c = opp.Term_Start_Date__c;
                renewal.Primary_Contact_del__c = opp.Primary_Contact_del__c;
                renewal.Subscription_ID__c = opp.Subscription_ID__c;
                renewal.Amount = opp.Amount;
                renewal.Trigger_AM_Sequence__c = true;
                renewal.Notes__c = opp.Notes__c;
                renewal.Student_Username__c = opp.Student_Username__c;
                renewal.Area_of_Interest__c = opp.Area_of_Interest__c;
                renewal.Other_Area_of_Interest__c = opp.Other_Area_of_Interest__c;
                renewal.Postmortem_Notes__c = opp.Postmortem_Notes__c;
                renewal.Activation_Link__c = opp.Activation_Link__c;
                helperClass.firstRun = false;
                              
                
            renewals.add(renewal);
                
              
            }
         
    }
       System.debug('firstRun is ' + helperClass.firstRun);
            System.debug('The list contains ' + renewals.size() + ' opptys');
         try {
           insert renewals; 
         } catch (Exception e) {
           System.debug('Exception type caught ' + e.getTypeName());
         }


I followed the advice to add renewal opportunities to a list and then insert the list - so thought this meant the trigger was properly bulkified? Any other tips on how to improve this trigger would be greatly appreciated as well. Thanks!
Hello all, 

I have created a formula checkbox field, BG_CHBX_06_VALUE__c, and is checked when the value in the referenced field is greater than 75%. 

Is it possible to for it to render a checkmark or the word, YES instead of checking a box? If possible, how can I modify my existing formulat to do so? 

Thanks!

 
IF(
BG_CHBX_06__c > 0.75,True,False
)