• Rocio Vivanco
  • NEWBIE
  • 75 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 4
    Likes Received
  • 0
    Likes Given
  • 37
    Questions
  • 45
    Replies
Hi all,

I see that even if you set who is the Sender in your email using an email batch job, you will get an email with the sender format:

<noreply.salesforce.com> on behalf of <email address of user who started the job>

I don't wish this to appear, even if I uncheck the Email Compliance ID checkbox via Email Administration --> Deliverability I get the wrong sender, that means, the email address of the user who started the batch job.

Now I was trying to use a similiar part of code like this:
 
// Use Organization Wide Address  
for(OrgWideEmailAddress owa : [select id, Address, DisplayName from OrgWideEmailAddress]) {
if(owa.Address.contains('CSR')) email.setOrgWideEmailAddressId(owa.id); }

after adding an organization wide address and using the sender email address for this. But after starting the batch job, this is still sending me an email where the sender email address is the one of the user who started the job and not the given to the owa Variable in the code.

Is there a way or trick to handle this?



 
Hi all,

when trying to run my test class, this fails with the error:
 
System.NullPointerException: Attempt to de-reference a null object

This is pointing to the code line in my apex class "String [] toEmailAddress = new String [] {er.ToEmailAddress__c};":
 
global void sendEmail(){

        Messaging.reserveSingleEmailCapacity(2);
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        // Strings to hold the email addresses to which you are sending the email.
        Email_Reminder__c er = Email_Reminder__c.getInstance('List');
        String [] toEmailAddress = new String [] {er.ToEmailAddress__c};
        String replyToAddress = er.replytoAddress__c;
        String SenderDisplayName= er.SenderDisplayName__c;

  ...

​and to one line before the Test.startTest() begins. This is my test class:
 
@isTest
public class EmailReminder_Test {
    static testMethod void testMethod() {
       
      insert new Email_Reminder__c(Name =='TestCS',
                                                         ToEmailAddress__c='test@email.com', 
                                                         replytoAddress__c = 'test@email.com', 
                                                         Subject__c = 'Test Email Reminder',
                                                         SenderDisplayName__c = 'Test Sender', Body__c = 
                                                         'This is a test email reminder');

      Test.startTest();
      EmailReminder sendEmailJob = new EmailReminder();
      String sch = '00 30 20 5 2 ? *';
      system.schedule('sendEmailJob', sch, sendEmailJob);
      Test.stopTest();
    
    }
    
}
I tried to fix it, but can not handle this til now. Any tips?
 
Hi all,

I have been trying to find out how can I use custom settings in apex code when it comes to use the sendEmail function.
For example, I have the following code lines:
 
global void sendEmail(){

 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 // Assign the addresses for the To and CC lists to the mail object.
        mail.setToAddresses('myToAddress@email.com');
        
        // Specify the address used when the recipients reply to the email. 
        mail.setReplyTo('myToAddress@email.com');
        
        // Specify the name used as the display name.
        mail.setSenderDisplayName('Salesforce Email Reminder');
        
        // Specify the subject line for your email address.
        mail.setSubject('Yearly Email Reminder');
        
        // Set to True if you want to BCC yourself on the email.
        mail.setBccSender(false);
        
        mail.setUseSignature(false);
    
        
        mail.setHtmlBody('This is a test email');
I have created a Custom Setting Test__c with the following fields and values in one record:

- ToAddress = 'myToAddress@email.com'
- replyToAddress = 'myToAddress@email.com'
- SenderDisplayName = 'Salesforce Email Reminder'
- Subject = 'Yearly Email Reminder'
- Body = 'This is a test'

Now, how can I replace the values in the parethesis for the respective email methods mail.setToAddresses(), etc. by the above mentioned custom setting. How can I invoke these custom setting values in the APEX code?. 

I would appreciate your answers.

 
Hi all,

I was searching for a possibility to send a yearly email reminder when the 1st. February in that year comes.
The only criteria to fire the email reminder is that so long it is the 1st. February in the year, the reminder has to be fired.

I tried to let a workflow rule or process to make this using a Date formula field, but this didn't work.

I was then thinking of implementing a batch apex job and schedule it to run every 1st February of every year. But this batch job should only send an email, nothing else.
When I see batch job codes, they all include: 
 
...
global database.querylocator start(Database.BatchableContext BC)
{
    return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, Sobject[] scope)
...

and the sendEmail is then used in a Finish part of the code.
The point is, I just want to send an email. The batch code doesn't need to be executed for specific or all accounts. It is about sending a notification like "Please don't forget to configure this on the 1st February", nothing else.

Would be enough if I write this code?:
 
private void sendEmail(){

        Messaging.reserveSingleEmailCapacity(2);
        

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        // Strings to hold the email addresses to which you are sending the email.
        String[] toAddresses = new String[] {[Select EmailAddress__c From CS_EmailAddresses__c Limit 1].EmailAddress__c};
          
        // Assign the addresses for the To and CC lists to the mail object.
        mail.setToAddresses(toAddresses);
        
        // Specify the address used when the recipients reply to the email. 
        mail.setReplyTo('mycompany@mydomain.com');
        
        // Specify the name used as the display name.
        mail.setSenderDisplayName('Salesforce Email Reminder');
        
        // Specify the subject line for your email address.
        mail.setSubject('Yearly Email Reminder');
        
        // Set to True if you want to BCC yourself on the email.
        mail.setBccSender(false);
        
        // Optionally append the salesforce.com email signature to the email.
        // The email address of the user executing the Apex Code will be used.
        mail.setUseSignature(false);
        
        // Specify the text content of the email.
        //mail.setPlainTextBody('Please configure this');
        
        mail.setHtmlBody('Your Invitee batch job has been processed.<br/><br/>Best Regards);
        
        // Send the email you have created.
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

 
Hi all,

we are facing a serious issue.
We have a batch APEX job running daily which makes updates on records fulfilling certain conditions. There is another job running parallel to this, in some cases updating or accessing to the same records than the batch job and hence, causing the error:
 
​Update failed. First exception on row 400 with id XXX; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 200 records:

So, I had then read that in order to fix this kind of error you should use FOR_UPDATE in your select statement (records that have to be updated).
The problem is, that you can not use FOR UPDATE for batch jobs. We tested this and effectively, we get the error:
 
System.QueryException: Locking is implied for each batch execution and therefore FOR UPDATE should not be specified
Then:
It will however lock the records within each execution of execute. See QueryLocator.getQuery()usage:

You cannot use the FOR UPDATE keywords with a getQueryLocator query to lock a set of records. The start method automatically locks the set of records in the batch.

Could you find a solution to this?. We would like to handle this in the code itself, because we don't have the permission to schedule the batch job for another time as the another job.

 
Hi all,

I have the same question as the guy in this thread:

https://success.salesforce.com/answers?id=9063000000048tfAAA

When you look at an email in Outlook which comes from an existing contact in Salesforce, you can see in the side panel the Activity history, open activities, related opportunities and cases this contact has. What we want is to be able to add the related list Sales Projects in addition to the alrady mentioned ones, like in this example:

User-added image

I am not talking about Publisher actions, I am talking about adding related lists (custom object) in the side panel. Is that possible to customize? if possible, how?.
our client notified us that a scheduled job ran on the 15th December 2017 and it took longer than expected. Checking the processed jobs and their submitted dates, I couldn't find any job running on the 15th December, although the job has been scheduled for running daily. It shows that it ran from 28th December.
How can I check, for example via a SOQL query, if the APEX job really ran on the 15th December and how long it took to run?.
I would appreciate any help here.
Hi all,

I am confuse about how batch jobs work. I scheduled an APEX job to run once a week. The job has run, but I don't know how many records it worked. The job run every minute from 00:00 - 13:42. It seems that my batch job has been processed 734 times:

User-added image
in each loop (734 loops) it processed 5 batch jobs. I guess that is what my screenshot describes.
I would appreciate answers about:

- What is Total Batches?
- What is Batches processed?
- What these 734 loops could mean?
Hi all,

I was wondering if there is a possibility to update a field with the value on another field without saving the record and use this field in a sharing rule.

For example, I have the field X in the object Account. The value is 'Value X'. I have a field X in the object Opportunity which should have the same value as in the X field in the object Account, that means, the value would be in this case 'Value X' as well. Now, I would like to have a process or something suitable to update the value in field X of the Opportunity everytime the value in the field X of the Account changes, all this without saving the record (that's why I can not use a workflow rule in this case). 

On the other hand, I need to use the value in the field X of the Opportunity in a sharing rule.

Is there a possibility to implement these requirements in Salesforce? how?.
Hi all,

hopefully can somebody help me with this issue.
When creating a record in Salesforce via form in Visualforce, this creates a view with a weird ID as label:

User-added image

As you can see a list view with the ID 00B3E... is being created, which is an issue in fact. When I click on that ID this leads me to this page:

User-added image


Did someone here experience this issue? does anybody have an idea what's going on here?.
Hi all,

I have been looking for an answer to my question: how to add an image to a Visualforce email template without using hard coding?.
Some say a possibility to add an image is storing the image in the Documents tab and then use this URL for the image:
 
https://AAA.salesforce.com/servlet/servlet. ImageServer?id=BBB&oid=CCC

The link where I found such a possible solution is this:
 
https://salesforce.stackexchange.com/questions/4641/is-is-possible-to-display-an-image-or-icon-in-a-email-using-a-visualforce-templa
The problem is: what about if you have many email templates to deploy in another organization?. Hence, hardcoding within the Visualforce email template in order to show the image, for example, the logo of an organization, is not a good solution.

We have 100 Visualforce email templates using the suggested URL, ok, it works, the image is being shown when you send the email, but as said, the problem is in the deployment of these email templates because of the use of hardcoding.

I would appreciate messages here how you solved this otherwise? (I have read that use of static ressources for this is not recommendable as well).

 
Hi all,

I have an object with three record types.
We created a Visualforce email template related to the object. The object we are using is Product2 and the record types are:

- Master
- Undergraduate
- PhD

But our email template is related to this object in general, but not to a specific record type. For example, the email template for Masters should be related to the record type Master. The email template for PhDs should be related to the record type PhD.

Is this possible in Salesforce or not at all?.

I would appreciate your answers.
I am not a Salesforce architect, but I would like to learn from the best practices.
When is appropriate to create record types? when is appropriate to put things under the same entity? in which cases? when is appropriate to put things in separate entities?.

Some say, if objects have many fields in common they should be in a same entity and build record types. Which other cases should lead to think of putting objects/things under the same entity and using record types?.

Which are the best practices?.
Hi all,

I have a code where I am using URLs and don't want to hardcode IDs in my APEX Code, so I was looking for syntax how to declare a URL with custom labels.

For example, this is the code which works in APEX:
 
public PageReference GotoPreinscripcionList() {

      shouldRedirect = true;
      url = '/a05?fcf=00B3E000000TsVm';
      //url.setredirect(true);
      return null;
     
     }
And this is the last attempt to make it work with custom labels (my 100th try):
 
public PageReference GotoPreinscripcionList() {

       shouldRedirect = true;
       String preinscripcion_FR_Id = Label.Preinscripcion_FR_ID;
       String preinscripcion_listview_Id = 
       Label.Preinscripcion_Postgrado_ListView;
       url = 'preinscripcion_FR_Id?fcf=preinscripcion_listview_Id';
       //url.setredirect(true);
       return null;
    }
Nothing happens. Even with 
 
String preinscripcion_listview_Id = 
       '{!$Label.Preinscripcion_Postgrado_ListView}';
Does anybody know how to handle this?


 
Hi all,

many speak of custom related lists with the possibility to edit or delete records on them.
I have built a visualforce component to show a custom related list with filter. This Visualforce component is within a tab panel:

User-added image


The problem is: If I click for example on the Edit Action, this leads you to the record but within the Visualforce embedded in the section "Trayectoria":

User-added image

This is an undesirable effect I would like to avoid or amend. If I click on the Edit Action I would like this to lead me to the Edit mode of the object on the tab of this object/entity, so here:

User-added image

My Visualforce page is this:
 
<apex:component access="global" controller="SIs_Test">

  <apex:attribute name="accountIdValue" type="String" description="This is the Id of the account" assignTo="{!accountId}" access="global" />

    <apex:form >
       <apex:pageblock id="CustomList" title="Solicitudes de Información">
          <apex:pageblocktable value="{!solinfos}" var="solinfo" rendered="{!NOT(ISNULL(solinfos))}">
              <apex:column >
                  <apex:facet name="header">Action</apex:facet>
                  <apex:commandLink action="{!editSolInfo}" value="Edit">
                  <apex:param name="solinfoid" value="{!solinfo.id}"/>
                  </apex:commandLink> &nbsp; | &nbsp;   <apex:commandLink action="{!deleteSolInfo}" value="Delete">
                  <apex:param name="solinfoid" value="{!solinfo.id}"/>
                  </apex:commandLink>
              </apex:column>
              <apex:column headerValue="Código de SI"> <apex:outputLink value="/{!solinfo.id}">{!solinfo.name}</apex:outputLink> </apex:column>
              <apex:column value="{!solinfo.Nombre_de_candidato__r.Name}"/>  
          </apex:pageblocktable>
       </apex:pageblock>
    </apex:form>

 </apex:component>
And this part of my the Apex class:
 
global List<Solicitud_de_contacto__c> getSolInfos()
    {
   
     solinfos = [Select id, Name, Nombre_de_candidato__r.Name from Solicitud_de_contacto__c where Nombre_de_candidato__r.id =: accountId];
     return solinfos;
    }
    
    public Pagereference editSolInfo()
    {
       String solinfoid= ApexPages.currentPage().getParameters().get('solinfoid'); 
     
       return new PageReference('/a0B/e?id='+solinfoid+'&retURL=/a0B/');
    }
    
    public Pagereference deleteSolInfo()
    {
       String solinfoid= ApexPages.currentPage().getParameters().get('solinfoid'); 
     
       Solicitud_de_contacto__c solinfo = [Select id from Solicitud_de_contacto__c where id =:solinfoid limit 1];
       if(solinfo !=null && solinfo.id !=null){
         delete solinfo;
       }
       return null;
    }
How can I amend my apex code, so the Edit action leads to desired and normal place where an Edit action on a related list without customization normally leads?.
I would appreciate any tips.




 
Hi all,

I am trying to make a rendering work with a combination of my email template, a visualforce component and an apex, controller class.

My email template has as RelatedToType the object Opportunity. In the email there should be displayed the most important account data (Account lookup in the object Opportunity). It should also show the contacts to this account, which have their Codigo_JDE__c empty.

What I would like to achieve is to display these contacts only if there are any, if not, the part to display the table of these contacts, should not be displayed.

Here is the part in my email template where I am invoking the Visualforce component:
 
<c:AccountContacts accountIdValue="{!relatedTo.AccountId}"/>

Here is my Visualforce component:
 
<apex:component access="global" controller="AccountContacts">

    <apex:attribute name="accountIdValue" type="String" description="This is the Id of the account" assignTo="{!accountId}" access="global" />
    
    <apex:outputPanel rendered="{!IF(AND(NOT(ISBLANK(conList)),conList.size>0),'Yes','No')}">  
    <tr >
        <td >
          Contact data:<br/><br/>
    
           <table>
           <thead>    
              <tr>
                <th>FIRST NAME</th> 
                <th>LAST NAME</th>
              </tr>
           </thead>        
           <tbody>
           <apex:repeat value="{!Cons}" var="pos">
              <tr>
                <td>{!pos.FirstName}</td>
                <td>{!pos.LastName}</td>                                        
              </tr>
                    
        </apex:repeat>
        </tbody>   
    </table>
   </td>
  </tr>
  </apex:outputpanel>

</apex:component>

I am using this part in the code:
 
rendered="{!IF(AND(NOT(ISBLANK(conList)),conList.size>0),'Yes','No')}"
to render only if the conList is not empty. The conList is declared in the apex class:
 
global with sharing class AccountContacts{
    
    global String accountId{get;set;}
    
    global List<Contact> conList{get;set;}

    global account account{
        get {
          Account = [Select Id, name from Account where id =: accountId];
          return account; }
       set;
    }
    
    global AccountContacts(){

    }
    
    
    global List<Contact> Cons{
        get{        
  
            List<Contact> conList = [SELECT Id,FirstName,LastName,Codigo_JDE__c FROM Contact WHERE AccountId=:accountId and Codigo_JDE__c = null];
            
            Boolean display = false;
            
            if(conList != null && conList.size()>0){

             display=true;
            
            }
            return conList;
        }
        set;
    }
    
    
    global String NewLine {
        get { return '\r\n'; }
        set;
    }
    
}
Unfortunately when I receive the email, even when there are contacts with Codigo_JDE__c empty, they are not being displayed (the table is not being displayed), why?.
I would appreciate if someone could give me tips where to correct this, as I have been spending hours trying to amend this without success.

 
Hi all,

I have read that it is recommended to have only one trigger for object. Is it possible to create more than one trigger handler per object?.

 
Hi all,

I don't know if this is the suitable place to post this thread.
I have to embed a Google Analytics code to my Visualforce page. The VF page is already published on the Web through a created site.

I added the GA code between the <script> </script> in the head tag in the visualforce this way:
 
<script>
 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-mycode-1', 'auto', {'allowLinker': true});
  ga('require', 'linker');
  ga('linker:autoLink', ['mycompany.com'] );

</script>
The Visualforce URL is something like this:
 
https://mycompany.secure.force.com/myfolder/myvisualforcepage
Is the GA code embedded in my Visualforce correct?, especially:

1. Is the domain name in the last line correct?
2. Is there something missing there?. The aim is to get the VF page tracked.

I would appreciate any help.

 
Hi all,

I am trying to build an email template, where I can diaplay information about three objects:

- Opportunity has a lookup to Account
- Account has a Contacts related list

What I want is to show:

- Opportunity.Name : it is possible
- Account data: it is possible
- Contacts data: not possible?

The RelatedToType would be Opportunity, so when the opportunity has change in the stage, this should fire an automatic email, the content in the email template.

Does anybody know if this can be handled in an email template?
Hi all,

unfortunately I couldn't find a solution to this.
I have the following code:
 
Datetime eventdate = event.EndDateTime;
               
               String dateOutput = eventdate.format('dd-MM-yyyy');
               event.Subject = 'Visit ' + acc_name + ' ' + eventdate;
Event has a field EndDateTime which is a Date Time type, but what I want is to convert that format to "dd-mm-yyyy".
I can save the event through Apex, but my subject appears as: Visit Test2 2017-05-31 10:00:00 (for example)

My Salesforce application timezone looks like this:

User-added image

In Spain we use to set the date dd/mm/yyyy or dd-mm-yyyy, but we need the application in English because our users require this.
Any idea how to convert the EndDateTime.

I would appreciate any help.
 
Hi all,

I am working on this since hours trying many code forms, trying with java script, with ajax, etc., without success.

For a special reason I am using two form tags in my Visualforce code.
I have the same case as here described:

https://salesforce.stackexchange.com/questions/8320/how-to-handle-two-form-tags-in-visualforce-page

My javascript code looks like this (this is one of my trials):
 
<apex:form >
             <script type="text/javascript">
                function grabExName(){
                  var ex = document.getElementById('optypage:cform:new_info').value;
                  alert(ex);
                }
             </script>
             <apex:actionFunction name="UpdateRelevantInformation" action="{!UpdateRelevantInformation}" reRender="out" oncomplete="grabExName();">
                <apex:param name="new_info" value="" />
             </apex:actionFunction>
        </apex:form>
This is in the "<body>" part of the code.

My commandbutton looks like this:
 
<apex:commandlink styleclass="btn btn-primary" id="new_info" value="Save new info" action="{!UpdateRelevantInformation}"  />

When I click that button it should let work the form with id "cform", so that when I click on the button, the functionality behind the action "UpdateRelevantInformation" should work.
Am I missing something here? because when I put the button on the second form, "UpdateRelevantInformation" doesn't do anything, but if I put the button in the first form, where the item Relevant Information should be updated, the button works.

I would appreciate your help.
 
Hi all,

I am trying to display/retrieve a given date in the format dd/mm/yyyy, but without success til now.

What is being displayed is this:

User-added image

My code in Visualforce is this:
 
<td style="white-space:nowrap;">
                  <apex:inputText value="{0,StartDateTime,MM'/'dd'/'yyyy}" disabled="true" >
                   <apex:param value="{!evento.StartDateTime}" /> 
                  <apex:inputText>
</td>
Even if I replace "inputText" by "outputText", under my problems list appears "disabled not compatible with outputtext.

StartDateTime is a field in the Event object and it is shown that way probably because my time zone is a British timezone:

User-added image

Users want the timezone in English and not Spanish.
Is there any form to display the date time in the format dd/mm/yyyy? (example: 17/05/2017)

I would appreciate tips.
 
Hi all,

I am trying to display a table using the <table> tag and pageblocksection, but fields appear dispersed:
 
<apex:pageBlock id="newopty"  rendered="true" title="New Opportunity">
        <apex:pageBlockSection id="Lapse" columns="2" collapsible="true" title="New Opportunity">
         <html>
           <table class="list" border="0" cellspacing="0" cellpadding="0" style="width:100% !important">
              <tr class="headerRow">
                  <th><b>Name</b></th>
                  <th><b>FDF</b></th>
                  <th><b>Feedback</b></th>
              </tr>
              <tr>
                 <td style="white-space:nowrap;"><apex:inputText id="optyname" value="{!optyname}" /></td>                  
                 <td style="white-space:nowrap;"><apex:inputCheckbox id="FDFcheck" value="{!FDFcheck}"/></td>
                 <td rowspan="7" style="white-space:nowrap;"><apex:inputTextarea id="feedback" value="{!feedback}" rows="7" /></td>
              </tr>
              <tr class="headerRow">
                 <th><b>Product</b></th>
                 <th><b>API</b></th>
              </tr>
              <tr>
                 <td style="white-space:nowrap;"><apex:inputText list="{!listOfproducts}" value="{!prodfamily}" /></td>
                 <td style="white-space:nowrap;"><apex:inputCheckbox value="{!APIcheck}" id="APIcheck" /></td>
              </tr>
              <tr class="headerRow">
                 <th><b>Close Date</b></th>
                 <th><b>Close lost</b></th>
               </tr>
               <tr>
                 <td style="white-space:nowrap;"><apex:inputText value="{!datename}" size="10" id="demo" onfocus="DatePicker.pickDate(false, this , false);"/>
                 </td>
                 <td style="white-space:nowrap;"><apex:inputCheckbox value="{!closelost}" id="closelost" /></td>
               </tr>
           </table>
          </html>
              <apex:commandButton value="submit" action="{!Submit}"/>
        </apex:pageBlockSection>
</apex:pageblock>
User-added image

I don't want to use pageTable as I am not displaying a list of records.
Someone here was facing the same issue, I tried to solve as described in his thread, but without success til now.
I would appreciate any tips, is it possible to use <table> with <apex:pageblocksection>?
 
Hi all,

I am having problems to save my controller code. It is about add contacts in a textarea, these contacts should be filtered by a given account.
Besides, It should control the functionality of a popup displaying a checkbox and the contact name.
I have added these code lines to my controller:
 
public with sharing class MyController {
  public string lookUp{get;set;}
   public list<Contact> contactList{get;set;}
   public Id accountId {get; set;}
   public boolean bool{get;set;}
   public set<id> contactids{get;set;}
   public boolean check{get;set;}
   public list<conContact> conList{get;set;}
   public ApexPages.StandardController controller;

  public MyController(ApexPages.StandardController con) {
     
      controller = con;
      conList = new list<conContact>();
      bool = false;
      contactids = new Set<Id>();
   }

public class conContact{

       public Contact con{get;set;}
       public boolean check{get;set;}

       public conContact(Contact c, boolean boo){
         con = c;
         check = boo;
       }
   }
    
    
    public void init_contact(){
       list<Contact> selectedContacts = new list<Contact>();
       lookUp = '';
       for(conContact conObj  : conList){
           if(conObj.check != false){  
              system.debug('conObj.con'+conObj,con);
              selectedContacts.add(conObj.con);
              lookUp += conObj.con.name + ' ,' ;
              system.debug('lookUp::'+lookUp);
              contactids.add(conObj.con.id);
            }
        }
        bool = true;
   }

But I get the error:

Variable does not exist: con

I have checked my code and it seems to be everything ok. Perhaps, is there something I am missing here?. What would it be?.

I would appreciate if someone could give me tips.
Hi all,

I see that even if you set who is the Sender in your email using an email batch job, you will get an email with the sender format:

<noreply.salesforce.com> on behalf of <email address of user who started the job>

I don't wish this to appear, even if I uncheck the Email Compliance ID checkbox via Email Administration --> Deliverability I get the wrong sender, that means, the email address of the user who started the batch job.

Now I was trying to use a similiar part of code like this:
 
// Use Organization Wide Address  
for(OrgWideEmailAddress owa : [select id, Address, DisplayName from OrgWideEmailAddress]) {
if(owa.Address.contains('CSR')) email.setOrgWideEmailAddressId(owa.id); }

after adding an organization wide address and using the sender email address for this. But after starting the batch job, this is still sending me an email where the sender email address is the one of the user who started the job and not the given to the owa Variable in the code.

Is there a way or trick to handle this?



 
Hi all,

when trying to run my test class, this fails with the error:
 
System.NullPointerException: Attempt to de-reference a null object

This is pointing to the code line in my apex class "String [] toEmailAddress = new String [] {er.ToEmailAddress__c};":
 
global void sendEmail(){

        Messaging.reserveSingleEmailCapacity(2);
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        // Strings to hold the email addresses to which you are sending the email.
        Email_Reminder__c er = Email_Reminder__c.getInstance('List');
        String [] toEmailAddress = new String [] {er.ToEmailAddress__c};
        String replyToAddress = er.replytoAddress__c;
        String SenderDisplayName= er.SenderDisplayName__c;

  ...

​and to one line before the Test.startTest() begins. This is my test class:
 
@isTest
public class EmailReminder_Test {
    static testMethod void testMethod() {
       
      insert new Email_Reminder__c(Name =='TestCS',
                                                         ToEmailAddress__c='test@email.com', 
                                                         replytoAddress__c = 'test@email.com', 
                                                         Subject__c = 'Test Email Reminder',
                                                         SenderDisplayName__c = 'Test Sender', Body__c = 
                                                         'This is a test email reminder');

      Test.startTest();
      EmailReminder sendEmailJob = new EmailReminder();
      String sch = '00 30 20 5 2 ? *';
      system.schedule('sendEmailJob', sch, sendEmailJob);
      Test.stopTest();
    
    }
    
}
I tried to fix it, but can not handle this til now. Any tips?
 
Hi all,

I have been trying to find out how can I use custom settings in apex code when it comes to use the sendEmail function.
For example, I have the following code lines:
 
global void sendEmail(){

 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 // Assign the addresses for the To and CC lists to the mail object.
        mail.setToAddresses('myToAddress@email.com');
        
        // Specify the address used when the recipients reply to the email. 
        mail.setReplyTo('myToAddress@email.com');
        
        // Specify the name used as the display name.
        mail.setSenderDisplayName('Salesforce Email Reminder');
        
        // Specify the subject line for your email address.
        mail.setSubject('Yearly Email Reminder');
        
        // Set to True if you want to BCC yourself on the email.
        mail.setBccSender(false);
        
        mail.setUseSignature(false);
    
        
        mail.setHtmlBody('This is a test email');
I have created a Custom Setting Test__c with the following fields and values in one record:

- ToAddress = 'myToAddress@email.com'
- replyToAddress = 'myToAddress@email.com'
- SenderDisplayName = 'Salesforce Email Reminder'
- Subject = 'Yearly Email Reminder'
- Body = 'This is a test'

Now, how can I replace the values in the parethesis for the respective email methods mail.setToAddresses(), etc. by the above mentioned custom setting. How can I invoke these custom setting values in the APEX code?. 

I would appreciate your answers.

 
Hi all,

I was searching for a possibility to send a yearly email reminder when the 1st. February in that year comes.
The only criteria to fire the email reminder is that so long it is the 1st. February in the year, the reminder has to be fired.

I tried to let a workflow rule or process to make this using a Date formula field, but this didn't work.

I was then thinking of implementing a batch apex job and schedule it to run every 1st February of every year. But this batch job should only send an email, nothing else.
When I see batch job codes, they all include: 
 
...
global database.querylocator start(Database.BatchableContext BC)
{
    return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, Sobject[] scope)
...

and the sendEmail is then used in a Finish part of the code.
The point is, I just want to send an email. The batch code doesn't need to be executed for specific or all accounts. It is about sending a notification like "Please don't forget to configure this on the 1st February", nothing else.

Would be enough if I write this code?:
 
private void sendEmail(){

        Messaging.reserveSingleEmailCapacity(2);
        

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        // Strings to hold the email addresses to which you are sending the email.
        String[] toAddresses = new String[] {[Select EmailAddress__c From CS_EmailAddresses__c Limit 1].EmailAddress__c};
          
        // Assign the addresses for the To and CC lists to the mail object.
        mail.setToAddresses(toAddresses);
        
        // Specify the address used when the recipients reply to the email. 
        mail.setReplyTo('mycompany@mydomain.com');
        
        // Specify the name used as the display name.
        mail.setSenderDisplayName('Salesforce Email Reminder');
        
        // Specify the subject line for your email address.
        mail.setSubject('Yearly Email Reminder');
        
        // Set to True if you want to BCC yourself on the email.
        mail.setBccSender(false);
        
        // Optionally append the salesforce.com email signature to the email.
        // The email address of the user executing the Apex Code will be used.
        mail.setUseSignature(false);
        
        // Specify the text content of the email.
        //mail.setPlainTextBody('Please configure this');
        
        mail.setHtmlBody('Your Invitee batch job has been processed.<br/><br/>Best Regards);
        
        // Send the email you have created.
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

 
Hi all,

I am confuse about how batch jobs work. I scheduled an APEX job to run once a week. The job has run, but I don't know how many records it worked. The job run every minute from 00:00 - 13:42. It seems that my batch job has been processed 734 times:

User-added image
in each loop (734 loops) it processed 5 batch jobs. I guess that is what my screenshot describes.
I would appreciate answers about:

- What is Total Batches?
- What is Batches processed?
- What these 734 loops could mean?
Hi all,

I have been looking for an answer to my question: how to add an image to a Visualforce email template without using hard coding?.
Some say a possibility to add an image is storing the image in the Documents tab and then use this URL for the image:
 
https://AAA.salesforce.com/servlet/servlet. ImageServer?id=BBB&oid=CCC

The link where I found such a possible solution is this:
 
https://salesforce.stackexchange.com/questions/4641/is-is-possible-to-display-an-image-or-icon-in-a-email-using-a-visualforce-templa
The problem is: what about if you have many email templates to deploy in another organization?. Hence, hardcoding within the Visualforce email template in order to show the image, for example, the logo of an organization, is not a good solution.

We have 100 Visualforce email templates using the suggested URL, ok, it works, the image is being shown when you send the email, but as said, the problem is in the deployment of these email templates because of the use of hardcoding.

I would appreciate messages here how you solved this otherwise? (I have read that use of static ressources for this is not recommendable as well).

 
I am not a Salesforce architect, but I would like to learn from the best practices.
When is appropriate to create record types? when is appropriate to put things under the same entity? in which cases? when is appropriate to put things in separate entities?.

Some say, if objects have many fields in common they should be in a same entity and build record types. Which other cases should lead to think of putting objects/things under the same entity and using record types?.

Which are the best practices?.
Hi all,

I have a code where I am using URLs and don't want to hardcode IDs in my APEX Code, so I was looking for syntax how to declare a URL with custom labels.

For example, this is the code which works in APEX:
 
public PageReference GotoPreinscripcionList() {

      shouldRedirect = true;
      url = '/a05?fcf=00B3E000000TsVm';
      //url.setredirect(true);
      return null;
     
     }
And this is the last attempt to make it work with custom labels (my 100th try):
 
public PageReference GotoPreinscripcionList() {

       shouldRedirect = true;
       String preinscripcion_FR_Id = Label.Preinscripcion_FR_ID;
       String preinscripcion_listview_Id = 
       Label.Preinscripcion_Postgrado_ListView;
       url = 'preinscripcion_FR_Id?fcf=preinscripcion_listview_Id';
       //url.setredirect(true);
       return null;
    }
Nothing happens. Even with 
 
String preinscripcion_listview_Id = 
       '{!$Label.Preinscripcion_Postgrado_ListView}';
Does anybody know how to handle this?


 
Hi all,

I am trying to make a rendering work with a combination of my email template, a visualforce component and an apex, controller class.

My email template has as RelatedToType the object Opportunity. In the email there should be displayed the most important account data (Account lookup in the object Opportunity). It should also show the contacts to this account, which have their Codigo_JDE__c empty.

What I would like to achieve is to display these contacts only if there are any, if not, the part to display the table of these contacts, should not be displayed.

Here is the part in my email template where I am invoking the Visualforce component:
 
<c:AccountContacts accountIdValue="{!relatedTo.AccountId}"/>

Here is my Visualforce component:
 
<apex:component access="global" controller="AccountContacts">

    <apex:attribute name="accountIdValue" type="String" description="This is the Id of the account" assignTo="{!accountId}" access="global" />
    
    <apex:outputPanel rendered="{!IF(AND(NOT(ISBLANK(conList)),conList.size>0),'Yes','No')}">  
    <tr >
        <td >
          Contact data:<br/><br/>
    
           <table>
           <thead>    
              <tr>
                <th>FIRST NAME</th> 
                <th>LAST NAME</th>
              </tr>
           </thead>        
           <tbody>
           <apex:repeat value="{!Cons}" var="pos">
              <tr>
                <td>{!pos.FirstName}</td>
                <td>{!pos.LastName}</td>                                        
              </tr>
                    
        </apex:repeat>
        </tbody>   
    </table>
   </td>
  </tr>
  </apex:outputpanel>

</apex:component>

I am using this part in the code:
 
rendered="{!IF(AND(NOT(ISBLANK(conList)),conList.size>0),'Yes','No')}"
to render only if the conList is not empty. The conList is declared in the apex class:
 
global with sharing class AccountContacts{
    
    global String accountId{get;set;}
    
    global List<Contact> conList{get;set;}

    global account account{
        get {
          Account = [Select Id, name from Account where id =: accountId];
          return account; }
       set;
    }
    
    global AccountContacts(){

    }
    
    
    global List<Contact> Cons{
        get{        
  
            List<Contact> conList = [SELECT Id,FirstName,LastName,Codigo_JDE__c FROM Contact WHERE AccountId=:accountId and Codigo_JDE__c = null];
            
            Boolean display = false;
            
            if(conList != null && conList.size()>0){

             display=true;
            
            }
            return conList;
        }
        set;
    }
    
    
    global String NewLine {
        get { return '\r\n'; }
        set;
    }
    
}
Unfortunately when I receive the email, even when there are contacts with Codigo_JDE__c empty, they are not being displayed (the table is not being displayed), why?.
I would appreciate if someone could give me tips where to correct this, as I have been spending hours trying to amend this without success.

 

Hi All,

 

I have a requirement to add my cases component on home page layout.

How can i go about it without creating a complete visualforce page ?