• sridhar v 7
  • NEWBIE
  • 85 Points
  • Member since 2016

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 11
    Replies
public class sendofferlettercontroller {

   public sendofferlettercontroller() { }

    public String toEmail {get;set;}
        public String ccEmail {get;set;}
    Public ID ParentID{get;set;}

    public String subject {get;set;}
    public String body {get;set;}
        
    private final contact MyLead;
       public static contact co1{get;set;}

    
    public sendofferlettercontroller(ApexPages.StandardController controller)
    {
        this.MyLead=(Contact)controller.getRecord();
             ParentID = apexpages.currentpage().getparameters().get('id');

    } 
   
             
    public PageReference sendEmail() {
        
           co1 = [select id ,name, Email  from contact where id =: ApexPages.currentPage().getParameters().get('id')];

        //create a mail object to send email 
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        String[] toaddress = toEmail.Split(','); //using comma separator between emails
        //String[] toaddress = toEmail.Split('[,;]'); //use can use Regex to mix with comma & semi colon separator

        //email properties
        String[] ccaddress = ccEmail.Split(',');
        mail.setToAddresses(toaddress);
        mail.setSubject(subject);
                           mail.setccAddresses(ccaddress);  

        mail.setUseSignature(true);
        mail.setPlainTextBody(body); 
                
        // send the email'
                             PageReference pdf =  Page.offerletterpage;
                                                  pdf.getParameters().put('id',(String)co1.id);
                     pdf.setRedirect(true);
                                          blob b;

                     try{
                     b = pdf.getContent();
                     }catch (VisualforceException e){
                     b = Blob.valueOf('Some Text');
                     }
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
                     efa.setFileName('ImpactGuru Offer Letter PDf'+'.pdf');
                     efa.setBody(b);
                     mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
                       try
                    {
                 //   Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                    }
                    catch(System.EmailException ex)
                    {
                    }
                    Datetime myDatetime = Datetime.now();
                    String myDatetimeStr;  
                    Attachment a = new Attachment();
                    a.parentid = co1.id;
                    a.body = b;
                    a.name = (co1.Name+' - '+myDatetime.format('d - MMMM, yyyy'));
                    insert a;

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

     }   
   

}

Thanks in advance
  • January 10, 2019
  • Like
  • 0
TRIGGER:

trigger ContactTrigger on Contact (before insert,before update) {
    if(Trigger.isBefore){
        if(Trigger.isInsert){
         ContactTriggerHandler.onBeforeInsert(Trigger.New);
        }
        if(Trigger.isUpdate){
            ContactTriggerHandler.onBeforeUpdate(Trigger.New);
        }
    }
}

CLASS:

public class ContactTriggerHandler {
    
    public static void onBeforeInsert(List<Contact> contactList){
        setPrimaryContact(contactList);
    }
    
    public static void onBeforeUpdate(List<Contact> contactList){
        updatePrimaryContact(contactList);
    }
    
    /* Instruction Number 8
     * When an existing Non-Primary Contact is updated to become a Primary Contact,  the system should check if the Account related to the updated Contact does not yet have a Primary Contact. If the Account already has a Primary Contact, a message should be shown to the user stating: "Invalid Primary Contact. This Account has an existing Primary Contact."
     * 
    */
   
    public static void updatePrimaryContact(List<Contact> contactList){
        List<Account> accountList = [SELECT Id, (SELECT Id, Primary_Contact__c FROM Contacts) FROM Account];
        Map<Id, Account> accountMap = new Map<Id, Account>();
        
        for(Account acct : accountList)    {
            accountMap.put(acct.Id, acct);
        }
        
        for(Contact contactNonPrime : contactList){
            for(Contact cc : accountMap.get(contactNonPrime.AccountId).Contacts){
                if(contactNonPrime.Primary_Contact__c == TRUE){
                    if(cc.Primary_Contact__c == TRUE && contactNonPrime.Id != cc.Id){
                        contactNonPrime.Primary_Contact__c.addError('Invalid Primary Contact. This Account has an existing Primary Contact.');
                    }
                }
            }
        }
    }
    
  /* Instruction Number 6
   * When a new Non-Primary Contact is created and the Account related to the new Contact does not have any existing Contacts, the new Contact should automatically become the Account's Primary Contact.
   */
        
    public static void setPrimaryContact(List<Contact> contactList){
        List<Account> accountList = [SELECT Id, (SELECT Id, Primary_Contact__c FROM Contacts)
                                     FROM Account];
        Map<Id, Account> accountMap = new Map<Id, Account>();
        
        for(Account acct : accountList)    {
            accountMap.put(acct.Id, acct);
        }
            
            for(Contact contactPrime : contactList){
                if(contactPrime.Primary_Contact__c != true && contactPrime.AccountId != NULL){
                   
                    if(accountMap.get(contactPrime.AccountId).Contacts.size() <1){
                        contactPrime.Primary_Contact__c = TRUE;
                    }
                }else if(contactPrime.Primary_Contact__c == TRUE && contactPrime.AccountId != NULL) {
                    for(Contact cc : accountMap.get(contactPrime.AccountId).Contacts){
                        if(cc.Primary_contact__c == TRUE){
                              contactPrime.Primary_Contact__c.addError('Invalid Primary Contact. This Account has an existing Primary Contact.');
                        }
                  }
             } 
        }
    }
}
  • January 10, 2019
  • Like
  • 0
Hey guys,

I'd like to have the following formula (which pulls in a heatmap of NY from the Documents Tab)
<apex:page standardcontroller="Contact" showHeader="false">
     <apex:image id="NY" value="{!'/servlet/servlet.FileDownload?file=0F01k00000002Wn'}" width="1920" height="940"/>
</apex:page>

use an if statement/merge field to verify that the record's state is actually NY. For example, I'd like in Excel terms to do if(contact.state__c = "NY", <apex:image id="NYJan19" value="{!'/servlet/servlet.FileDownload?file=0F01k00000002Wn'}" width="1920" height="940"/> ,"")

The reason being that I plan on having an image for every state so I need to merge in the record's state field so I can properly match them. Otherwise this would require 50 visualforce pages.

Thanks!!
Hi,
Could you please help me on the below.

We have a custom object for which the standard View is overriden with a Visualforce page for Classic and a lightning component for Lightning Override of the View. Now this works fine in the Lightning mode and classic mode for Internal users accordingly. But when the same record detail page is opened in a Partner Community, it  displays the Detail page of salesforce and not the overriden page or component.

We see a post on Stackexchange where one of them have mentioned that this is a limitation on Partner Community. Link below.
https://salesforce.stackexchange.com/questions/199370/view-override-does-not-work-in-partner-community

I wanted to know if there is any salesforce doc which mentions this.


Thanks,
Hi All,

Coud you please help me the below.

I have a inline visual force page that is added to Account Page Layout. On this Page, i have links to different Visualforce Pages. Now, the issue is whenever i click on any of these links it opens up the page but with Header and Sidebar hidden. I see that this is due to an additional parameter that is getting added in the URL (inline=1). if i remove this parameter and refresh the page, then it loads fine with header and sidebar.

is there a way that i could get around this without having to use javascript and reload the page by removing inline parameter in javascript.

Thanks,
 
Hi every one,

actually i wrote visual force page 
<apex:page standardController="account" contentType="Application/vnd.ms-excel">
    <apex:form>
    <apex:pageblock title="account">
        <apex:pageBlockTable value="{!account.contacts}" var="contacts">
            <apex:column value="{!contact.name}"/>
            <apex:column value="{!contact.phone}"/>
      </apex:pageBlockTable>
        </apex:pageblock>
   </apex:form>
</apex:page>

actually my intention is i want to know how to use contentType in vf page and how it display .
i wrote above program previed this program i am ot geeting error
but it s not showing any out put.

please let me know if any one knows about it 

Thank you
surender reddy

 
public class sendofferlettercontroller {

   public sendofferlettercontroller() { }

    public String toEmail {get;set;}
        public String ccEmail {get;set;}
    Public ID ParentID{get;set;}

    public String subject {get;set;}
    public String body {get;set;}
        
    private final contact MyLead;
       public static contact co1{get;set;}

    
    public sendofferlettercontroller(ApexPages.StandardController controller)
    {
        this.MyLead=(Contact)controller.getRecord();
             ParentID = apexpages.currentpage().getparameters().get('id');

    } 
   
             
    public PageReference sendEmail() {
        
           co1 = [select id ,name, Email  from contact where id =: ApexPages.currentPage().getParameters().get('id')];

        //create a mail object to send email 
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        String[] toaddress = toEmail.Split(','); //using comma separator between emails
        //String[] toaddress = toEmail.Split('[,;]'); //use can use Regex to mix with comma & semi colon separator

        //email properties
        String[] ccaddress = ccEmail.Split(',');
        mail.setToAddresses(toaddress);
        mail.setSubject(subject);
                           mail.setccAddresses(ccaddress);  

        mail.setUseSignature(true);
        mail.setPlainTextBody(body); 
                
        // send the email'
                             PageReference pdf =  Page.offerletterpage;
                                                  pdf.getParameters().put('id',(String)co1.id);
                     pdf.setRedirect(true);
                                          blob b;

                     try{
                     b = pdf.getContent();
                     }catch (VisualforceException e){
                     b = Blob.valueOf('Some Text');
                     }
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
                     efa.setFileName('ImpactGuru Offer Letter PDf'+'.pdf');
                     efa.setBody(b);
                     mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
                       try
                    {
                 //   Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                    }
                    catch(System.EmailException ex)
                    {
                    }
                    Datetime myDatetime = Datetime.now();
                    String myDatetimeStr;  
                    Attachment a = new Attachment();
                    a.parentid = co1.id;
                    a.body = b;
                    a.name = (co1.Name+' - '+myDatetime.format('d - MMMM, yyyy'));
                    insert a;

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

     }   
   

}

Thanks in advance
  • January 10, 2019
  • Like
  • 0
TRIGGER:

trigger ContactTrigger on Contact (before insert,before update) {
    if(Trigger.isBefore){
        if(Trigger.isInsert){
         ContactTriggerHandler.onBeforeInsert(Trigger.New);
        }
        if(Trigger.isUpdate){
            ContactTriggerHandler.onBeforeUpdate(Trigger.New);
        }
    }
}

CLASS:

public class ContactTriggerHandler {
    
    public static void onBeforeInsert(List<Contact> contactList){
        setPrimaryContact(contactList);
    }
    
    public static void onBeforeUpdate(List<Contact> contactList){
        updatePrimaryContact(contactList);
    }
    
    /* Instruction Number 8
     * When an existing Non-Primary Contact is updated to become a Primary Contact,  the system should check if the Account related to the updated Contact does not yet have a Primary Contact. If the Account already has a Primary Contact, a message should be shown to the user stating: "Invalid Primary Contact. This Account has an existing Primary Contact."
     * 
    */
   
    public static void updatePrimaryContact(List<Contact> contactList){
        List<Account> accountList = [SELECT Id, (SELECT Id, Primary_Contact__c FROM Contacts) FROM Account];
        Map<Id, Account> accountMap = new Map<Id, Account>();
        
        for(Account acct : accountList)    {
            accountMap.put(acct.Id, acct);
        }
        
        for(Contact contactNonPrime : contactList){
            for(Contact cc : accountMap.get(contactNonPrime.AccountId).Contacts){
                if(contactNonPrime.Primary_Contact__c == TRUE){
                    if(cc.Primary_Contact__c == TRUE && contactNonPrime.Id != cc.Id){
                        contactNonPrime.Primary_Contact__c.addError('Invalid Primary Contact. This Account has an existing Primary Contact.');
                    }
                }
            }
        }
    }
    
  /* Instruction Number 6
   * When a new Non-Primary Contact is created and the Account related to the new Contact does not have any existing Contacts, the new Contact should automatically become the Account's Primary Contact.
   */
        
    public static void setPrimaryContact(List<Contact> contactList){
        List<Account> accountList = [SELECT Id, (SELECT Id, Primary_Contact__c FROM Contacts)
                                     FROM Account];
        Map<Id, Account> accountMap = new Map<Id, Account>();
        
        for(Account acct : accountList)    {
            accountMap.put(acct.Id, acct);
        }
            
            for(Contact contactPrime : contactList){
                if(contactPrime.Primary_Contact__c != true && contactPrime.AccountId != NULL){
                   
                    if(accountMap.get(contactPrime.AccountId).Contacts.size() <1){
                        contactPrime.Primary_Contact__c = TRUE;
                    }
                }else if(contactPrime.Primary_Contact__c == TRUE && contactPrime.AccountId != NULL) {
                    for(Contact cc : accountMap.get(contactPrime.AccountId).Contacts){
                        if(cc.Primary_contact__c == TRUE){
                              contactPrime.Primary_Contact__c.addError('Invalid Primary Contact. This Account has an existing Primary Contact.');
                        }
                  }
             } 
        }
    }
}
  • January 10, 2019
  • Like
  • 0
Hi,
Can anyone help me how to display the data which is just now inserted in account ?
Hey guys,

I'd like to have the following formula (which pulls in a heatmap of NY from the Documents Tab)
<apex:page standardcontroller="Contact" showHeader="false">
     <apex:image id="NY" value="{!'/servlet/servlet.FileDownload?file=0F01k00000002Wn'}" width="1920" height="940"/>
</apex:page>

use an if statement/merge field to verify that the record's state is actually NY. For example, I'd like in Excel terms to do if(contact.state__c = "NY", <apex:image id="NYJan19" value="{!'/servlet/servlet.FileDownload?file=0F01k00000002Wn'}" width="1920" height="940"/> ,"")

The reason being that I plan on having an image for every state so I need to merge in the record's state field so I can properly match them. Otherwise this would require 50 visualforce pages.

Thanks!!
Created a custom list view in visual force to add onto a page mimicking a related list. 

I needed to remove the Action column-- that was sucessfully done through some javascript code I found here-- I pasted the code below too ( https://developer.salesforce.com/forums/?id=9060G000000MOwXQAW ). 
How can I remove the alphabet shortcuts above the list view? 

User-added image
________________________________________________________



<apex:page tabStyle="Order__c"  showHeader="false" standardController="Account"  >
                <style> 
                    .background {width:100%; hieght:100%; align:center; background:white;}
                </style>
        
        <div class="background">   
          
             <!-- This includeScript enables the script action below which removes the "Action" column of the list. -->
             <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"/> 
             <!-- <apex:sectionHeader title="Recieved" subTitle="Orders" /> --> 
                    <!-- <apex:pageMessages /> --> 
               <apex:ListViews type="Order__c" />    
               <!-- <apex:enhancedList type="Order__c" height="400" rowsPerPage="100"     />  -->
        </div>
             <script>
                 $(".actionColumn").css("display","none");
             </script>
             
             <script type="application/javascript">
    var aTags = document.getElementsByTagName('a');
    for(var i = 0; i < aTags.length; i++) 
        aTags[i].target = "_parent";
    function navigateToUrl (a){ 
        window.top.location.href = a; 
    }
            </script>
   
</apex:page>
Hi, I am trying to create a link (Content Delivery type of a link) for multiple files thru Code. I was able to create a link for a single file using ContentDistribution. The same thing I wanted to create one link for multiple files to be able to send  in the email. Right now this can be done thru Content Pack. But I don't want use Content Pack as I want to do thru code, I want to add files to Content pack or something similar and able to create a link out of that. ContentDistribution just takes the ContentVersionID . Looks like Content Pack api is not exposed . Please advise how to go with this ? thanks
Hi All,

I have a field label__c where i am storing custom label name related to each record. 
Here i am able to display this in visualforce page by using {!$Label[label__c]}, but i am not able to use same in visualforce components.

Please help me out in achiving this.

Thanks in advance.

 
Hi,
i need help from tou 
How to write a code to given scenario
User-added image
this is my vf page in this vf page insert values and click on save button.
After click of save button record will save and it will redirecting to object.
here i dont want to go object record page. after click of save button record save and page will redirect same vf page like below
User-added image
I've come across a very specific but easily reproduceable bug.  What happens is that if you have a form on a Visualforce Page with some inputFields on it which include two lookup fields, one dependent on the other via lookup filtering, and you do a partial rerender of the page, the cursor will jump from whatever field it is on up to the first field on the form.

I know, I know... that's pretty specific.  But several of my customers have hit this.  So I am looking for confirmation that it is a bug, and more importantly I am looking for advice on how I can combat this.

How to Reproduce:

First create two lookup fields on the Account object.  One lookup to the Account object and one to the Contact object.  The lookup to the Account object can be named "Distributor__c" and the one to the Contact "Distributor_Contact__c".  Then on the Contact lookup field, add the following lookup filter:

User-added image

The create this Apex Class...

public with sharing class cursorJumpExtension {

    public Integer refreshCount {get;set;}

    public cursorJumpExtension(ApexPages.StandardController controller) {
        refreshCount=0;
    }

    public void refreshPlus(){
        refreshCount+=1;
    }

}

Then this Visualforce Page...
 
<apex:page standardController="Account" extensions="cursorJumpExtension">
<apex:form >

    <apex:actionFunction name="doRefresh" action="{!refreshPlus}" reRender="refreshing" immediate="true"/>

    <apex:pageBlock id="refreshing">
   
        <script>
            window.setTimeout(doRefresh,3000);   
        </script>
   
        This block re-renders every 3 seconds.<br/><br/>
        Last refresh at: {!NOW()}<br/>
        Number of times refreshed: {!refreshCount}
    </apex:pageBlock>

    <apex:pageBlock >
        <apex:pageBlockSection columns="1">
            <apex:inputField value="{!Account.Name}"/>
            <apex:inputField value="{!Account.Distributor__c}"/>
            <apex:inputField value="{!Account.Distributor_Contact__c}"/>
            <apex:inputField value="{!Account.website}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>

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


Now navigate to the Page and put the cursor in the website field.  You will see that the next time the top box refreshes, the cursor jumps to the first field!  Annoying!  Then you can go back to your lookup field and deactivate the lookup filter... OR simply change it to a different kind of filter that doesn't reference another field, and the cursor jumping phenomena stops.

Anyone know what I can do here??