• Sudhir Chowdary
  • NEWBIE
  • 55 Points
  • Member since 2014
  • Mr
  • Eternus Solutions


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 14
    Replies
Hi,

I am writing a class to send an email with all attachments related to record.

I have used bits and samples from a few different places and managed to get the attachment side working fine. 
I am having trouble setting the toaddresses. Instead of a fixed address it needs to reference a field called Email_to_send_confirmation_to__c.

I dont know why but I can't figure out how to do it.

Please could someone have a look below and see where I am going wrong. I also believe the code is quite messy as I have cut and pasted bits from all over...
 
public class TrainingConfirmationSend {
    ApexPages.StandardController controller;   
 
 public course_sale__c q
 {get;set;}
    
 String op = ApexPages.currentPage().getParameters().get('id');
 
 public Id oppr   
 {get;set;}       
 
 public TrainingConfirmationSend(ApexPages.StandardController ctrl)   
 {oppr = ctrl.getRecord().Id;}
     
 public void GetCustomFields() {
            course_sale__c address = [SELECT Email_to_send_confirmation_to__c FROM Course_Sale__c WHERE id = :oppr];
  }
 public PageReference emailAtt()
 {
 
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
     string[] toaddress = New String[] {address.Email_to_send_confirmation_to__c};
        mail.settoaddresses(toaddress);
        mail.setReplyTo('test@test.com');
        mail.setSenderDisplayName('test');
        mail.setBccSender(false);
        mail.setUseSignature(false);
        mail.setTemplateId('00XD0000001dOXr');
        mail.saveAsActivity = false;    
        
      //Set email file attachments
        List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        for (Attachment a : [select Id, Name, Body, BodyLength from Attachment where ParentId = :oppr])
        {
     // Add to attachment file list
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
        efa.setFileName(a.Name);
        efa.setBody(a.Body);
        fileAttachments.add(efa);
        }
        mail.setFileAttachments(fileAttachments);
      //Send email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        return null;
}
    
}

Thanks for your help,

Kind regards
Joe
public class objectController1
{

public  string searchTxt {get; set;}

 String queryString;
 
    public void searchrecords() {
      
    
    
   
      
        system.debug('selectedObject ---selectedField--------'+selectedObject+'---'+selectedField ); 
        
        
        queryString = 'SELECT Id, name';
        
        
        if (selectedObject!= null && selectedObject!= '')
         {
            queryString += ' from  '+ selectedObject+'';
        }
        
        
        if ( searchTxt != null && searchTxt!= '')
        
         {
            if (selectedField != null && selectedField != '') {
            
            queryString += ' where ' + selectedField +' = '+searchTxt;
            
            system.debug('queryString -----'+queryString );
            
            }
            
        }
        

       
        system.debug('queryString -----------'+queryString );    
            
        lstQuery= database.query(queryString);
       
        
    }

    public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    

    public String selectedObject {get; set;}
    
    
      public list<sobject >lstQuery{get; set;}
      

    public String selectedField {get; set;}

    Public objectController1()
    {   
        selectedObject = 'account';
    }
    
    

    public List<SelectOption> getObjectNames()
        
    {
        List<SelectOption> objNames = new List<SelectOption>();
        
        List<String> entities = new List<String>(schemaMap.keySet());
        
        entities.sort();
        
        for(String name : entities)
        {
            objNames.add(new SelectOption(name,name));
        }
        return objNames;
     }
     
     

     public List<SelectOption> getObjectFields() 
     {
            Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
            
            Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
            
            Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
            
            List<SelectOption> fieldNames = new List<SelectOption>();
            
            for (String fieldName: fieldMap.keySet()) 
            {  
                fieldNames.add(new SelectOption(fieldName,fieldName));
                
            
            }
            return fieldNames;
      }       
}
-------------------------------------------------------------------------------------------------------------------------------------------


<apex:page controller="objectController1" setup="false" showHeader="false" sidebar="false">

 <apex:form >
  <apex:pageBlock > 

<apex:pageBlockSection columns="4"> 
 <apex:pageBlockSectionItem >
 <apex:outputlabel value="Object Names :"/> 
 <apex:actionRegion >
  <apex:selectList value="{!selectedObject}" size="1">
  <apex:selectOptions value="{!ObjectNames}"/> 
  <apex:actionSupport event="onchange" rerender="myFields"/>
   </apex:selectList>
    </apex:actionRegion> 
    </apex:pageBlockSectionItem>
  
   
    <apex:pageBlockSectionItem >
     <apex:outputlabel value="Field Names :"/>
     <apex:outputPanel id="myFields">
     <apex:actionRegion > 
     <apex:selectList value="{!selectedField}" size="1">
      <apex:selectOptions value="{!ObjectFields}"/> 
      </apex:selectList> 
      </apex:actionRegion> 
      </apex:outputPanel>
       </apex:pageBlockSectionItem> 
       
       <apex:pageBlockSectionItem >
          <input id="a" placeholder="label" style="margin-left:10px;" />
      </apex:pageBlockSectionItem>
      
      <apex:pageBlockSectionItem >
        <apex:commandButton onclick="callSearch();" value="Search" reRender="x" style="margin-left:10px;" />
      </apex:pageBlockSectionItem> 
     
</apex:pageBlockSection> 

 <apex:pageblockTable value="{!lstQuery}" var="eachRecord" id="list">
            <apex:column value="{!eachRecord.id}"/>
            <apex:column value="{!eachRecord['Name']}"/>
            
        
 </apex:pageblockTable>

</apex:pageBlock>

 <apex:actionFunction name="callSearch" action="{!searchRecords}" reRender="list">
        <apex:param name="a" value="" assignTo="{!searchTxt}"/>
       
    </apex:actionFunction>
 </apex:form>
  </apex:page>
Here is my formula:

CASE( Field_name__c, 
"fieldvalue1", IMAGE("/resource/image_1","image1",45,115), 
"fieldvalue2", IMAGE("/resource/image_2", "image2",45,115), 
"" 
)

I have tried adding our community prefex before resource like this, but that doesn't work:

CASE( Field_name__c, 
"fieldvalue1", IMAGE("seasuitebygoby/resource/image_1","image1",45,115), 
"fieldvalue2", IMAGE("/seasuitebygoby/resource/image_2", "image2",45,115), 
"" 
)

I even tried this suggestion, but it didn't work:

CASE( Field_name__c, 
"fieldvalue1", IMAGE(LEFT($Api.Partner_Server_URL_260, FIND( '/services',$Api.Partner_Server_URL_260))+/resource/image_1","image1",45,115), 
"fieldvalue2",IMAGE(LEFT($Api.Partner_Server_URL_260, FIND( '/services',$Api.Partner_Server_URL_260))+/resource/image_2", "image2",45,115), 
"" 
)

Any ideas?
Hi,
i have a process in process builder which changes the field (Status -- > picklist) (Market -- > picklist)

If Status changes to Budget we change Market to Budget
If Market changes to Budget we change Status to Budget. 
and its going recursive how do i stop that 
 
Hi,

I am writing a class to send an email with all attachments related to record.

I have used bits and samples from a few different places and managed to get the attachment side working fine. 
I am having trouble setting the toaddresses. Instead of a fixed address it needs to reference a field called Email_to_send_confirmation_to__c.

I dont know why but I can't figure out how to do it.

Please could someone have a look below and see where I am going wrong. I also believe the code is quite messy as I have cut and pasted bits from all over...
 
public class TrainingConfirmationSend {
    ApexPages.StandardController controller;   
 
 public course_sale__c q
 {get;set;}
    
 String op = ApexPages.currentPage().getParameters().get('id');
 
 public Id oppr   
 {get;set;}       
 
 public TrainingConfirmationSend(ApexPages.StandardController ctrl)   
 {oppr = ctrl.getRecord().Id;}
     
 public void GetCustomFields() {
            course_sale__c address = [SELECT Email_to_send_confirmation_to__c FROM Course_Sale__c WHERE id = :oppr];
  }
 public PageReference emailAtt()
 {
 
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
     string[] toaddress = New String[] {address.Email_to_send_confirmation_to__c};
        mail.settoaddresses(toaddress);
        mail.setReplyTo('test@test.com');
        mail.setSenderDisplayName('test');
        mail.setBccSender(false);
        mail.setUseSignature(false);
        mail.setTemplateId('00XD0000001dOXr');
        mail.saveAsActivity = false;    
        
      //Set email file attachments
        List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        for (Attachment a : [select Id, Name, Body, BodyLength from Attachment where ParentId = :oppr])
        {
     // Add to attachment file list
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
        efa.setFileName(a.Name);
        efa.setBody(a.Body);
        fileAttachments.add(efa);
        }
        mail.setFileAttachments(fileAttachments);
      //Send email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        return null;
}
    
}

Thanks for your help,

Kind regards
Joe
Any anyone give me an idea how to move the trigger code to Apex class. My code is
trigger InsertingBU on Opportunity (after insert,after update) 
{
    Set<Id> accountIds = new Set<Id>();
    for(Opportunity o : Trigger.New)
        accountIds.add(o.AccountId);
        
    List<Business_Unit_Company__c> buCompaniesToBeUpserted = new List<Business_Unit_Company__c>();   

    Map<Id,Business_Unit_Company__c> existingBuCompanies = new Map<Id,Business_unit_Company__c>();
    
    for(Business_Unit_Company__c bu : [Select Business_Unit__c,Company__c,Stage__c from Business_Unit_Company__c where Company__c IN: accountIds])
      existingBuCompanies.put(bu.Business_Unit__c, bu);
      
    for(Opportunity o : Trigger.New) 
    {
      if(o.Opportunity_Business_Unit__c != null && existingBuCompanies.get(o.Opportunity_Business_Unit__c) != null)
      {
        Business_Unit_Company__c relatedBuCompany = existingBuCompanies.get(o.Opportunity_Business_Unit__c);                              
        if(relatedBuCompany.Stage__c != 'Closed Won')
        {
          if(o.StageName == 'Closed Won')
          {
            relatedBuCompany.Stage__c = 'Closed Won';
            buCompaniesToBeUpserted.add(relatedBuCompany);
          }
          else if(relatedBuCompany.Stage__c != 'Closed Lost' && o.StageName == 'Closed Lost')
          {
            relatedBuCompany.Stage__c = 'Closed Lost';
            buCompaniesToBeUpserted.add(relatedBuCompany);
          }
          else if(relatedBuCompany.Stage__c != 'Open')
          {
            relatedBuCompany.Stage__c = 'Open';
            buCompaniesToBeUpserted.add(relatedBuCompany);
          }
        }        
      } 
      else if(o.Opportunity_Business_Unit__c != null)
      {
        Business_Unit_Company__c newBuCompany = new Business_Unit_Company__c();
        newBuCompany.Company__c = o.AccountId;
        newBuCompany.Business_Unit__c = o.Opportunity_Business_Unit__c;
        if(o.StageName.contains('Closed'))
        {
          newBuCompany.stage__c = o.StageName ;
        }
        else
        {
          newBuCompany.stage__c ='Open';
        }
        buCompaniesToBeUpserted.add(newBuCompany);
      }   
    }
    if(!buCompaniesToBeUpserted.IsEmpty())
      upsert buCompaniesToBeUpserted;
}

 

i Have 2 picklist one should have all subjects, second picklist should have fields related to selected objects in picklist 1, now if I select a field in picklist 2 and metion a field valu in an one input filed then records with same field value in  selected object should be displayed
 
public class objectController1
{

public  string searchTxt {get; set;}

 String queryString;
 
    public void searchrecords() {
      
    
    
   
      
        system.debug('selectedObject ---selectedField--------'+selectedObject+'---'+selectedField ); 
        
        
        queryString = 'SELECT Id, name';
        
        
        if (selectedObject!= null && selectedObject!= '')
         {
            queryString += ' from  '+ selectedObject+'';
        }
        
        
        if ( searchTxt != null && searchTxt!= '')
        
         {
            if (selectedField != null && selectedField != '') {
            
            queryString += ' where ' + selectedField +' = '+searchTxt;
            
            system.debug('queryString -----'+queryString );
            
            }
            
        }
        

       
        system.debug('queryString -----------'+queryString );    
            
        lstQuery= database.query(queryString);
       
        
    }

    public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    

    public String selectedObject {get; set;}
    
    
      public list<sobject >lstQuery{get; set;}
      

    public String selectedField {get; set;}

    Public objectController1()
    {   
        selectedObject = 'account';
    }
    
    

    public List<SelectOption> getObjectNames()
        
    {
        List<SelectOption> objNames = new List<SelectOption>();
        
        List<String> entities = new List<String>(schemaMap.keySet());
        
        entities.sort();
        
        for(String name : entities)
        {
            objNames.add(new SelectOption(name,name));
        }
        return objNames;
     }
     
     

     public List<SelectOption> getObjectFields() 
     {
            Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
            
            Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
            
            Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
            
            List<SelectOption> fieldNames = new List<SelectOption>();
            
            for (String fieldName: fieldMap.keySet()) 
            {  
                fieldNames.add(new SelectOption(fieldName,fieldName));
                
            
            }
            return fieldNames;
      }       
}
-------------------------------------------------------------------------------------------------------------------------------------------


<apex:page controller="objectController1" setup="false" showHeader="false" sidebar="false">

 <apex:form >
  <apex:pageBlock > 

<apex:pageBlockSection columns="4"> 
 <apex:pageBlockSectionItem >
 <apex:outputlabel value="Object Names :"/> 
 <apex:actionRegion >
  <apex:selectList value="{!selectedObject}" size="1">
  <apex:selectOptions value="{!ObjectNames}"/> 
  <apex:actionSupport event="onchange" rerender="myFields"/>
   </apex:selectList>
    </apex:actionRegion> 
    </apex:pageBlockSectionItem>
  
   
    <apex:pageBlockSectionItem >
     <apex:outputlabel value="Field Names :"/>
     <apex:outputPanel id="myFields">
     <apex:actionRegion > 
     <apex:selectList value="{!selectedField}" size="1">
      <apex:selectOptions value="{!ObjectFields}"/> 
      </apex:selectList> 
      </apex:actionRegion> 
      </apex:outputPanel>
       </apex:pageBlockSectionItem> 
       
       <apex:pageBlockSectionItem >
          <input id="a" placeholder="label" style="margin-left:10px;" />
      </apex:pageBlockSectionItem>
      
      <apex:pageBlockSectionItem >
        <apex:commandButton onclick="callSearch();" value="Search" reRender="x" style="margin-left:10px;" />
      </apex:pageBlockSectionItem> 
     
</apex:pageBlockSection> 

 <apex:pageblockTable value="{!lstQuery}" var="eachRecord" id="list">
            <apex:column value="{!eachRecord.id}"/>
            <apex:column value="{!eachRecord['Name']}"/>
            
        
 </apex:pageblockTable>

</apex:pageBlock>

 <apex:actionFunction name="callSearch" action="{!searchRecords}" reRender="list">
        <apex:param name="a" value="" assignTo="{!searchTxt}"/>
       
    </apex:actionFunction>
 </apex:form>
  </apex:page>

Hi
I have the following line of code written in my class to refer to the current Page: 
System.currentPageReference().getParameters().get('selectedTemplateId');

Can anyone help me replace this code so as to refer the current page dynamically?