• Sure@Dream
  • SMARTIE
  • 540 Points
  • Member since 2012

  • Chatter
    Feed
  • 17
    Best Answers
  • 5
    Likes Received
  • 130
    Likes Given
  • 32
    Questions
  • 117
    Replies
I am auto filling a date/time field with Now() but it's 2 hours behind. What is up with that? Do I need to change a timezone setting or something?
Please help me with solving this error.
My trigger fires each time is record is inserted.It works fine with small data.Every night i get lot of inserts I am getting this error:: System.DmlException: Insert failed. first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

below is my code
 
trigger Linktorecord on project__c (before insert,before update,after insert) {

    Map<String,product2> pMap=new Map<String,product2>();
    List<product2> p2List=new List<Product2>();
    List<Opportunity> oppList=New List<Opportunity>();
    List<Opportunity> oppList2=New List<Opportunity>();    
    oppList=[select id,name,accountid,serialnumber__c from opportunity where SerialNumber__c !=null];

    for(product2 pro  : [select id,productcode from product2]){
        pMap.put(pro.productcode,pro);
    }
   
  if(trigger.isinsert&&trigger.isbefore)
    for(Project__c I:trigger.new){

        if(i.Number__c != null && Pmap.Containskey(i.Number__c))
        {
            i.product__c=pMap.get(i.Number__c ).Id;
            break;
        } 
            
        else{
               
        Product2 newp =new Product2();
        if(i.number__c  !=null){        
        newp.Name=i.Number__c;
        }
        if(i.Number__c !=null){
        newp.ProductCode=i.Number__c;
        }
        p2List.add(newp);
        }
       
        insert p2List;
        if(p2List.size() >0){
        i.product__c=p2List[0].id; 
        }
       }
       
       if(trigger.isinsert && trigger.isafter){
       List<project__c> newproj =new List<project__c>();
       set<id> opids=new set<id>();
       newproj=trigger.new;
       Opplist2=[select id,SerialNumber__c,project__c from opportunity where Serialnumber__c =:newproj[0].Serialnumber__c];
       for(project__c I2:newproj){
         opids.add(i2.id);
       }
      if(!opids.isempty()){
      List<opportunity> oList =[select id,project__c from opportunity where Serialnumber__c =:newproj[0].Serialnumber__c];
       for(Opportunity ol:olist){
             
             ol.project__c =trigger.new[0].id;
       }      
      update olist;
      }       
    }
}

 
With good reason, How do I show white space (blank) instead of --none-- in a visualforce case picklist? 

​I have about 10 picklist fields. None are required and I want the ones that have no value to be blank white space instead of "--none--". 

The reason for this is to keep my UI looking clean and readable.
Having 10 fields with a label and "--none--" beside each of them is very cumbersome. I'd much rather they just show blank.

I'm looking to create a custom Pick list field on the "Account" object that is automatically populated based on the options of another field within the Account Object.  For example  the new field name is "Type" and the available options are: Strategic and Emerging. I would like the value of this field to be automatically populated based on the value selected under existing picklst field  field "Vertical" within standard account object.  

Vertical field has the follwoing options: Automotive,  CPG, Entertainment, Financial, Oil Gas and Power, Other, Pharmaceuticals, Restaurants, Retail, Tech, Telecommunications, Travel, Insurance

The mapping will be as follow: 
Automotive - Strategic
CPG - Strategic
Entertainment - Emerging
Financial - Strategic
Oil Gas and Power - Emerging
Other - Emerging
Pharmaceuticals - Strategic
Restaurants - Strategic
Retail - Strategic
Telecommunications - Emerging
Travel  - Emerging
Insurance - Strategic

Greatly appreciate any guidance you can provide. 

Best, 
JP
Hi everyone,

I have to test this class:

List<Account> oldAccounts   = Trigger.old;
        for(Account check : oldAccounts){
            if(check.Account_ID__c!=null){
                check.addError('Accounts that have SAP Account ID can not be deleted');
            }
        }

I know that in theese cases one has to use try/catch methods to solve the test.
But I've been trying for hours and I don't know how to solve it.

I post what I did so far, it covers everything except last line ('addError'):

@isTest
public class TriggerAccountDeleteTest {
      public class MyException extends Exception {}
       static testMethod void metodoDeletAccount(){
        
             //Create an Account with his required fields
             Account accountPrueba = new Account();
                accountPrueba.Name = 'Siemens2';
                accountPrueba.Account_Country__c = 'a014E000005XNKh';
                accountPrueba.Language__c = 'a064E0000060Wnr'; 
                accountPrueba.Department__c = 'Services';
            
            //Insert it
            insert accountPrueba ;
           
            //Test.startTest();  
                try{
                    delete accountPrueba;
                    Account deletedAccount = [SELECT Id, IsDeleted FROM Account WHERE Id = :accountPrueba.Id ALL ROWS];
                    System.assertEquals(deletedAccount.IsDeleted, true);
        
                    }
                 catch(Exception e){
                    Boolean b = null;
                    accountPrueba2.Account_ID__c = String.valueOf(b);
                    System.assert(e.getMessage().contains('Accounts that have SAP Account ID can not be deleted'));
                 }
               Test.stopTest();   
        
    }
}
Thank you for your time
Cheers,
Alberto
Hello,

I want to add a text inside like below

User-added image

caseObj.Descripion= Label.Descrption;

Description label is like
"Date:\nTime:\nname:"

When i try to add this label, it always adds the "Date:\nTime:\nname:"
the new line is never added.

How can i achieve it ?
Hi Everyone,
      I need to conditionally render the highlighted apex out put texts but this is not wotking. Can someone please help me with the code below:
Rendered attribute is dependent on value of Variable ResultSize. The variable is showing the correct value hence I am not putting any apex code . The flow of code is gven below:

1. User key in the input values in input text boxes.
2. There is an onkeyup written on the input boxes. Than on key up function calles for a javascript that in turn calls for the apex action function . This apex action function rerenders the attribute. All other id's are being rerendered fine by action function except id's of out put texts size,size1.

<apex:page controller="ProposalSearchControllerModified" sidebar="false" readonly="True">

  <apex:form >
  <apex:pageMessages id="errors"/>

  <apex:pageBlock title="Search Proposal Records" mode="edit" id="OuterPageBlock">

  <table width="100%" border="0">
  <tr>  
    <td width="200" valign="top">

      <apex:pageBlock title="Search Parameters" mode="edit" id="criteria">

      <script type="text/javascript">

      function doSearch() {
        searchServer(
          document.getElementById("Name").value,
          document.getElementById("OpportunityID").value,
          document.getElementById("SolicitationNo").value,
          document.getElementById("ProposalNo").value

          );

      }
     
   

      </script> 

      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors,size,size1">
          <apex:param name="Name" value="" />
          <apex:param name="OpportunityID" value="" />
          <apex:param name="SolicitationNo" value="" />
          <apex:param name="ProposalNo" value="" />

      </apex:actionFunction>

      <table cellpadding="2" cellspacing="2">
      <tr>
        <td style="font-weight:bold;">Opportunity ID<br/>
        <input type="text" id="OpportunityID" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Solicitation #<br/>
        <input type="text" id="SolicitationNo" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Proposal #<br/>
        <input type="text" id="ProposalNo" onkeyup="doSearch();"/>
        </td>
      </tr>
      


      <tr>
        <td>
          <b><apex:outputText id="size"  style="font-style:Bold;" value="Total Records Returned  :  {!ResultSize}" rendered="{!ResultSize<1000}"/></b>
          <b><apex:outputText id="size1"  style="font-style:Bold;" value="Total Records Returned  :  {!ResultSize} ++" rendered="{!ResultSize==1000}"/></b>

     
         
        </td>  
      </tr>
      

       
   </table>
  </apex:pageBlock>
       

    </td>

    <td valign="top">
    <table style="width: 100%;">
    <td>
    
    <apex:pageBlock mode="edit" id="results">    

        <div style="overflow: auto; height: 300px;">
          
        <apex:pageBlockTable value="{!Opportunities}" var="opp">

            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Opportunity Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Name" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <!--<apex:outputLink value="/apex/SiteDetailPage?id={!opp.id}" target="_blank" rendered="{!IF(URLL=$Label.SalesforceURL,false,true)}">{!opp.Name}</apex:outputLink>
                <apex:outputLink value="/{!opp.id}" target="_blank" rendered="{!IF(URLL=$Label.SalesforceURL,true,false)}">{!opp.Name}</apex:outputLink>-->
                <apex:commandlink value="{!opp.Name}" rerender="RecordDetailSection" action="{!ClearOrder}">                
                 <apex:param name="DetailRecordId"  value="{!opp.Id}" assignTo="{!DetailRecordId}"/>   
                </apex:commandlink>               

            </apex:column>
            


            
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Opportunity ID" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="OpportunityID" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!opp.Opportunity_ID__c}"/>
            </apex:column>
            
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Proposal #" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="ProposalNo" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!opp.Proposal__c}"/>
            </apex:column>          


        </apex:pageBlockTable>
       </div>
       
    </apex:pageBlock>
    
    </td>

    </tr>
    </table>
    
    
    </td>

  </tr>

  </table>

   

  </apex:pageBlock>

  </apex:form>
   

</apex:page>
Hi Everyone,
           Due to some SOQL sub query limitations I have to query list of opportunity records into 2 seperate lists. for our e.g lets call them List A and List B.

So List A gets its values from soql query

List<Opportunity> ListA=[select Id, Name from Opportunity where StageName='Claosed Won'];

List<Opportunity> ListB=[select Id,Name from Oppoortunity where Sub_Stage__c='Aawarded'];

Set<Opportunity> SetC=ListA+ListB.

Now I want to combine List A and List B , take out the duplaicate data out of the combination and make a set out of it  Set c= List A+ List B ( but it should not have any duplaicate records)

Can anyone please help me with the syntax to join 2 lists into a set?

Please note that due to some limits I cannot get all my data into 1 list . The where clause e/g used above are just for theory . It's bit more complicated than that.
email not sent to user .

Trigger : 

trigger checkDuplicateValue on Account (after insert)
{
    if(Trigger.isAfter)
    {   
        //Get list of Users
        Map<Id,User> userMap = new Map<Id,User>([SELECT Name, Email FROM User]);
        
        //Get all Ids in order to do a query
        //and bulkify the trigger
        Set<Id> accIdSet = new Set<Id>();
        for(Account a : Trigger.new)
        {
            accIdSet.add(a.Id);
        }
        
        List<Account> accList = [Select ID, owner.Id, Name, fax, phone 
                                 From Account 
                                 Where Id in :accIdSet];
        
        if(!accList.isEmpty())
        {
            //Create a map with the Name and the Owner Id
            //With the Owner Id I can look for the User in the first Map
            Map<String, Id> accMap = new Map<String, Id>();
            for(Account acc : accList)
            {
                accMap.put(acc.Name, acc.owner.Id);
            }
            
            for(Account acc : Trigger.new)
            {
                String accName = acc.Name;
                if(accMap.containsKey(accName))
                {
                    //Double check the name for the new account
                    Id userId = accMap.get(accName);
                    acc.adderror('Account already exists in your Organization with name ' + acc.Name);
                    
                    //Retrieve the owner's email
                    String theEmail = userMap.get(userId).Email;
                    EmailHelper.sendEmail(theEmail);
                }
            }
        }
    }
}



Class :

public with sharing class EmailHelper
{
    public static void sendEmail(String theEmail)
    {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new String[] {theEmail});
        mail.setSenderDisplayName('My Email');
        mail.setSubject('My email subject');
        mail.setPlainTextBody('Process fails duplicate value');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

 
Hi Folks,

Foe the testMethod: I need to use and access contact data based on the RecordType. I need to acess it Dynamically, i.e., using developerName. Please help if I need to make any chages.With current code I am getting Exception: System.ListException: List index out of bounds. Please help me fixing this. How exactly I should create:  recordtypeid=rlist[3].id

Thanks in advance

list<RecordType> rList = [Select id 
                                            From RecordType 
                                            Where sObjectType = 'Contact'and RecordType.Name = 'developerName'];
                                         
      
            Contact c1, c2, c3, c4, c5;
            c1 = TestUtils.createContact(new Contact(title = 'CEO', Salutation = 'Mr.', Lastname='Contact 1', AccountId=ac1.id, Email='test1@test.com', recordtypeid=rlist[3].id));
            c2 = TestUtils.createContact(new Contact(title = 'CEO', Salutation = 'Mr.', Lastname='Contact 1', AccountId=ac1.id, Email='test2@test.com', recordtypeid=rlist[3].id));
Hello,

I'm new to working on Visualforce pages.

We have an object that if a checkbox field is marked as true by the user, there is a formula field that returns a line of text if true, null if false. An example of one of these formulas is:

IF( Household_Budget_does_not_Show_a_Need__c , "Household budget does not show a need for the level of assistance requested", null)

I have it set to treat blank fields as blank.

There are about 21 of these fields. The problem I'm having with the Visualforce page is that when the field is null, it's still leaving a line of space on the pdf. What I would like is if the value is null, there will be no line of space.

Currently on the Visualforce page, I have it set up like:<apex:outputfield value="{!Application_Update__c.Household_Budget_Text__c}"/> 

How can I display this field that if it's null it will not take up a line of space on the Visualforce page?
This works fine
IF(CONTAINS("VS:BJ", Owner.Alias), "Legacy", 
IF(ISBLANK(BillingState), "International", 
IF(CONTAINS("WA:OR:CA:AZ:NV:IDMT:WY:UT:CO:NM:TX:OK:KS:NE:WY:NE:SD:ND:MN:IA:MO:AR:LA:WI:IL", BillingState), "USA - West", 
IF(CONTAINS("AB:BC:MB:NT:NU:SK:YT", BillingState), "CAN - West", 
IF(CONTAINS("DC:OH:MI:IN:KY:TN:MS:AL:GA:FL:SC:NC:VA:WV:PA:PA:NY:ME:ME:VT:NH:MA:RI:CT:NJ:DE:DE:MD", BillingState), "USA - East", 
IF(CONTAINS("NB:NL:NS:ON:PE:QC", BillingState), "CAN - East", 
"International"))))))
But i need to first evaluate a Checkboxf field.If its TRUE, then should be done, otherwise, continues.  So when I add (first line)
IF(Global_Key_Account__c="TRUE"), "Global",
IF(CONTAINS("VS:BJ", Owner.Alias), "Legacy", 
IF(ISBLANK(BillingState), "International", 
IF(CONTAINS("WA:OR:CA:AZ:NV:IDMT:WY:UT:CO:NM:TX:OK:KS:NE:WY:NE:SD:ND:MN:IA:MO:AR:LA:WI:IL", BillingState), "USA - West", 
IF(CONTAINS("AB:BC:MB:NT:NU:SK:YT", BillingState), "CAN - West", 
IF(CONTAINS("DC:OH:MI:IN:KY:TN:MS:AL:GA:FL:SC:NC:VA:WV:PA:PA:NY:ME:ME:VT:NH:MA:RI:CT:NJ:DE:DE:MD", BillingState), "USA - East", 
IF(CONTAINS("NB:NL:NS:ON:PE:QC", BillingState), "CAN - East", 
"International"))))))
I get Error: Syntax error. Extra ','
Reading up on different formatting but cant get it! thanks-
I have a checkbox in my vf page which is using custom controller. I need to get check box value true in apex class controller when it is checked, so that I can perform my logic based on that checkbox value. How to do that?
Are there any samples or docs for this. I've attempted to create an Apex Trigger on FeedComment, but it's just doesn't seem to work. I would also have to get the user ID of the original post etc.

Essentially all I want to do is send push to a user who's post was commented on. Seems like a pretty standard thing to do. Is there no easy way to do this with the Chatter API?
I have a requirment where selected records in wrapper class shold be displayed seperately.Upon selecting a particualr record and displayed in seperatly,that record should not be allowed to select again in wrapper class.i.e that records check box should be disabled.

How to disable selected records checkboxes only
I have created an email alert and I need to add disc bullet points to HTML Version of email template. I have added the below tags:
<ul type = "disc">
<li> item 1 </li>
</ul>

This is not working, please help me achieve disc bullets!
Hi,
I would like to figure out how to create a formula field that would evaluate stages and set a "phase" based on the stage.
Alternatively, I'd be OK with the Phase being a picklist, but updated from a workflow rule.

So if stages are Planning, Kick-off, Discovery, Software, Data, Training, & Closing, I would want the "phase" field to be set appropriately.

So if stage is in Planning OR Kick-off, then Phase is "Project Planning";
if stage is Discovery OR Software OR Data, then Phase is "Tech"; 
if Stage is Training OR Closing, then Phase is "Closing".

Does anyone have any suggestions?
Thanks!

Hi ,
I am trying to open the VF page and getting following error that The dependent picklist 'Survey' requires its controlling field 'Status' to be present on the page.

Since I have added the both field on the VF page. not sure why?

<apex:page standardController="Case" extensions="CSQuickCloseController" standardstylesheets="false" title="Quick Close" >
    <apex:pageMessages />
    <apex:Form >
       <apex:pageBlock rendered="{!IF( CurrentCase.Quick_Close__c == false, true, false)}">
           <apex:commandButton action="{!backToCasePage}" value="Back To Case" />
       </apex:pageBlock>
       <apex:pageblock title="Case Edit" rendered="{!IF( CurrentCase.Quick_Close__c == true, true, false)}">
           <apex:pageBlockButtons >
               <apex:commandButton value="Save" action="{!CustomSave}"/>
               <apex:commandButton action="{!Cancel}" value="Cancel" />
           </apex:pageBlockButtons>
           <apex:pageBlockSection title="User Efforts" rendered="{!IF(CurrentCase.RecordType.name != 'Training',true,false)}" columns="1">
               <apex:inputField value="{!CurrentCase.Less_than_15_minutes__c}"/>
               <apex:inputField value="{!CurrentCase.Hours_spent__c}"/>
               <apex:inputField value="{!CurrentCase.Minutes_spent__c}"/>
               <apex:outputField value="{!CurrentCase.Total_Time_Spent__c}"/>
           </apex:pageBlockSection>
           <apex:pageBlockSection title="Case Information" columns="1">
              <!--<apex:outputField value="{!CurrentCase.Account.Name}"/>-->
              <apex:inputField value="{!CurrentCase.AccountId}"/>
                <apex:inputField value="{!CurrentCase.ContactId}" required="true"/>
              <apex:outputField value="{!CurrentCase.Status}"/>
              <!--<apex:inputField value="{!CurrentCase.Reason}"/>-->
               <apex:outputField value="{!CurrentCase.Reason}"/>
               <apex:inputField value="{!CurrentCase.Internal_Comments__c}"/>
           </apex:pageBlockSection>
           <apex:pageBlockSection title="Categorisation" rendered="{!IF(CurrentCase.RecordType.name != 'FY16',true,false)}" columns="2">
               <apex:inputField value="{!CurrentCase.Type}" required="true"/>
               <apex:inputField value="{!CurrentCase.Member_Letter__c}"/>
               <apex:inputField value="{!CurrentCase.Category_level_2__c}"/>
               <apex:inputField value="{!CurrentCase.Member_Letter_Ref__c}"/>
               <apex:inputField value="{!CurrentCase.Category_level_3__c}" required="True"/>
               <apex:inputField value="{!CurrentCase.Business_Enhancements__c}"/>
               <apex:inputField value="{!CurrentCase.Category_level_4__c}" required="True"/>
               <apex:inputField value="{!CurrentCase.Business_Enhancement_Date__c}"/>
               <apex:inputField value="{!CurrentCase.Detail__c}" required="True"/>
           </apex:pageBlockSection>
           <!--<apex:pageBlockSection title="Billing Details" columns="2">
               <apex:outputField value="{!CurrentCase.Billing_category__c}"/>
               <apex:inputField value="{!CurrentCase.Quantity__c}"/>
               <apex:outputField value="{!CurrentCase.Rate__c}"/>
               <apex:inputField value="{!CurrentCase.Actual_Fee__c}"/>
               <apex:inputField value="{!CurrentCase.Approved__c}"/>
               <apex:inputField value="{!CurrentCase.Reason_for_Discount__c}"/>
               <apex:inputField value="{!CurrentCase.Reason_for_Cancellation__c}"/>
               <apex:inputField value="{!CurrentCase.Billing_BIN__c}"/>
           </apex:pageBlockSection>-->
          <apex:pageBlockSection title="Survey" rendered="{!IF(CurrentCase.RecordType.name != 'Finance' && CurrentCase.RecordType.name != 'Treasury' && CurrentCase.RecordType.name != 'FY16' && CurrentCase.RecordType.name != 'CBDIP' && CurrentCase.RecordType.name != 'Fraud'  && CurrentCase.RecordType.name != 'Training',true,false)}" columns="2">
              
               <apex:InputField value="{!CurrentCase.Do_Not_Survey_picklist__c}" required="True"/>
               <apex:inputField value="{!CurrentCase.Survey_Type__c}" required="True"/>
               <apex:InputField value="{!CurrentCase.DNS_Reason__c }" required="True"/>
               <apex:inputField value="{!CurrentCase.Multiple_Case_workers__c}"/>
               <apex:inputField value="{!CurrentCase.DNS_Reason_Other__c}"/>
           </apex:pageBlockSection>
       </apex:pageblock>  
    </apex:Form>
</apex:page>
 
Can we use formulas in email templates such as TODAY()? I tried but it did not work.Any workarounds other than creating a formula fields and merging them?