• MariP
  • NEWBIE
  • 75 Points
  • Member since 2010

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 16
    Replies

Hi everybody,

 

The users can populate a text area with free email addresses.

I put them in a list (I suppose they have put ";" as a separator between each elements)

 

How can I check each one is a valid email address ?

 

Here is my code :

 

 

// add user free field to  the list of emails	 
 if (closedRequest.Others_email_addresses__c!= null) { 	

list<string> lEmailOthersAddressesList = closedRequest.Others_email_addresses__c.split(';', 15);

for(String sOthersAddresses : lEmailOthersAddressesList){
lEmailAddressesList.add(sOthersAddresses);
System.debug('valeur de lEmailAddressesList = ' + lEmailAddressesList);
}
}

 Is it possible to test sOthersAddresses to see if it is a valid address email ?

 

Thanks for any help !

Marie

 

  • March 24, 2011
  • Like
  • 0

Hi,

 

I wanted to populate a list incrementing myself the meter :

 

 

public with sharing class CSR_CORE_RequestTriggers_SendSingleEmail {

// Collections
public list<string> lTypesContactList {get;set;}

public void SendEmail(List<Request__c> closedRequestList){
System.debug('## Start class ## CSR_CORE_RequestTriggers_SendSingleEmail - ligne 14 ' + UserInfo.getName());

for (Request__c closedRequest:closedRequestList){

// GET EMAIL ADDRESSES

Boolean resultTest;

//put values of multi-select picklist field into a list
try{
list<string> lTypesContactList = closedRequest.Contact_types_for_Email__c.split(';', 15);

// for every type of contact of the list, find its email address in Contact external
Integer count = 0 ;
for (String sTypesContact : lTypesContactList) {
System.debug('valeur de sTypesContact : ' + sTypesContact);

try{
Contact_external__c acc_Contact_External = [select Name, Email__c from Contact_external__c
where Account__c = :closedRequest.Entity__c
and title__c = :sTypesContact limit 1 ];
// it is an external contact
System.debug('valeur de acc_Contact_External : ' + acc_Contact_External);
if(acc_Contact_External.Name != null){
// contact has an email address
if(acc_Contact_External.email__c != null){
// System.debug('valeur de count = [' + count + ']');
// lEmailAddressesList.add(acc_Contact_External.email__c); *
lEmailAddressesList[count] = (acc_Contact_External.email__c);
count++;
}
}
} catch (System.QueryException e) {
System.debug('passage dans le Catch');
// not found in external contact
resultTest = sTypesContact.contains('lanner');
// is it a planner ?
System.debug('valeur de resultTest - Planner : ' + resultTest);
if(resultTest == true ) {

Request__c acc_Request = [select Id, Entity__r.Supply_planner_contact__r.Email
from Request__c where Id = :closedRequest.Id];
System.debug('valeur de acc_Request : ' + acc_Request);
System.debug('valeur de acc_Request.Entity__r.Supply_planner_contact__r.Email : ' + acc_Request.Entity__r.Supply_planner_contact__r.Email);

if(acc_Request.Entity__r.Supply_planner_contact__r.Email != null){
System.debug('valeur de Planner email : ' + acc_Request.Entity__r.Supply_planner_contact__r.Email);
// lEmailAddressesList.add(acc_Request.Entity__r.Supply_planner_contact__r.Email);
lEmailAddressesList[count] = (acc_Request.Entity__r.Supply_planner_contact__r.Email);
count++;
}
} else {

resultTest = sTypesContact.contains('ield Service');
System.debug('valeur de resultTest - FSM : ' + resultTest);
// is it a field service manager ?
if(resultTest == true ) {

Request__c acc_Request = [select Id, Entity__r.Field_service_manager_contact__r.Email
from Request__c where Id = :closedRequest.Id];
System.debug('valeur de acc_Request : ' + acc_Request);
System.debug('valeur de acc_Request.Entity__r.Field_service_manager_contact__r.Email : ' + acc_Request.Entity__r.Field_service_manager_contact__r.Email);

if(acc_Request.Entity__r.Field_service_manager_contact__r.Email != null){
System.debug('valeur de FSM email : ' + acc_Request.Entity__r.Field_service_manager_contact__r.Email);
// lEmailAddressesList.add(acc_Request.Entity__r.Field_service_manager_contact__r.Email);
lEmailAddressesList[count] = (acc_Request.Entity__r.Field_service_manager_contact__r.Email);
count++;
}
}
}
} // try (1)
} // for lTypesContactList

System.debug('valeur de lEmailAddressesList après boucle lecture : ' + lEmailAddressesList);

(I used first .add method, but I add only the last value)

 

Does anybody can tell me what I am doing wrong ?

Thank you  !

 

Marie

 

 

  • March 24, 2011
  • Like
  • 0

Hi !

 

I need some help...

 

In apex, I want to get email address from a contact linked to the account concerned by the request on which the trigger started :

 

I try to explain better :                                                                                                           Contact(Object)

                                                                                                                                                 Email

                                                                                                                                                 (I want to get this...)

 

                                                                       Account (Object)

                                                                       Field_service_manager_contact__c (lookup to contact)

 

Request__c (Object)                                                                                                           

Entity__c (lookup to Account)                                                                                             

(I am here)                                                                                                                             

 

Is it clear ?

I don't know how to code this in my class.....

 

Thanks a lot to help me !

Marie

 

 

 

 

  • March 23, 2011
  • Like
  • 0

Hi,

Is it possible to get the ID of the Organization Wide Address you want, to be chosen with a test on its display address ?

I would like not to put "hard code" ID.

 

I found some code somewhere and pasted it in mine, but it doesn't work :

 

// create a new single email message object  
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
	
// Assign the addresses for the To, CC and BCC lists to the mail object.  
email.setBccAddresses(lEmailAddressesList);

// Use Organization Wide Address  
for(OrgWideEmailAddress owa : [select id, Address from OrgWideEmailAddress]) {
if(owa.Address.contains('CSR')) email.setOrgWideEmailAddressId(owa.id); } 

// Specify the subject line for your email address.  
email.setSubject('The request has been closed : ' + closedRequest.Name);
	
// Set to True if you want to BCC yourself on the email.  
email.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.  
email.setUseSignature(false);

email.setHtmlBody('This request :<b> ' + closedRequest.Name +' </b>has been closed<br />' +
'Subject : ' + closedRequest.Subject__c +'<br />' +
'Short description : ' + closedRequest.Short_description__c +'<br />' +
'<p>Resolution :<b> ' + closedRequest.Answer__c +' </b></p>' +
'<p>Thank you</p>');

email.setSaveAsActivity(false);
  	
// Send the email you have created.  
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email })

For now, I haven' find any documentation about this.

Does someone have any solution for me ?

Marie

 

  • March 23, 2011
  • Like
  • 0

Hi everybody !

I'm rather inexperienced on Sales Force developments in general, an on Apex particulary...

I want to send emails via a trigger after update.

 

Here is the trigger :

 

trigger CSR_CORE_RequestAfterUpdate on Request__c (after update) {
    //codes executed by spoon
     if(UserInfo.getName()== 'SPOON Consulting' || UserInfo.getName()== 'Stephane Tiger'){
        System.debug('## Start CSR_CORE_RequestAfterUpdate'+ UserInfo.getName()); 
        
        Map<Id, Request__c> mpReqStatus = new Map<Id, Request__c> ();//
        Map<Id, List<Id>> mpReqSLA = new Map<Id, List<Id>> ();
        List<Id> lstReqSLAIds;  
        Set<id> slaIds = new Set<Id>();//old sla ids
        
        List<Request__c> requestList =new List<Request__c>();//list to be used for inserting milestone alerts
        Boolean requestAdded =false;
        
        for(Integer i = 0;i<trigger.new.size();i++){
            if(trigger.new[i].Call_type__c == UTI_Constants.callType_In_Request){           
                
                lstReqSLAIds = new List<Id>();                  
                //assuming whenever a case is closed...alerts are only invalidated not generated. so taking into consideration onlytrigger.old[i].SLAs 
                
                
                if((trigger.new[i].SLA_1__c != trigger.old[i].SLA_1__c ) ||(trigger.new[i].Status__c != trigger.old[i].Status__c) ){//trigger.new[i].Status__c == UTI_Constants.status_Closed_Request
                    System.debug('## adding sla1s for ' + trigger.new[i].Request_Type__c);                  
                    requestList.add(trigger.new[i]);
                    requestAdded=true;
                    if( trigger.old[i].SLA_1__c != null){
                        System.debug('## adding sla1 to invalidate alert if old sla 1 is not null' + trigger.new[i].Request_Type__c); 
                        slaIds.add(trigger.old[i].SLA_1__c);
                        lstReqSLAIds.add(trigger.old[i].SLA_1__c);
                    }
                }       
                    
                System.debug( '## SLA2s differ ');
                if((trigger.new[i].SLA_2__c != trigger.old[i].SLA_2__c)|| (trigger.new[i].Status__c != trigger.old[i].Status__c)){//trigger.new[i].Status__c == UTI_Constants.status_Closed_Request 
                    System.debug('## adding sla2 for ' + trigger.new[i].Request_Type__c); 
                    if( trigger.old[i].SLA_2__c != null){//to invalidate milestone alerts, need to check if old SLA is not null
                        System.debug('## adding sla2 to invalidate alert if old sla 2 is not null' + trigger.new[i].Request_Type__c); 
                        slaIds.add(trigger.old[i].SLA_2__c);
                        lstReqSLAIds.add(trigger.old[i].SLA_2__c);
                    }
                    
                    if(!requestAdded){
                        System.debug( '## Request added to list already');
                        requestList.add(trigger.new[i]);
                    }
                }                           
                    
                if(!lstReqSLAIds.isEmpty()){
                    System.debug('## adding slas to list ');
                    mpReqSLA.put(trigger.old[i].id,lstReqSLAIds);
                    mpReqStatus.put(trigger.old[i].id,trigger.old[i]);
                    System.debug('## added slas to list  ' +mpReqSLA +' reqStatus' +mpReqStatus);
                }
            }       
            
        }
        //invalidates existing alerts...
        if(mpReqSLA.size() > 0 && mpReqStatus.size() > 0)  {
            System.debug('## call the method invalidateMilestoneAlerts accordingly');
            UTI_CORE_AlertTriggers.invalidateMilestoneAlerts(slaIds, mpReqStatus, mpReqSLA);
        }
        
        //inserting alerts
        if(requestList.size() > 0)  {
            System.debug('## call the method InsertMilestoneAlerts accordingly');
            UTI_CORE_AlertTriggers.insertMilestoneAlerts(requestList);
        }
          
        System.debug('## End CSR_CORE_RequestAfterUpdate'+ UserInfo.getName()); 
     }

    //codes executed by MCP
     if(UserInfo.getName()== 'Marie-Christine PIEL'){
     
        List<Request__c> closedRequestList =new List<Request__c>();//list for which send an email
        
        for(Integer i = 0;i<trigger.new.size();i++){
            if(trigger.new[i].Call_type__c == UTI_Constants.callType_In_Request){  
                if ((trigger.new[i].Status__c != trigger.old[i].Status__c) && 
                (trigger.new[i].Status__c =='CORE_Closed')) {
                closedRequestList.add(trigger.new[i]);
                }
               }
            }
        if(closedRequestList.size() > 0)  {
          CSR_CORE_RequestTriggers_SendSingleEmail.SendEmail(closedRequestList);
        }
        }
}

 I'm only concerned with the code inside the test on my profile, at the end.

 

And here is my class :

public with sharing class CSR_CORE_RequestTriggers_SendSingleEmail {

// Objets
public Request__c oRequest {get;set;}
public Contact_external__c oContact_external {get;set;}
public Contact oContact {get;set;}

// Collections
public list<string> lEmailAddressesList {get;set;}
public list<string> lTypesContactList {get;set;}


public void SendEmail(List<Request__c> closedRequestList){
	
	for (Request__c closedRequest:closedRequestList){

// GET EMAIL ADDRESSES
	
	Boolean resultTest;
	
	//put values of multi-select picklist field into a list
		list<string> lTypesContactList = closedRequest.Contact_types_for_Email__c.split(';', 15);
	
	// for every type of contact of the list, find its email address in Contact external
	     Integer count = 0 ;
	     while (lTypesContactList [count] != null) {
		
	     Contact_external__c acc_Contact_External  = [select Email__c from Contact_external__c 
	    	 where Account__c = :closedRequest.Entity__c 
	     and title__c = :lTypesContactList[count] limit 1 ];
	     	// it is an external contact
			 if(acc_Contact_External.email__c != null){
			     lEmailAddressesList[count] = acc_Contact_External.email__c; 
			     count++ ;
			     // not found in external contact
		  		 } //else {
		  		 	//resultTest = lTypesContactList[count].contains('laner');
		  		 	// is it a planer ?
		  		 	//if(resultTest == true ) {
		  		 	//	Contact acc_Contact = [select email from Contact
		  		 	//	where Contact.Id = Account.  
		  		 	//                                                     +
		  		 	                                                                
		  		 	//}
		  		 //}
	     }

	// add email of the contact chosen if there is one 
		 if(closedRequest.Other_contact_for_Email__c!=null){
		 Contact acc_Contact = [select Email from Contact 
		 where Id = :closedRequest.Other_contact_for_Email__c limit 1 ];
		 count++ ;  
		 } 

	// put emails in a STRING field with ';' for separator
	     count = 0 ;
	     String emailAddresses = ' ';
	     while (lEmailAddressesList [count] != null) {
	     emailAddresses = emailAddresses + lEmailAddressesList[count] ; 
	     emailAddresses = emailAddresses + '; ' ;
	     count++ ;
  		 }

	// add user free field to that field 	
		 emailAddresses = emailAddresses + closedRequest.Others_email_addresses__c;
	
// SEND THE EMAIL

	// Reserve email capacity for this transaction 
	Messaging.reserveSingleEmailCapacity(2);
	
	// pour liste des erreurs d'envoi si plantage    
	List<Messaging.SendEmailResult> results = new list<Messaging.SendEmailResult>();
	
	// create a new single email message object  
	Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
	
	// Strings to hold the email addresses to which you are sending the email
	String[] bccAddresses = new String[] {emailAddresses};	
	
	// Assign the addresses for the To, CC and BCC lists to the mail object.  
	email.setBccAddresses(bccAddresses);
	
	// Specify the address used when the recipients reply to the email.   
	email.setReplyTo('support@acme.com');
	
	// Specify the name used as the display name.  
	email.setSenderDisplayName('Salesforce Support???');
	
	// Specify the subject line for your email address.  
	email.setSubject('The request has been closed : ' + closedRequest.Id);
	
	// Set to True if you want to BCC yourself on the email.  
	email.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.  
	email.setUseSignature(false);
		
	// value of setTargetObjectId must be Id of a contact, a lead or a user
	//email.setTargetObjectId()
	
	// value of setWhatId must be Id of an account, asset, campaign, case, .....            
	//email.setWhatId(candidat);
	    
    // The email template ID used for the email : NO : not if BCC used
    // email.setTemplateId('00XD0000001Vdq1');
                        
    
	// Specify the text content of the email.  
	//email.setPlainTextBody('Your Case: ' + case.Id +' has been created');
	
	// mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created<p>'+
    //  ' View case <a href=https://na1.salesforce.com/'+case.Id+'>click here</a>');
	
	email.setHtmlBody('The request:<b> ' + closedRequest.Id +' </b>has been closed<p>'+
	     ' Here is the answer :<b> ' + closedRequest.Answer__c +' </b><p>');

	email.setSaveAsActivity(false);
	
	// Send the email you have created.  
	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
  
	}			 
}

}

 

When I compile the trigger, I get this message :Error: Compile Error: Method does not exist or incorrect signature: CSR_CORE_RequestTriggers_SendSingleEmail.SendEmail(LIST<Request__c>) at line 85 column 11

 

I can't find why..

I need help !!!

Marie


 

 

  • March 18, 2011
  • Like
  • 0

Hi everybody,

I have a master-detail relationship between 2 custom objects (Call_Plan_Line__c and Call_Plan_Line_Result__c). In the header of my page, I display datas from the master object, and particulary the name of the DC Center of the store, which is a lookup field to Account. This field is blank, although I know there is something in it (the Id of the account, I suppose).

 

Here is my code :

<apex:outputfield value="{!Call_Plan_Line__c.Delivery_DC__c}"/>

Here is the result :

 

I have tried this too :

<apex:outputfield value="{!Call_Plan_Line__c.Delivery_DC__r.Name}"/>

Here is the result :

 

Any help will be welcome !

 

 

 

 

 

  • January 14, 2011
  • Like
  • 0

Hi every body !

 

I need some help to finish my test class.

 

Y have a customer object (Int_Call_Plan__c), which has a lookup to object Account, through a customer field.

 

In the map to load the object via the data loader, I have this for the concerned field :

 

       KCODCLI=Call_Plan_Line_POS__r\:External_key__c

 

In my test class, I need to set this field. I have done this, I know it's wrong, but I can't find how to write it. I have tried others combinations (for example with the Id of Account I try to get after insert), without success for now.

 

public with sharing class Test_IntCallPlanResult2 {

static testMethod void testIntCallPlanResult2() {
        
        /*=====================
        ACCOUNT
        =======================*/
        Account testAccount1 = new Account();
        testAccount1.Name = 'TestAccount1';
        testAccount1.External_key__c = 'XXXPOS1';
        
        insert testAccount1;
        Account IdtestAccount1 = [select Id from Account where External_key__c ='XXXPOS1' limit 1];
                
        
        /*========================
        test IntCallPlan
        ==========================*/

        Int_Call_Plan__c intCallPlanNew1 = new Int_Call_Plan__c();
        intCallPlanNew1.Call_Plan_Name__c='TESTCPLR_RC';
        intCallPlanNew1.Call_Plan_Line_Order_Reminder_Top__c='0';
        intCallPlanNew1.Call_Plan_Line_Result_Top__c='0';
        intCallPlanNew1.Call_Plan_Line_POS__c='XXXPOS1';
        intCallPlanNew1.CPLR_Record_Type__c='FRLR_RC';
        
        upsert intCallPlanNew1;
      
  }   
}

 

Thanks for your help, anyone.. !

Marie

 

 

  • November 16, 2010
  • Like
  • 0

Hi

stil on my page block table...

To gain some place, I would like to not display format date (this : (28/10/2010) ) near an input date field...

How to do this, if it's possible ?

 

Here is the code for my VF page :

 

            <apex:pageblocktable value="{!resultList}" var="res"
            rendered="{!AND((Call_Plan_Line__c.Result_type__c=='FRLR_RC'),resultListSize>0)}">
                <apex:column headervalue="{!$Label.CORE_ActionDate}" width="20px">
                    <apex:inputfield value="{!res.Action_Date__c}"/>
                </apex:column>
             </apex:pageblocktable>

Thanks for any help

  • October 28, 2010
  • Like
  • 0

Hi,

I begin on Visual Force and Apex...

 

I have a VF page where I want to save a pageblocktable, and then go back on the previous page. It saves, but stays on the page...

 

Here is my class :

 

public  class CallPlanResultController {
    
    public List<Call_Plan_Line_Result__c> resultList {get;set;}
    ApexPages.StandardController controller;
    public Call_Plan_Line__c callPlanLine {get;set;}
    public Integer resultListSize {
        get{    
            return resultList.size();
        }
    }

    public CallPlanResultController(ApexPages.StandardController inputController){
        controller = inputController;

        callPlanLine = (Call_Plan_Line__c)controller.getRecord();

        resultList = new list<Call_Plan_Line_Result__c>();
        for (Call_Plan_Line_Result__c result:[select id,name,Action_Date__c,Action_Type__c,Info_Date__c,
        Nb_of_days_of_StockOut__c,New_needs__c,Order_received__c,Product_Code__c,Product_Name__c,Stock__c,
        To_Process__c,Variance_ROP_Order__c,Comment__c,Objective_Quantity__c,Order_Quantity__c,
        Result_Quantity__c,DMDUnit__c,Order_Qty_Equiv__c,Max_Min__c,Consistency__c,Back_Order_Top__c,
        Back_Order_Observation__c,Back_Order_Qty__c,New_Product_Code__c,New_Product_Name__c
         from Call_Plan_Line_Result__c where call_plan_line__c = :controller.getId()]){
            resultList.add(result);
        }
    }
    
   
    public void save(){
        PageReference retour = controller.save();
        update resultList;
    }

}

and in my page I only use the save function of the controller :

 

<apex:commandbutton value="{!$Label.CORE_Btn_Save}" action="{!save}"/>

 

Any help will be appreciated....

 

 

 

 

 

 

  • October 27, 2010
  • Like
  • 0

Hi everybody,

 

The users can populate a text area with free email addresses.

I put them in a list (I suppose they have put ";" as a separator between each elements)

 

How can I check each one is a valid email address ?

 

Here is my code :

 

 

// add user free field to  the list of emails	 
 if (closedRequest.Others_email_addresses__c!= null) { 	

list<string> lEmailOthersAddressesList = closedRequest.Others_email_addresses__c.split(';', 15);

for(String sOthersAddresses : lEmailOthersAddressesList){
lEmailAddressesList.add(sOthersAddresses);
System.debug('valeur de lEmailAddressesList = ' + lEmailAddressesList);
}
}

 Is it possible to test sOthersAddresses to see if it is a valid address email ?

 

Thanks for any help !

Marie

 

  • March 24, 2011
  • Like
  • 0

Hi,

 

I wanted to populate a list incrementing myself the meter :

 

 

public with sharing class CSR_CORE_RequestTriggers_SendSingleEmail {

// Collections
public list<string> lTypesContactList {get;set;}

public void SendEmail(List<Request__c> closedRequestList){
System.debug('## Start class ## CSR_CORE_RequestTriggers_SendSingleEmail - ligne 14 ' + UserInfo.getName());

for (Request__c closedRequest:closedRequestList){

// GET EMAIL ADDRESSES

Boolean resultTest;

//put values of multi-select picklist field into a list
try{
list<string> lTypesContactList = closedRequest.Contact_types_for_Email__c.split(';', 15);

// for every type of contact of the list, find its email address in Contact external
Integer count = 0 ;
for (String sTypesContact : lTypesContactList) {
System.debug('valeur de sTypesContact : ' + sTypesContact);

try{
Contact_external__c acc_Contact_External = [select Name, Email__c from Contact_external__c
where Account__c = :closedRequest.Entity__c
and title__c = :sTypesContact limit 1 ];
// it is an external contact
System.debug('valeur de acc_Contact_External : ' + acc_Contact_External);
if(acc_Contact_External.Name != null){
// contact has an email address
if(acc_Contact_External.email__c != null){
// System.debug('valeur de count = [' + count + ']');
// lEmailAddressesList.add(acc_Contact_External.email__c); *
lEmailAddressesList[count] = (acc_Contact_External.email__c);
count++;
}
}
} catch (System.QueryException e) {
System.debug('passage dans le Catch');
// not found in external contact
resultTest = sTypesContact.contains('lanner');
// is it a planner ?
System.debug('valeur de resultTest - Planner : ' + resultTest);
if(resultTest == true ) {

Request__c acc_Request = [select Id, Entity__r.Supply_planner_contact__r.Email
from Request__c where Id = :closedRequest.Id];
System.debug('valeur de acc_Request : ' + acc_Request);
System.debug('valeur de acc_Request.Entity__r.Supply_planner_contact__r.Email : ' + acc_Request.Entity__r.Supply_planner_contact__r.Email);

if(acc_Request.Entity__r.Supply_planner_contact__r.Email != null){
System.debug('valeur de Planner email : ' + acc_Request.Entity__r.Supply_planner_contact__r.Email);
// lEmailAddressesList.add(acc_Request.Entity__r.Supply_planner_contact__r.Email);
lEmailAddressesList[count] = (acc_Request.Entity__r.Supply_planner_contact__r.Email);
count++;
}
} else {

resultTest = sTypesContact.contains('ield Service');
System.debug('valeur de resultTest - FSM : ' + resultTest);
// is it a field service manager ?
if(resultTest == true ) {

Request__c acc_Request = [select Id, Entity__r.Field_service_manager_contact__r.Email
from Request__c where Id = :closedRequest.Id];
System.debug('valeur de acc_Request : ' + acc_Request);
System.debug('valeur de acc_Request.Entity__r.Field_service_manager_contact__r.Email : ' + acc_Request.Entity__r.Field_service_manager_contact__r.Email);

if(acc_Request.Entity__r.Field_service_manager_contact__r.Email != null){
System.debug('valeur de FSM email : ' + acc_Request.Entity__r.Field_service_manager_contact__r.Email);
// lEmailAddressesList.add(acc_Request.Entity__r.Field_service_manager_contact__r.Email);
lEmailAddressesList[count] = (acc_Request.Entity__r.Field_service_manager_contact__r.Email);
count++;
}
}
}
} // try (1)
} // for lTypesContactList

System.debug('valeur de lEmailAddressesList après boucle lecture : ' + lEmailAddressesList);

(I used first .add method, but I add only the last value)

 

Does anybody can tell me what I am doing wrong ?

Thank you  !

 

Marie

 

 

  • March 24, 2011
  • Like
  • 0

Hi !

 

I need some help...

 

In apex, I want to get email address from a contact linked to the account concerned by the request on which the trigger started :

 

I try to explain better :                                                                                                           Contact(Object)

                                                                                                                                                 Email

                                                                                                                                                 (I want to get this...)

 

                                                                       Account (Object)

                                                                       Field_service_manager_contact__c (lookup to contact)

 

Request__c (Object)                                                                                                           

Entity__c (lookup to Account)                                                                                             

(I am here)                                                                                                                             

 

Is it clear ?

I don't know how to code this in my class.....

 

Thanks a lot to help me !

Marie

 

 

 

 

  • March 23, 2011
  • Like
  • 0

Hi,

Is it possible to get the ID of the Organization Wide Address you want, to be chosen with a test on its display address ?

I would like not to put "hard code" ID.

 

I found some code somewhere and pasted it in mine, but it doesn't work :

 

// create a new single email message object  
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
	
// Assign the addresses for the To, CC and BCC lists to the mail object.  
email.setBccAddresses(lEmailAddressesList);

// Use Organization Wide Address  
for(OrgWideEmailAddress owa : [select id, Address from OrgWideEmailAddress]) {
if(owa.Address.contains('CSR')) email.setOrgWideEmailAddressId(owa.id); } 

// Specify the subject line for your email address.  
email.setSubject('The request has been closed : ' + closedRequest.Name);
	
// Set to True if you want to BCC yourself on the email.  
email.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.  
email.setUseSignature(false);

email.setHtmlBody('This request :<b> ' + closedRequest.Name +' </b>has been closed<br />' +
'Subject : ' + closedRequest.Subject__c +'<br />' +
'Short description : ' + closedRequest.Short_description__c +'<br />' +
'<p>Resolution :<b> ' + closedRequest.Answer__c +' </b></p>' +
'<p>Thank you</p>');

email.setSaveAsActivity(false);
  	
// Send the email you have created.  
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email })

For now, I haven' find any documentation about this.

Does someone have any solution for me ?

Marie

 

  • March 23, 2011
  • Like
  • 0

Hi everybody !

I'm rather inexperienced on Sales Force developments in general, an on Apex particulary...

I want to send emails via a trigger after update.

 

Here is the trigger :

 

trigger CSR_CORE_RequestAfterUpdate on Request__c (after update) {
    //codes executed by spoon
     if(UserInfo.getName()== 'SPOON Consulting' || UserInfo.getName()== 'Stephane Tiger'){
        System.debug('## Start CSR_CORE_RequestAfterUpdate'+ UserInfo.getName()); 
        
        Map<Id, Request__c> mpReqStatus = new Map<Id, Request__c> ();//
        Map<Id, List<Id>> mpReqSLA = new Map<Id, List<Id>> ();
        List<Id> lstReqSLAIds;  
        Set<id> slaIds = new Set<Id>();//old sla ids
        
        List<Request__c> requestList =new List<Request__c>();//list to be used for inserting milestone alerts
        Boolean requestAdded =false;
        
        for(Integer i = 0;i<trigger.new.size();i++){
            if(trigger.new[i].Call_type__c == UTI_Constants.callType_In_Request){           
                
                lstReqSLAIds = new List<Id>();                  
                //assuming whenever a case is closed...alerts are only invalidated not generated. so taking into consideration onlytrigger.old[i].SLAs 
                
                
                if((trigger.new[i].SLA_1__c != trigger.old[i].SLA_1__c ) ||(trigger.new[i].Status__c != trigger.old[i].Status__c) ){//trigger.new[i].Status__c == UTI_Constants.status_Closed_Request
                    System.debug('## adding sla1s for ' + trigger.new[i].Request_Type__c);                  
                    requestList.add(trigger.new[i]);
                    requestAdded=true;
                    if( trigger.old[i].SLA_1__c != null){
                        System.debug('## adding sla1 to invalidate alert if old sla 1 is not null' + trigger.new[i].Request_Type__c); 
                        slaIds.add(trigger.old[i].SLA_1__c);
                        lstReqSLAIds.add(trigger.old[i].SLA_1__c);
                    }
                }       
                    
                System.debug( '## SLA2s differ ');
                if((trigger.new[i].SLA_2__c != trigger.old[i].SLA_2__c)|| (trigger.new[i].Status__c != trigger.old[i].Status__c)){//trigger.new[i].Status__c == UTI_Constants.status_Closed_Request 
                    System.debug('## adding sla2 for ' + trigger.new[i].Request_Type__c); 
                    if( trigger.old[i].SLA_2__c != null){//to invalidate milestone alerts, need to check if old SLA is not null
                        System.debug('## adding sla2 to invalidate alert if old sla 2 is not null' + trigger.new[i].Request_Type__c); 
                        slaIds.add(trigger.old[i].SLA_2__c);
                        lstReqSLAIds.add(trigger.old[i].SLA_2__c);
                    }
                    
                    if(!requestAdded){
                        System.debug( '## Request added to list already');
                        requestList.add(trigger.new[i]);
                    }
                }                           
                    
                if(!lstReqSLAIds.isEmpty()){
                    System.debug('## adding slas to list ');
                    mpReqSLA.put(trigger.old[i].id,lstReqSLAIds);
                    mpReqStatus.put(trigger.old[i].id,trigger.old[i]);
                    System.debug('## added slas to list  ' +mpReqSLA +' reqStatus' +mpReqStatus);
                }
            }       
            
        }
        //invalidates existing alerts...
        if(mpReqSLA.size() > 0 && mpReqStatus.size() > 0)  {
            System.debug('## call the method invalidateMilestoneAlerts accordingly');
            UTI_CORE_AlertTriggers.invalidateMilestoneAlerts(slaIds, mpReqStatus, mpReqSLA);
        }
        
        //inserting alerts
        if(requestList.size() > 0)  {
            System.debug('## call the method InsertMilestoneAlerts accordingly');
            UTI_CORE_AlertTriggers.insertMilestoneAlerts(requestList);
        }
          
        System.debug('## End CSR_CORE_RequestAfterUpdate'+ UserInfo.getName()); 
     }

    //codes executed by MCP
     if(UserInfo.getName()== 'Marie-Christine PIEL'){
     
        List<Request__c> closedRequestList =new List<Request__c>();//list for which send an email
        
        for(Integer i = 0;i<trigger.new.size();i++){
            if(trigger.new[i].Call_type__c == UTI_Constants.callType_In_Request){  
                if ((trigger.new[i].Status__c != trigger.old[i].Status__c) && 
                (trigger.new[i].Status__c =='CORE_Closed')) {
                closedRequestList.add(trigger.new[i]);
                }
               }
            }
        if(closedRequestList.size() > 0)  {
          CSR_CORE_RequestTriggers_SendSingleEmail.SendEmail(closedRequestList);
        }
        }
}

 I'm only concerned with the code inside the test on my profile, at the end.

 

And here is my class :

public with sharing class CSR_CORE_RequestTriggers_SendSingleEmail {

// Objets
public Request__c oRequest {get;set;}
public Contact_external__c oContact_external {get;set;}
public Contact oContact {get;set;}

// Collections
public list<string> lEmailAddressesList {get;set;}
public list<string> lTypesContactList {get;set;}


public void SendEmail(List<Request__c> closedRequestList){
	
	for (Request__c closedRequest:closedRequestList){

// GET EMAIL ADDRESSES
	
	Boolean resultTest;
	
	//put values of multi-select picklist field into a list
		list<string> lTypesContactList = closedRequest.Contact_types_for_Email__c.split(';', 15);
	
	// for every type of contact of the list, find its email address in Contact external
	     Integer count = 0 ;
	     while (lTypesContactList [count] != null) {
		
	     Contact_external__c acc_Contact_External  = [select Email__c from Contact_external__c 
	    	 where Account__c = :closedRequest.Entity__c 
	     and title__c = :lTypesContactList[count] limit 1 ];
	     	// it is an external contact
			 if(acc_Contact_External.email__c != null){
			     lEmailAddressesList[count] = acc_Contact_External.email__c; 
			     count++ ;
			     // not found in external contact
		  		 } //else {
		  		 	//resultTest = lTypesContactList[count].contains('laner');
		  		 	// is it a planer ?
		  		 	//if(resultTest == true ) {
		  		 	//	Contact acc_Contact = [select email from Contact
		  		 	//	where Contact.Id = Account.  
		  		 	//                                                     +
		  		 	                                                                
		  		 	//}
		  		 //}
	     }

	// add email of the contact chosen if there is one 
		 if(closedRequest.Other_contact_for_Email__c!=null){
		 Contact acc_Contact = [select Email from Contact 
		 where Id = :closedRequest.Other_contact_for_Email__c limit 1 ];
		 count++ ;  
		 } 

	// put emails in a STRING field with ';' for separator
	     count = 0 ;
	     String emailAddresses = ' ';
	     while (lEmailAddressesList [count] != null) {
	     emailAddresses = emailAddresses + lEmailAddressesList[count] ; 
	     emailAddresses = emailAddresses + '; ' ;
	     count++ ;
  		 }

	// add user free field to that field 	
		 emailAddresses = emailAddresses + closedRequest.Others_email_addresses__c;
	
// SEND THE EMAIL

	// Reserve email capacity for this transaction 
	Messaging.reserveSingleEmailCapacity(2);
	
	// pour liste des erreurs d'envoi si plantage    
	List<Messaging.SendEmailResult> results = new list<Messaging.SendEmailResult>();
	
	// create a new single email message object  
	Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
	
	// Strings to hold the email addresses to which you are sending the email
	String[] bccAddresses = new String[] {emailAddresses};	
	
	// Assign the addresses for the To, CC and BCC lists to the mail object.  
	email.setBccAddresses(bccAddresses);
	
	// Specify the address used when the recipients reply to the email.   
	email.setReplyTo('support@acme.com');
	
	// Specify the name used as the display name.  
	email.setSenderDisplayName('Salesforce Support???');
	
	// Specify the subject line for your email address.  
	email.setSubject('The request has been closed : ' + closedRequest.Id);
	
	// Set to True if you want to BCC yourself on the email.  
	email.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.  
	email.setUseSignature(false);
		
	// value of setTargetObjectId must be Id of a contact, a lead or a user
	//email.setTargetObjectId()
	
	// value of setWhatId must be Id of an account, asset, campaign, case, .....            
	//email.setWhatId(candidat);
	    
    // The email template ID used for the email : NO : not if BCC used
    // email.setTemplateId('00XD0000001Vdq1');
                        
    
	// Specify the text content of the email.  
	//email.setPlainTextBody('Your Case: ' + case.Id +' has been created');
	
	// mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created<p>'+
    //  ' View case <a href=https://na1.salesforce.com/'+case.Id+'>click here</a>');
	
	email.setHtmlBody('The request:<b> ' + closedRequest.Id +' </b>has been closed<p>'+
	     ' Here is the answer :<b> ' + closedRequest.Answer__c +' </b><p>');

	email.setSaveAsActivity(false);
	
	// Send the email you have created.  
	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
  
	}			 
}

}

 

When I compile the trigger, I get this message :Error: Compile Error: Method does not exist or incorrect signature: CSR_CORE_RequestTriggers_SendSingleEmail.SendEmail(LIST<Request__c>) at line 85 column 11

 

I can't find why..

I need help !!!

Marie


 

 

  • March 18, 2011
  • Like
  • 0

Hi everybody,

I have a master-detail relationship between 2 custom objects (Call_Plan_Line__c and Call_Plan_Line_Result__c). In the header of my page, I display datas from the master object, and particulary the name of the DC Center of the store, which is a lookup field to Account. This field is blank, although I know there is something in it (the Id of the account, I suppose).

 

Here is my code :

<apex:outputfield value="{!Call_Plan_Line__c.Delivery_DC__c}"/>

Here is the result :

 

I have tried this too :

<apex:outputfield value="{!Call_Plan_Line__c.Delivery_DC__r.Name}"/>

Here is the result :

 

Any help will be welcome !

 

 

 

 

 

  • January 14, 2011
  • Like
  • 0

Hi every body !

 

I need some help to finish my test class.

 

Y have a customer object (Int_Call_Plan__c), which has a lookup to object Account, through a customer field.

 

In the map to load the object via the data loader, I have this for the concerned field :

 

       KCODCLI=Call_Plan_Line_POS__r\:External_key__c

 

In my test class, I need to set this field. I have done this, I know it's wrong, but I can't find how to write it. I have tried others combinations (for example with the Id of Account I try to get after insert), without success for now.

 

public with sharing class Test_IntCallPlanResult2 {

static testMethod void testIntCallPlanResult2() {
        
        /*=====================
        ACCOUNT
        =======================*/
        Account testAccount1 = new Account();
        testAccount1.Name = 'TestAccount1';
        testAccount1.External_key__c = 'XXXPOS1';
        
        insert testAccount1;
        Account IdtestAccount1 = [select Id from Account where External_key__c ='XXXPOS1' limit 1];
                
        
        /*========================
        test IntCallPlan
        ==========================*/

        Int_Call_Plan__c intCallPlanNew1 = new Int_Call_Plan__c();
        intCallPlanNew1.Call_Plan_Name__c='TESTCPLR_RC';
        intCallPlanNew1.Call_Plan_Line_Order_Reminder_Top__c='0';
        intCallPlanNew1.Call_Plan_Line_Result_Top__c='0';
        intCallPlanNew1.Call_Plan_Line_POS__c='XXXPOS1';
        intCallPlanNew1.CPLR_Record_Type__c='FRLR_RC';
        
        upsert intCallPlanNew1;
      
  }   
}

 

Thanks for your help, anyone.. !

Marie

 

 

  • November 16, 2010
  • Like
  • 0

Hi

stil on my page block table...

To gain some place, I would like to not display format date (this : (28/10/2010) ) near an input date field...

How to do this, if it's possible ?

 

Here is the code for my VF page :

 

            <apex:pageblocktable value="{!resultList}" var="res"
            rendered="{!AND((Call_Plan_Line__c.Result_type__c=='FRLR_RC'),resultListSize>0)}">
                <apex:column headervalue="{!$Label.CORE_ActionDate}" width="20px">
                    <apex:inputfield value="{!res.Action_Date__c}"/>
                </apex:column>
             </apex:pageblocktable>

Thanks for any help

  • October 28, 2010
  • Like
  • 0

Hi,

I begin on Visual Force and Apex...

 

I have a VF page where I want to save a pageblocktable, and then go back on the previous page. It saves, but stays on the page...

 

Here is my class :

 

public  class CallPlanResultController {
    
    public List<Call_Plan_Line_Result__c> resultList {get;set;}
    ApexPages.StandardController controller;
    public Call_Plan_Line__c callPlanLine {get;set;}
    public Integer resultListSize {
        get{    
            return resultList.size();
        }
    }

    public CallPlanResultController(ApexPages.StandardController inputController){
        controller = inputController;

        callPlanLine = (Call_Plan_Line__c)controller.getRecord();

        resultList = new list<Call_Plan_Line_Result__c>();
        for (Call_Plan_Line_Result__c result:[select id,name,Action_Date__c,Action_Type__c,Info_Date__c,
        Nb_of_days_of_StockOut__c,New_needs__c,Order_received__c,Product_Code__c,Product_Name__c,Stock__c,
        To_Process__c,Variance_ROP_Order__c,Comment__c,Objective_Quantity__c,Order_Quantity__c,
        Result_Quantity__c,DMDUnit__c,Order_Qty_Equiv__c,Max_Min__c,Consistency__c,Back_Order_Top__c,
        Back_Order_Observation__c,Back_Order_Qty__c,New_Product_Code__c,New_Product_Name__c
         from Call_Plan_Line_Result__c where call_plan_line__c = :controller.getId()]){
            resultList.add(result);
        }
    }
    
   
    public void save(){
        PageReference retour = controller.save();
        update resultList;
    }

}

and in my page I only use the save function of the controller :

 

<apex:commandbutton value="{!$Label.CORE_Btn_Save}" action="{!save}"/>

 

Any help will be appreciated....

 

 

 

 

 

 

  • October 27, 2010
  • Like
  • 0