• Pinky 10
  • NEWBIE
  • 40 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 9
    Replies
Something is wrong in my code for email template I am getting a below o/p but I want fig 2 output.It looks good on page but when i am generating
 a PDF it is showing below ouput. 
Fig 1

fig 2
User-added image





File
Edit
Debug
Test
Workspace
Help
<
>
ProspectingStatusUpdater
TrigToValidateContactRoles
Code Coverage: None
API Version:
Go To
1
trigger TrigToValidateContactRoles on Opportunity (before insert, before update) {
2

3
List<OpportunityContactRole> conRoleList = new List<OpportunityContactRole>();
4

5
Set<Id> ownerIdSet = new Set<Id>();
6

7
for(Opportunity opp : Trigger.new){
8
ownerIdSet.add(opp.ownerId);
9
}
10

11
User loggedInUser = [Select Id, Profile.Name from User where id =: UserInfo.getUserId() limit 1];
12

13
List<User> userList = [Select Id, UserRole.Name, Profile.Name from User where id in: ownerIdSet and UserRole.Name != null];
14

15
if(Trigger.isUpdate)
16
conRoleList = [Select Id, OpportunityId from OpportunityContactRole where OpportunityId in: Trigger.newMap.keySet()];
17

18
for(Opportunity opp : Trigger.new)
19
{
20

21
boolean isVerifyRolesValidation = True;
22

23
if(loggedInUser.Profile.Name.contains('System Administrator') || loggedInUser.Profile.Name.contains('Sales - Executive') || loggedInUser.Profile.Name.contains('Sales Operations - Liz Temp'))
24
{
25
isVerifyRolesValidation = false;
26
}
27
else
28
{
29
for(User u : userList)
30
{
31
if(opp.ownerId == u.Id && u.UserRole.Name.contains('Account Management'))
32
{
33
isVerifyRolesValidation = false;
34
break;
35
}
36
}
37
}
38
if(isVerifyRolesValidation){
39

40
if(opp.Probability >= 50)
41
{
42
if(Trigger.isInsert){
43
opp.addError('Contact Roles must be entered for this Opportunity before the Stage can be changed to Proposal or higher');
44
}
45
if(Trigger.isUpdate)
46
{
47
boolean isValid = false;
48
for(OpportunityContactRole cr : conRoleList){
49
if(opp.Id == cr.OpportunityId){
50
isValid = True;
51
break;
52
}
53
}
54

55
if(!isValid){
56
opp.addError('Contact Roles must be entered for this Opportunity before the Stage can be changed to Proposal or higher');
57
}
58
}
59
}
60
}
61
}
62
}
 


 
trigger OppValidateMandatoryFields on Opportunity (before update) {

    List<String> accounts = new List<String>{};
    List<String> asotpa = new List<String>{};
    
    for (Opportunity ao:trigger.new){
        accounts.add(ao.AccountId);
        asotpa.add(ao.ASO_or_TPA_Account__c);
    }

    Map<Id, Account> oppaccountsMap = new Map<Id, Account>([SELECT Referral_Agent_Broker_Contact_Person_new__r.Email, Account_Legal_Name__c, Account_Manager__r.Email, Client_Channel_Segment__c, Client_Channel_Sub_Segment__c, Revenue_Effective_Date__c, Phone, Payment_Terms__c, Utilization_Guarantee__c, Utilization_Guarantee_Details__c, Rate_Lock_Period__c, Rate_Lock_Period_Details__c, Util_Cap_for_Consult__c, Util_Cap_Description__c, Account_Type__c from Account
              WHERE Id IN :accounts]);
    Map<Id, Account> asotpasMap = new Map<Id, Account>([SELECT Name from Account
              WHERE Id IN :asotpa]);  
    Map<Id, OpportunityContactRole> oppcontactMap = new Map<Id, OpportunityContactRole>();
    for(OpportunityContactRole ocr :[SELECT OpportunityId, Contact.Email, Contact.Phone FROM OpportunityContactRole WHERE OpportunityId in :Trigger.New AND IsPrimary = true]){
        oppcontactMap.put(ocr.OpportunityId, ocr);
    }
              
    Set<Id> oppOwners = new Set<Id>();
    for(User u : [select Id from User where Username like 'aroga@teladoc%' or username like 'aford@teladoc%' or username like 'trenz@teladoc%' or username like 'ejoy@teladoc%' or username like 'dgoldberg@teladoc%']){
        oppOwners.add(u.Id);
    }
    
    Id providerType = [Select Id from RecordType where DeveloperName = 'Provider_Platform'][0].Id;
              
    for(Opportunity obj : trigger.new){
        
        Opportunity oldOpp = new Opportunity();
        oldOpp = Trigger.oldMap.get(obj.Id);
        
        if (obj.RecordTypeId != providerType && (oldOpp.StageName != 'Contracting' && oldOpp.StageName != 'Closed Won') && (obj.StageName == 'Contracting' ||  obj.StageName == 'Closed Won') && (/* obj.Client_Retail_Fee__c == null || */ obj.Teladoc_Net_Fee__c == null || obj.Fee_Type__c == null || oppaccountsMap.get(obj.AccountId).Account_Legal_Name__c == null || oppaccountsMap.get(obj.AccountId).Client_Channel_Segment__c == null || oppaccountsMap.get(obj.AccountId).Client_Channel_Sub_Segment__c == null || /* oppaccountsMap.get(obj.AccountId).Revenue_Effective_Date__c == null || */ oppaccountsMap.get(obj.AccountId).Phone == null || /* oppaccountsMap.get(obj.AccountId).Payment_Terms__c == null || */ oppaccountsMap.get(obj.AccountId).Utilization_Guarantee__c == null || oppaccountsMap.get(obj.AccountId).Utilization_Guarantee_Details__c == null || oppaccountsMap.get(obj.AccountId).Rate_Lock_Period__c == null || oppaccountsMap.get(obj.AccountId).Rate_Lock_Period_Details__c == null || oppaccountsMap.get(obj.AccountId).Util_Cap_for_Consult__c == null || oppaccountsMap.get(obj.AccountId).Util_Cap_Description__c == null || (oppcontactMap.get(obj.Id) != null && (oppcontactMap.get(obj.Id).Contact.Email == null || oppcontactMap.get(obj.Id).Contact.Phone == null))) && obj.Description != 'Test Data'){
            obj.addError('You are missing mandatory fields necessary to move an opportunity to Contracting or Closed Won. <a href="https://c.'+System.Url.getSalesforceBaseURL().getHost().substringBefore('.')+'.visual.force.com/apex/missingfields_ci?aid='+obj.AccountId+'&oid='+obj.Id+'" >Click here for list of missing fields</a>', FALSE);
        }else if((oldOpp.StageName != 'Contracting' && oldOpp.StageName != 'Closed Won') && (obj.StageName == 'Contracting' ||  obj.StageName == 'Closed Won')){
                        
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String ASO_Name;
            
            ASO_Name = 'empty';
            if (obj.ASO_or_TPA_Account__c != null){
                ASO_Name = asotpasMap.get(obj.ASO_or_TPA_Account__c).Name;
            }
            String[] ToAddresses;
            //ToAddresses = new String[] { UserInfo.getUserEmail() };
            String[] CcAddresses;
            // CcAddresses = new String[] { 'jvela@cloudberrycreative.com' };
    
            Set<String> CcAddresses2 = new Set<String> {UserInfo.getUserEmail(), obj.Account_Owner_Email__c};
            
            if (oppaccountsMap.get(obj.AccountId).Account_Manager__r.Email != null){
                toAddresses = new String[] { oppaccountsMap.get(obj.AccountId).Account_Manager__r.Email };
            } else if(oppOwners.contains(obj.OwnerId)){
                toAddresses = new String[] { 'ksanderson@teladoc.com','ProvImplementation@teladoc.com' };
                CcAddresses = new String[] { 'aaddis@teladoc.com' };
            } else if(ASO_Name.contains('Aetna') || obj.Name.contains('Aetna')){
                toAddresses = new String[] { 'lferguson@teladoc.com','scrain@teladoc.com','ldelarso@teladoc.com','kwarrick@teladoc.com' };
                CcAddresses = new String[] { 'aaddis@teladoc.com' };
            } else if (obj.Initial_of_Lives__c < 500 && oppaccountsMap.get(obj.AccountId).Account_Type__c != 'Health Plan'){
                toAddresses = new String[] { 'newimplementation@teladoc.com' };
                CcAddresses = new String[] { 'aaddis@teladoc.com' };        
            } else if (oppaccountsMap.get(obj.AccountId).Account_Type__c == 'Reseller'){
                toAddresses = new String[] { 'ResellImplemenation@teladoc.com','kbowie@teladoc.com' };
                CcAddresses = new String[] { 'aaddis@teladoc.com' };
            } else if (obj.Initial_of_Lives__c >= 500 && obj.Initial_of_Lives__c <= 20000 && oppaccountsMap.get(obj.AccountId).Account_Type__c != 'Health Plan'){
                toAddresses = new String[] { 'midimplementation@teladoc.com','dvindedzis@teladoc.com' };
                CcAddresses = new String[] { 'aaddis@teladoc.com' };
            } else if (obj.Initial_of_Lives__c > 20000 || oppaccountsMap.get(obj.AccountId).Account_Type__c == 'Health Plan'){
                toAddresses = new String[] { 'jtardie@teladoc.com','LargeImplementation@teladoc.com' };
                CcAddresses = new String[] { 'aaddis@teladoc.com' };
            } else {
                toAddresses = new String[] { 'aaddis@teladoc.com' };
            }
            
            if(CcAddresses != null && CcAddresses.size() > 0){
                CcAddresses.addAll(CcAddresses2);
            } else {
                CcAddresses = new List<String>(CcAddresses2);
            }
            
            mail.setToAddresses(toAddresses);         
            mail.setCcAddresses(ccAddresses);
            mail.setReplyTo('executive@teladoc.com');
            mail.setSenderDisplayName('Teladoc Mail Service');
            mail.setBccSender(false);
            mail.setUseSignature(false);
            mail.setSaveAsActivity(false);
    
            if (oppaccountsMap.get(obj.AccountId).Account_Manager__r.Email != null){
                mail.setSubject('New client intake form');
                mail.setHtmlBody('<html><body>'+obj.Name+' is now in stage '+obj.StageName+'. <a href="https://'+System.Url.getSalesforceBaseURL().getHost().substringBefore('.')+'.salesforce.com/apex/ClientIntakeForm?aid='+obj.AccountID+'&oid='+obj.Id+'">Click here</a> to view the Client Intake Form.</body></html>');
            } else {
                mail.setSubject('New client intake form, please assign an Account Manager');
                mail.setHtmlBody('<html><body>'+obj.Name+' is now in stage '+obj.StageName+'. <a href="https://'+System.Url.getSalesforceBaseURL().getHost().substringBefore('.')+'.salesforce.com/apex/ClientIntakeForm?aid='+obj.AccountID+'&oid='+obj.Id+'">Click here</a> to view the Client Intake Form. Please assign an Account Manager.</body></html>');
            }
            
            try{
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            } catch (Exception e){
                System.debug(e.getMessage());
                System.debug('There was an error while sending email notification to the recipients: ' + toAddresses + ' CC: ' + ccAddresses);
            }
        }
    }
}

 
public with sharing class LaunchTinderboxController {

    Id oppid = System.currentPageReference().getParameters().get('id');
    string buttonid = System.currentPageReference().getParameters().get('bid');
    
    public Opportunity opp = new Opportunity();
    public Opportunity getOpp(){
        opp = [SELECT Id, Proposal_Template__c, Tbox_template__c, Contract__c, Pricing_Option__c, Include_Additional_Pricing_Option__c, Additional_Pricing_Option__c from Opportunity where Id = :oppid];
        return opp;
    }
    
    public PageReference gotoTinderbox(){
        getOpp();
        if (buttonid == 'proposal'){
            opp.Tbox_template__c = opp.Proposal_Template__c;
            update opp;
        }
        if (buttonid == 'contract'){
            opp.Tbox_template__c = opp.Contract__c;
            update opp;
        }
        if (buttonid == 'baa'){
            opp.Tbox_template__c = 'BAA';
            update opp;
        }
    PageReference callPage = new PageReference('/apex/tinderbox__create_proposal_opp?Id='+oppid);
    return callPage;    
    }
}
@isTest
private class TestCheckJitterbitExtract {

    static testMethod void myUnitTest() {
       Test.startTest();

    Batchaccountcountfieldschedule sh1 = new Batchaccountcountfieldschedule();

    String sch = '0 0 2 * * ?';

    system.schedule('Test Territory Check', sch, sh1);

    Test.stopTest();
       
        
    }
}

for 

global class CheckJitterbitExtract implements Schedulable{
    global void execute(SchedulableContext SC) {
        boolean jobRanOK = false;
        DateTime dt = DateTime.now().addHours(-5);
        for(LoginHistory lh : [Select Status, LoginTime, Application From LoginHistory where LoginType = 'Partner Product' and UserId = '00560000001brWwAAI' and LoginTime > :dt]){
            if(lh.Status == 'Success' && lh.Application.contains('Jitterbit')){
                jobRanOK = true;
            }
        }
        if(!jobRanOK)
            throw new JitterbitException('Please check Jitterbit to investigate a possible issue with ToBe extract as there was no connection made to SF today.');
    }
}


 
global class EmailSignatureController {

global String leadState {get;set;}

Private Set<String> westStates = new Set<String>{'AK','AZ','AR','CA','CO','HI','ID','IA','KS','LA','MO','MT','NE','NV','NM','ND','OK','OR','SD','TX','UT','WA'};
//Private Set<String> eastStates {'AL','CT','DE','DC','FL','GA','IL','IN','KY','ME','MA','MD','MI','MN','MS','NH','NJ','NY','NC','OH','PA','RI','SC','TN','VT','VA','WV','WI','WY'};

global User getSender(){

User sender = null;

if(leadState != null && !westStates.contains(leadState)){

sender = [Select Name, Email, Phone, Title from User where IsActive = true and UserName like 'msweetser@teladoc%' limit 1][0];

} else {
sender = [Select Name, Email, Phone, Title from User where IsActive = true and UserName like 'tyanquoi@teladoc%' limit 1][0];
}

return sender;

}


}
public with sharing class LaunchTinderboxController {

    Id oppid = System.currentPageReference().getParameters().get('id');
    string buttonid = System.currentPageReference().getParameters().get('bid');
    
    public Opportunity opp = new Opportunity();
    public Opportunity getOpp(){
        opp = [SELECT Id, Proposal_Template__c, Tbox_template__c, Contract__c, Pricing_Option__c, Include_Additional_Pricing_Option__c, Additional_Pricing_Option__c from Opportunity where Id = :oppid];
        return opp;
    }
    
    public PageReference gotoTinderbox(){
        getOpp();
        if (buttonid == 'proposal'){
            opp.Tbox_template__c = opp.Proposal_Template__c;
            update opp;
        }
        if (buttonid == 'contract'){
            opp.Tbox_template__c = opp.Contract__c;
            update opp;
        }
        if (buttonid == 'baa'){
            opp.Tbox_template__c = 'BAA';
            update opp;
        }
    PageReference callPage = new PageReference('/apex/tinderbox__create_proposal_opp?Id='+oppid);
    return callPage;    
    }
}
@isTest
private class TestCheckJitterbitExtract {

    static testMethod void myUnitTest() {
       Test.startTest();

    Batchaccountcountfieldschedule sh1 = new Batchaccountcountfieldschedule();

    String sch = '0 0 2 * * ?';

    system.schedule('Test Territory Check', sch, sh1);

    Test.stopTest();
       
        
    }
}

for 

global class CheckJitterbitExtract implements Schedulable{
    global void execute(SchedulableContext SC) {
        boolean jobRanOK = false;
        DateTime dt = DateTime.now().addHours(-5);
        for(LoginHistory lh : [Select Status, LoginTime, Application From LoginHistory where LoginType = 'Partner Product' and UserId = '00560000001brWwAAI' and LoginTime > :dt]){
            if(lh.Status == 'Success' && lh.Application.contains('Jitterbit')){
                jobRanOK = true;
            }
        }
        if(!jobRanOK)
            throw new JitterbitException('Please check Jitterbit to investigate a possible issue with ToBe extract as there was no connection made to SF today.');
    }
}


 
global class EmailSignatureController {

global String leadState {get;set;}

Private Set<String> westStates = new Set<String>{'AK','AZ','AR','CA','CO','HI','ID','IA','KS','LA','MO','MT','NE','NV','NM','ND','OK','OR','SD','TX','UT','WA'};
//Private Set<String> eastStates {'AL','CT','DE','DC','FL','GA','IL','IN','KY','ME','MA','MD','MI','MN','MS','NH','NJ','NY','NC','OH','PA','RI','SC','TN','VT','VA','WV','WI','WY'};

global User getSender(){

User sender = null;

if(leadState != null && !westStates.contains(leadState)){

sender = [Select Name, Email, Phone, Title from User where IsActive = true and UserName like 'msweetser@teladoc%' limit 1][0];

} else {
sender = [Select Name, Email, Phone, Title from User where IsActive = true and UserName like 'tyanquoi@teladoc%' limit 1][0];
}

return sender;

}


}