• SMaster
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 41
    Questions
  • 158
    Replies

Hi All,

 

I have a custom object, I need to make the record as read only based on the value of a particular custom picklist field..for a particular profile...

 

For Ex:

 

I have an Object says: Custom_Object__c

Custom Field is: Picklist__c

 

as i save the record with the Picklist__c='Changed' for a particular profile.. my complete record should become read only.. is that can be achieved...?

 

Thanks

Hi All,

 

I have a custom object, I need to make the record as read only based on the value of a particular custom picklist field..for a particular profile...

 

For Ex:

 

I have an Object says: Custom_Object__c

Custom Field is: Picklist__c

 

as i save the record with the Picklist__c='Changed' for a particular profile.. my complete record should become read only.. is that can be achieved...?

 

Thanks

Hi All,

 

I need to update the Multiple Detail Object Records based on the Master Record field update...

 

Master Object: RMG_Employee_Master__c

Master Field: Proposal_Status__c

 

Detail Object: Proposal__c

Detail Field: Status__c

 

Please Suggest..

 

trigger detailstatus1 on RMG_Employee_Master__c (after insert,after update)
{
 List<Proposal__c> ac = new List<Proposal__c>();
 Set<id> Ids = new Set<id>();
     for (RMG_Employee_Master__c o : Trigger.new) {
         Ids.add(o.Id);
        }
      Map<id, Proposal__c> owners = new Map<id, Proposal__c>([Select id,Status__c from Proposal__c Where Id in :Ids]); 

for (RMG_Employee_Master__c o : Trigger.new)
     {
        if(o.Proposal_Status__c != 'Closed')
             {
                 //Instantiate a new account and set it to the current opportunity parent. 
                 Proposal__c pc = owners.get(o.Id);
                 pc.Status__c = 'Closed';
                 ac.add(pc);
             }   
        
     }
     update ac;
     }

 

Hi,

 

I want to rerender the apex page block, what is the way of doing that...

Hi All,

 

The scenario is something like:

 

I am trying to create an apex class, in which i have created a method to send an email with attachment with the selected files only.... for this i am also creating the visualforce page using inputcheckbox.....

 

the apex class is something like:

 

But i am getting an error  "Error: Compile Error: Loop variable must be an SObject or list of Attachment"

 

public class Checkbox_Class 

{

 

        public Id oppr     {    get;set;    }         

        public Checkbox_Class(ApexPages.StandardController ctrl)    

        {       

        oppr = ctrl.getRecord().Id;         

        }

       

       

        List<Attachmentwrapper> AttachmentList = new List<Attachmentwrapper>();

        List<Attachment> selectedAttachments = new List<Attachment>();

       

        public List<Attachmentwrapper> getAttachments()

        {

        for (Attachment a : [select Id, Name, Body, BodyLength from Attachment where ParentId = :oppr])

        {      

            AttachmentList.add(new Attachmentwrapper(a));

            return AttachmentList;

                               

        }

        }

         

        public PageReference getSelected()

        {

           

         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

         String[] toAddresses = new String[]{'ashish.garg@headstrong.com'};

         mail.setToAddresses(toAddresses);

         mail.setReplyTo('ashish.garg@headstrong.com');

         mail.setSenderDisplayName('CRM Support');

         mail.setBccSender(false);

         mail.setUseSignature(false);

         mail.setTargetObjectId('005Q0000000FR7f');

         mail.setTemplateId('00XQ0000000QULj');

         mail.saveAsActivity = false;

                          

         //selectedAttachments.clear();

         for(Attachmentwrapper accwrapper : AttachmentList)

         {

         if(accwrapper.selected == true)

         {

         selectedAttachments.add(accwrapper.acc);

         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

         }

         else

         {

         return null;

         }

         }       

        public List<Attachment> GetSelectedAttachments()

        {

            if(selectedAttachments.size()>0)

            return selectedAttachments;

            else

            return null;

        }    

       

        public class Attachmentwrapper

        {

            public Attachment acc{get; set;}

            public Boolean selected {get; set;}

            public Attachmentwrapper(Attachment a)

            {

                acc = a;

               selected = false;

            }

        }

    }

 

 

Hi,

 

I have created a visualforce page where i am displaying all the Notes and Attachments.

 

With every record i have also used an Inputcheckbox.. i just want to determine the record id of the selected record on the checkbox click....

 

Hi,

 

Happy New Year to you all..   :)

 

I want to select an attachment in visualforce page and sent an email with that selected attachment.. all the attachments are getting displayed on the visualforce page from the Notes and Attachment related list..

 

Now while clicking the "Send" button all the attachments are going out.. but i need to send only the selected attachments.. please suggest what am i missing......

 

 

 

 

I have the following Apex Class:

 

public class testmail
{
 ApexPages.StandardController controller;   
 
 public opportunity_proposals__c q
 {
 get;set;
 }
    
 String op = ApexPages.currentPage().getParameters().get('id');
 
 public Id oppr   
 {    get;set;    }       
 
 public testmail(ApexPages.StandardController ctrl)   
 {      
 oppr = ctrl.getRecord().Id;        
 }
 
 public PageReference emailAtt()
 {
 
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[]{'SMaster@gmail.com'};
        mail.setToAddresses(toAddresses);
        mail.setReplyTo('SMaster@gmail.com');
        mail.setSenderDisplayName('CRM Support');
        mail.setBccSender(false);
        mail.setUseSignature(false);
        mail.setTargetObjectId('005Q0000000FR7f');
        mail.setTemplateId('00XQ0000000QULj');
        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;
}
}

 

 

and the following Visualforce page:

 

<apex:page standardController="opportunity_proposals__c" extensions="testmail">
  <apex:form >
   <apex:pageBlock title="Attachments">
   <apex:pageBlockButtons >
            <apex:commandButton value="Send" action="{!emailAtt}"/>
        </apex:pageBlockButtons>


     <apex:pageBlockTable value="{!opportunity_proposals__c.Attachments}" var="Att">
     <apex:column headerValue="Select">
            <apex:inputCheckbox value="{!opportunity_proposals__c.for_sendemailwithattachment__c}"/>
        </apex:column>
       <apex:column value="{!Att.createddate}"/>
       <apex:column value="{!Att.name}"/>
       <apex:column value="{!Att.description}"/>
     </apex:pageBlockTable>
     
      </apex:pageBlock>

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

Hi,

 

I want to send an email with attachment, but i should be able to select the file to email from all attachments.

Hi All,

 

I want to send an email with an Attachment from Notes and Attachment related list.

 

i.e. i have few attachments inside Notes and Attachment related list of a custom Object.. and on a button click i need to send an email with attachment

 

please let me kow how can i do that...

 

 

Thanks

Hi All,

 

I want to send an email with the selected Attachment from Notes and Attachment related list....

 

i.e. i have some file inside Notes and Attachment related list.. and i want to select one file out of them.. and want to email that with some template.. please let me kow how can i do that...

 

 

Thanks

Hi,

 

I have multiple uploaded files inside the related list "Notes and Attachment" for the custom object.

 

I need to send an email to a particluar user with one selected Attachment...

 

Now, i am not able to understand how can i select a particular attachment and sent it as an email???

 

 

Hi All,

 

I want to create a visualforece page to upload and display the attachment using the visualforce page...

 

I am able to upload an attachment using the visualforce page... and get it displayed inside Notes and Attachment section.. but i want them to display inside another visualforce page...

 

pleae let me know how can that be achieved??

 

Thanks

 

Hi,

 

I have created a visualforce page to upload an attachment for a custom object. Now I simply want to create a new field "Type of Attachment" (Drop Down Field) with that attachment .. just to make my user understand that what kind of attachment it is.... and that Field ofcourse should get visible inside Notes and Attachment related list......

 

Can it be done....

Hi,

 

I want to create a new record in the related list of the Opportunity, using the visualforce button on the Opportunity Page layout.

 

I have an Proposal object as a related list in an opportunity. Whenever a user click a button on the oportunity page layout a new record inside Proposal should get created.... how can i achieve that??

Hi All,

 

I have a Javascript code to send email to the selected records... Now i simply want to to display all those records with their Employee code for which an Email has been sent sucessfully...Pls Help... below is my JS code:

 

 

{!requireScript("/soap/ajax/20.0/connection.js")}
{!requireScript("/soap/ajax/20.0/apex.js")}

 
var recordsSelected = {!GETRECORDIDS( $ObjectType.RMG_Employee_Master__c)};

 

if (recordsSelected.length < 1)
{
  alert('Please select atleast one recrod');
}
else if(confirm('Are you sure to send email to the selected records?'))
{
        for (var j=0; j< recordsSelected.length; j++)
{

 


               var result = sforce.connection.query('select Email_Address__c, EmpCode__c,Name,Send_Email__c  from RMG_Employee_Master__c    where id = '+"'" +recordsSelected[j] + "'");

              var employee = new sforce.SObject("RMG_Employee_Master__c");
              employee.Id = recordsSelected[j];
              employee.Send_Email__c = 'True';
              result = sforce.connection.update([employee]);

              employee.Send_Email__c = 'False';
              result = sforce.connection.update([employee]);
 

// i have tried using this code to achieve the same.. but its giving me undefined........
var myarray=new Array();
myarray[j]=employee.EmpCode__c;
alert(myarray[j]);
                

              
}

Hi All,

 

I have a Javascript code to send email to the selected records... Now i simply want to to display all those records with their Employee code for which an Email has been sent sucessfully...Pls Help... below is my JS code:

 

 

{!requireScript("/soap/ajax/20.0/connection.js")}
{!requireScript("/soap/ajax/20.0/apex.js")}

 
var recordsSelected = {!GETRECORDIDS( $ObjectType.RMG_Employee_Master__c)};

 

if (recordsSelected.length < 1)
{
  alert('Please select atleast one recrod');
}
else if(confirm('Are you sure to send email to the selected records?'))
{
        for (var j=0; j< recordsSelected.length; j++)
{

 


               var result = sforce.connection.query('select Email_Address__c, EmpCode__c,Name,Send_Email__c  from RMG_Employee_Master__c    where id = '+"'" +recordsSelected[j] + "'");

              var employee = new sforce.SObject("RMG_Employee_Master__c");
              employee.Id = recordsSelected[j];
              employee.Send_Email__c = 'True';
              result = sforce.connection.update([employee]);

              employee.Send_Email__c = 'False';
              result = sforce.connection.update([employee]);
 

// i have tried using this code to achieve the same.. but its giving me undefined........
var myarray=new Array();
myarray[j]=employee.EmpCode__c;
alert(myarray[j]);
                

              
}

Hi All,

 

Inside an Opportunity i have a custom object "opportunity_proposals__c", as i click on the 'New Opportunity Proposal' button in the related list, a new page of Opportunity Proposal gets opened to create a new record.... i want the 'Opportunity Proposal name' field should gets prepopulated with an Opportunity name....

 

i have written a trigger for this...

 

trigger ProposalName on opportunity_proposals__c (before insert)
{

for(opportunity_proposals__c a:Trigger.new)       
{
String Prop = 'Proposal';
a.Name = a.Opportunity__c + Prop ;
}


}

 

I need to prepopulate the Name field with the Opportunity Name.. while creating the new record....

 

i hope i have explained the requirement.. pls let me know if anything else is required....

 

Thanks

Hi,

 

I need to create a new record in the related list.. but that record should get created only after i attached a file to it...

 

In order to upload the file.. i have created a visualforce page...

 

 

Hi,

 

I need to create a new record in the related list.. but that record should get created only after i attached a file to it...

 

i mean... in order to create the record in the related list first i'll upload the file.. and with the uploaded file name will become the record name... and the new record will be created...

 

if i am not able to explain..well..  please let me know...

Hi All,

 

I have a custom object, I need to make the record as read only based on the value of a particular custom picklist field..for a particular profile...

 

For Ex:

 

I have an Object says: Custom_Object__c

Custom Field is: Picklist__c

 

as i save the record with the Picklist__c='Changed' for a particular profile.. my complete record should become read only.. is that can be achieved...?

 

Thanks

Hi,

 

I need to constantly update the master field based on the detail field value i.e. a picklist field with multiple values.

 

Master Object > RMG_Employee_Master__c

Master Object Field > Proposal_Status__c

 

Child Object > Proposal__c

Child Object Field > Status__c

 

 

I am able to update the master field based on the detail field value. But how can  loop through the multiple detail records to set the value of one master field:

 

trigger proposalstatus on Proposal__c (after insert,after update)
{

   List<RMG_Employee_Master__c> opps = new List<RMG_Employee_Master__c>();
   List<ID> masterIds = new List<ID>();
   Map<ID, String> childDetailMap = new Map<ID, String>();
  
   for(Proposal__c c: Trigger.new)
    {
      masterIds.add(c.RMG_Employee_Code__c);
      childDetailMap.put(c.RMG_Employee_Code__c, (c.Status__c));
    }
    opps = [select id, Proposal_Status__c from RMG_Employee_Master__c where id in :masterIds];
 
   for(RMG_Employee_Master__c rem: opps)
    {
      rem.Proposal_Status__c = childDetailMap.get(rem.id);
    }
    if(opps.size() > 0)
    {
     Update opps;
     }
}

  • January 27, 2011
  • Like
  • 0

Hi,

 

I want to rerender the apex page block, what is the way of doing that...

This is my code, I am sending email to Installers, I need a test code for this. I wonder if anyone can help?

 

Thanks in advance.

trigger handleServiceEmail on Case (after update) {

Set<Id> caseIds = new Set<Id>();
List<Case> cl = [SELECT id, Service__r.Installer__c, Case_Type__c FROM Case WHERE id IN: trigger.newMap.keyset()];
Id[] targetCaseIds = new Id[] {};

List<Messaging.SingleEmailMessage> email = new List<Messaging.SingleEmailMessage>();
  
  for(Case c : cl){
    if(c.Case_Type__c == 'Urgent') {
      caseIds.add(c.Service__r.Installer__c);
      targetCaseIds.add(c.id);
      
      OrgWideEmailAddress owa = [select id from OrgWideEmailAddress]; 
      EmailTemplate template = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'Urgent Email' LIMIT 1];
    
      for(Contact contact :[SELECT id,Email FROM Contact WHERE AccountID IN: caseIds]){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setOrgWideEmailAddressId(owa.Id);
        mail.setTargetObjectId(contact.Id);
        mail.setTemplateID(template.ID);
        mail.setSaveAsActivity(false);
        mail.setWhatId(c.ID);
        
        email.add(mail);
      } 
   
    }
  }  
  Messaging.sendEmail(email);
  
}

 

 

  • January 04, 2011
  • Like
  • 0

Hi,

 

I have created a visualforce page where i am displaying all the Notes and Attachments.

 

With every record i have also used an Inputcheckbox.. i just want to determine the record id of the selected record on the checkbox click....

 

Hi,

 

Happy New Year to you all..   :)

 

I want to select an attachment in visualforce page and sent an email with that selected attachment.. all the attachments are getting displayed on the visualforce page from the Notes and Attachment related list..

 

Now while clicking the "Send" button all the attachments are going out.. but i need to send only the selected attachments.. please suggest what am i missing......

 

 

 

 

I have the following Apex Class:

 

public class testmail
{
 ApexPages.StandardController controller;   
 
 public opportunity_proposals__c q
 {
 get;set;
 }
    
 String op = ApexPages.currentPage().getParameters().get('id');
 
 public Id oppr   
 {    get;set;    }       
 
 public testmail(ApexPages.StandardController ctrl)   
 {      
 oppr = ctrl.getRecord().Id;        
 }
 
 public PageReference emailAtt()
 {
 
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[]{'SMaster@gmail.com'};
        mail.setToAddresses(toAddresses);
        mail.setReplyTo('SMaster@gmail.com');
        mail.setSenderDisplayName('CRM Support');
        mail.setBccSender(false);
        mail.setUseSignature(false);
        mail.setTargetObjectId('005Q0000000FR7f');
        mail.setTemplateId('00XQ0000000QULj');
        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;
}
}

 

 

and the following Visualforce page:

 

<apex:page standardController="opportunity_proposals__c" extensions="testmail">
  <apex:form >
   <apex:pageBlock title="Attachments">
   <apex:pageBlockButtons >
            <apex:commandButton value="Send" action="{!emailAtt}"/>
        </apex:pageBlockButtons>


     <apex:pageBlockTable value="{!opportunity_proposals__c.Attachments}" var="Att">
     <apex:column headerValue="Select">
            <apex:inputCheckbox value="{!opportunity_proposals__c.for_sendemailwithattachment__c}"/>
        </apex:column>
       <apex:column value="{!Att.createddate}"/>
       <apex:column value="{!Att.name}"/>
       <apex:column value="{!Att.description}"/>
     </apex:pageBlockTable>
     
      </apex:pageBlock>

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

Hi All,

 

I want to send an email with the selected Attachment from Notes and Attachment related list....

 

i.e. i have some file inside Notes and Attachment related list.. and i want to select one file out of them.. and want to email that with some template.. please let me kow how can i do that...

 

 

Thanks

 Hi Folks,

 

How to map a ld with the list and display the same in the VF page??

 

For Eg:

Map<id,List<object__c>> obj=new Map<id,List<object__c>>();

 

Now, I want the fields in the object__c to be displayed in the VF page and want to update the same field via VF page.

 

Any examples will be helpful..

 

Thanks

Raj

Hi There,

 

I would like to attach and attachment to an email. Looking through the documentation I can see the methods for setDocumentAttachments and setFileAttachments  but neither of these appear to allow attaching an 'Attachment' object.

 

I have an opportunity with a file attached in 'Notes & Attachments' but not sure how to add this to an email.

 

TIA

 

 

To cut to the chase I'm trying to create a trigger that will send an email alert when the stage is changed. Seems easy enough, but the catch is that a different attachment has to be send with each email alert. The attachment would correspond to the account and would be found in Notes & Attachments. I have no prior experience writing apex and was wondering if anyone could help. 


Thanks in advance

 

 

I'm attempting to send an email with a large attachment (or attachments) using SingleEmailMessage. A EmailFileAttachment[] List is created to contain the attachments which are within the 10mb limit for all attachments but when the attachment(s) exceed 2mb in size the Apex heap size limit is exceeded. There's obviously something I'm missing here. With this in mind, how are files, of up to 10mb collectively, attached to an email using the setFileAttachments method without exceeding the Apex heap size limit?

 

There's no problem uploading a file of up to 5mb in size to the Attachments object for example, that doesn't cause a Apex heap size error. So I assume blobs don't count against heap size. But that doesn't seem to be true for a collection of objects that contain a blob. Surely the blob is only held by reference?

 

The code below doesn't enforce the 10mb attachments limit but assume it's not exceeded. When fileAttachments exceeds 2mb the 'System.Exception: Apex heap size too large' occurs.

 

// Create EmailMessage and assign parameters
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(toAddresses);
mail.setCcAddresses(ccAddresses);
mail.setReplyTo('support@acme.com');
mail.setSenderDisplayName('Support');
mail.setSubject('New Case Created : ' + case.Id);
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setPlainTextBody('Your Case: ' + case.Id +' has been created');
mail.setTargetObjectId(case.contactId);
mail.setWhatId(case.Id);

// Set email file attachments
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for (Attachment a : [select Name, Body, BodyLength
from Attachment
where ParentId = :case.Id])
{
// 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 })

Message Edited by nelloC on 02-16-2010 03:35 AM
  • February 10, 2010
  • Like
  • 0

These notes assume you know how to work with the Messaging.SingleEmailMessage class. If anybody has a better way of doing this, let me know.

While building an APEX class that emails Case Owner, boss wanted to add the last few attachments of a Case to the email being generated.

 

1.) Instantiate SingleEmailMessage object:

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

 

2.) Query Attachments of whatever object type you want attachments on. I return the results to an Attachment[] array. Note - this is a good place to limit the number of attachments you want to return.

Attachment[] queryAttachment = [select Body, Id, Name, ContentType from Attachment where Parentid=:someCaseObject.Id order by CreatedDate DESC];

 

3.) Create an EmailFileAttachment[] array to hold each file, loop through the query and populate the array.

        Messaging.EmailFileAttachment[] allAttachments = new
        for(integer i=0;i<queryAttachment.size();i++)
        {
            Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
            fileAttachment.setBody(queryAttachment[i].Body);
            fileAttachment.setFileName(queryAttachment[i].Name);
            allAttachments[i] =  fileAttachment;
        }
Messaging.EmailFileAttachment[queryAttachment.size()];
 

4.) Now that our allAttachments array is populated, pass allAttachments to your mail object's setFileAttachments method:

        mail.setFileAttachments(allAttachments);
 

5.) Do the rest of your mail.methods to generate and send your email.

 

http://blog.psychopup.net/post/2009/10/15/Adding-Attachments-to-emails-via-APEX-in-Salesforce.aspx