• Samantha Chua
  • NEWBIE
  • 35 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 7
    Replies
Hi Guys!

I am creating this custom button. What it does is that it will create a contract and push values from opportunity over, whenever it is being clicked.

Running into a problem here as I am trying to make my contract name = Opportunity contract type + Opportunity product + opportunity account name.

How do i do the concatenation?

Here is a snippet of my codes:
 
c.Name = "{!Opportunity.Contract_Type__c}"; + "{!Opportunity.Account}";



Any help is greatly appreciated!

Regards,
Samantha (:

Hi guys,

I have got a button which works perfectly find when generating a contract from Opporutnity.

However, if my opportunity MRR or opportunity Contract month (terms) equats to 0, it does not work. Any idea if there is a workaround?

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} 

var status = "{!Opportunity.StageName}";

var newRecords = [];

var caseRecordType = sforce.connection.query("Select Id from RecordType where SobjectType = 'Contract' and DeveloperName = 'contract'");

var records = caseRecordType.getArray("records"); 

if (status == "Closed Won") 
{ 
    var c = new sforce.SObject("Contract");
    c.RecordTypeId = records[0].Id;
    c.AccountId = "{!Opportunity.AccountId}";
    c.CompanySignedId = "{!Opportunity.Account_ManagerId__c}";
    c.Opportunity__c = "{!Opportunity.Id}";
    c.Contract_Type__c = "{!Opportunity.Contract_Type__c}";
    c.ContractTerm = "{!Opportunity.Contract_Term_months__c}";
    c.Product__c = "{!Opportunity.Product__c}";
    c.MRR__c = "{!VALUE(TEXT(Opportunity.New_MRR__c))}";
    c.CustomerSignedId = "{!Opportunity.Sold_To_ContactId__c}"; 

    newRecords.push(c); 
    sforce.connection.create(newRecords, 
                             { 
                                 onSuccess : function(result){ 
                                     console.log(result[0]); 
                                     console.log('Success '+result.id); 
                                     alert ('Service contract generated. Please refresh page to view latest case in Related Contract list.'); 
                                     
                                 }, 
                                     
                                     onFailure : function(){ 
                                         console.log('Error '+result[0]); 
                                     } 
                                 
                             }); 
    
} 
else 
{ 
    alert ('Opportunity must be closed won before a service contract can be generated.'); 
}

Thanks!

Regards,
Samantha
 

Hi Guys,

I am creating this custom button. What it does is that it will create a contract and push values from opportunity over, whenever it is being clicked.

Running into a problem here as the MRR value is not being pushed over. MRR is a currency field type, 16 digits and 2 decimal points.

How do I get it to populate?

Here is a snippet of my codes:
 
//c.MRR__c = "{!Opportunity.MRR__c}";

Regards,
Samantha (:
Hi Guys!

I am creating this custom button. What it does is that it will create a contract and push values from opportunity over, whenever it is being clicked.

Running into a problem here as I am trying to make my contract name = Opportunity contract type + Opportunity product + opportunity account name.

How do i do the concatenation?

Here is a snippet of my codes:
c.Name = "{!Opportunity.Contract_Type__c}"; + "{!Opportunity.Account}";
Any help is greatly appreciated!

Regards,
Samantha (:
 
Hi!

I have the following button which executes if contact email is not null. However, I would like to check the presence of an attachment before sending the email. 

Can't seem to find the Attachment object though. Any idea how I can add an if condition for Attachment.Id != null?
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

var email = "{!Contact.Email}";

if (email != null)
{  
   sforce.apex.execute("sendWelcomeOfficialReceiptEmail","sendOfficialReceipt",{caseId:'{!Case.Id}', contactId:'{!Contact.Id}'});
   alert ('Email sent. Please refresh page and check activity history.');
} else {
alert ('Contact email is empty. Please specify email and try again.');
}

Regards,
Samantha
Hi,

I have a snippet of conditional statements which are not executing ): Anyone knows what I am doing wrong?

These codes work:
//Retrieving email from email template name
            EmailTemplate ABC = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'ABC'];
            EmailTemplate domainX = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'BCS'];
            EmailTemplate efg = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'EFG'];
            EmailTemplate evpl = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'HIJ'];

            
                if (c.Product__c.contains('ABC')) {
                    templateId = ABC.Id;
                } else if (c.Product__c.equals('fib') || c.Product__c.equals('efg')){
                    templateId = efg.Id;
                } else if (c.Product__c.contains('Hosted') || c.Product__c.contains('Domain Name')){
                    templateId = domainX.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evpl.Id;
                }
            }

However, when i add in one more condition to check, it stopped working ):
Here is a snippet:
 
//Retrieving email from email template name
            EmailTemplate ABC = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'ABC'];
            EmailTemplate domainX = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'BCS'];
            EmailTemplate efg = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'EFG'];
            EmailTemplate evpl = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'HIJ'];
           
            EmailTemplate DDosWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'abc'];
            EmailTemplate fiberWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'csd'];
            EmailTemplate evplWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'sds'];
            
            if (c.Sales_Type__c.equals('Wholesale')) {
                isWholesale = true;
            } else {
                isWholesale = false;
            }
            
            if (isWholesale == false) {
                if (c.Product__c.contains('abc')) {
                    templateId = abc.Id;
                } else if (c.Product__c.equals('Fibernet') || c.Product__c.equals('Lite')){
                    templateId = efg.Id;
                } else if (c.Product__c.contains('Hosted') || c.Product__c.contains('Domain')){
                    templateId = domainX.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evpl.Id;
                }
            } else {
                if (c.Product__c.contains('abc')) {
                    templateId = DDosWS.Id;
                } else if (c.Product__c.equals('Fibernet') || c.Product__c.equals('Lite')){
                    templateId = fiberWS.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evplWS.Id;
                }
            }

What am I doing wrong in the boolean check?

Regards,
Samantha
 
Hi,

I have a snippet of code for a custom button which works great. But issue here is that it only generates the case record type tag to the profile of the current user. 

I am trying to get it to create another case record type instead but somehow the case.recordtypeid isnt working. Would appreciate any help or feedback on my snippet of codes here! (:
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} 
var status = "{!Opportunity.StageName}"; 
var newRecords = []; 
if (status == "Closed Won") 
{ 
var c = new sforce.SObject("Case"); 
c.RecordType = "0126F000000uanz"; 
c.AccountId = "{!Opportunity.AccountId}"; 
c.Type = "{!Opportunity.Type}"; 
c.Subject = "{!Opportunity.Name}"; 

newRecords.push(c); 
result = sforce.connection.create(newRecords); 
alert ('Case has been created.Please refresh page')} 
else 
{ 
alert ('Opportunity must be won before a case can be generated.'); 
}

Regards,
Samantha
Hi guys,

I have got 2 codes, 1 for the apex class with webservice and the other for my custom button. While the button seems to be running fine, the class dont seem to be executing. I am unable to find where I have gone wrong. Would appreicate any form of feedback possible.

Regards,
Samantha
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 

var email = "{!Contact.Email}"; 

if (email != null) 
{ 
sforce.apex.execute("sendWelcomeEmailtoContactEmail","sendWelcomeEmail",{caseId:'{!Case.Id}', contactId:'{!Contact.Id}'}); 
alert ('Email sent. Please refresh page and check activity history.'); 
} else { 
alert ('Contact email is empty. Please specify email and try again.'); 
}

global class sendWelcomeEmailtoContactEmail{
    
    WebService static void sendWelcomeEmail(ID caseId, ID contactId){
        
        Attachment aAtt;
        Id templateId;
        list <String> ccAdd = new List<String>();
        
        ccAdd.add('samanthachuazl@gmail.com');
                        
        try{        
            
            EmailTemplate fiberTemplate = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'receipt'];
            templateId = fiberTemplate.Id;  
            
            //Creating a new email file attachment list and file attachment object
            Messaging.EmailFileAttachment [] efaList = new List<Messaging.EmailFileAttachment> () ;
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            
            efa.setFileName(aAtt.Name);
            efa.setBody(aAtt.Body);
            efa.setContentType(aAtt.ContentType);
            efaList.add(efa);              
            
            //creating a new email envelope
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            
            mail.setSenderDisplayName('Sales');
            
            if(efaList != null) {
                mail.setFileAttachments(efaList) ;
            }
            
            //mail.setToAddresses(toAdd);            
            mail.setTargetObjectId(contactId);
            mail.setWhatid(caseId);
            mail.setTemplateId(templateId);
            //mail.setPlainTextBody('hellos');
            mail.setUseSignature(false);
            mail.setCcAddresses(ccAdd);
            mail.setBccSender(false);
            mail.setSaveAsActivity(true);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
        }        
        
        catch(Exception e)
        {
            System.debug('***Catch Exception : ' + e);
        }
    }    
}
Hi,

I would like to know how I can retrieve a Case Object based on the Attachment Parent ID (Trigger). Been trying to do so but not making any progress. Would appreciate some advice on how I can go about doing so~!

Cheers
Hi

I have a working code which allows to me to send whatever is being attached to a case. However, although mail.setWhatid(caseId) clearly takes in the case id linked to the attachment being uploaded, the email activity is still not being saved in case activity history. Please advise.
List<Attachment> attList = [SELECT Id, CreatedDate, ParentId, Name, Body, ContentType, Parent.Name FROM ATTACHMENT WHERE Id in: trigger.newMap.keySet()];
    
    for (Attachment a : attList) {
        attachIdList.add(a.parentId);
    }   
    
    List<Case> caseList = [Select Id from Case where Id in: attachIdList LIMIT 1];   
    
    for (Attachment att : attList) {
        for (case c : caseList) {
            if (today.isSameDay(att.CreatedDate) && att.ParentId == c.Id) {
                caseId = att.ParentId;
                aAtt = att;
            }
        }
    }
    
    Messaging.EmailFileAttachment [] efaList = new List<Messaging.EmailFileAttachment> () ;
    Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
    
    efa.setFileName(aAtt.Name);
    efa.setBody(aAtt.Body);
    efa.setContentType(aAtt.ContentType);
    efaList.add(efa) ;   
    
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
    mail.setSenderDisplayName 'Corporate Sales Support hehehe');
    
    if(efaList != null) {
        mail.setFileAttachments(efaList) ;
    }
    mail.setToAddresses(toAdd);
    mail.setWhatid(caseId);
    //mail.setTemplateId(et.id);
    mail.setPlainTextBody('hellos');
    mail.setUseSignature(false);
    mail.setBccSender(false);
    mail.setSaveAsActivity(true);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

 

Hi guys,

I have got a button which works perfectly find when generating a contract from Opporutnity.

However, if my opportunity MRR or opportunity Contract month (terms) equats to 0, it does not work. Any idea if there is a workaround?

 

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} 

var status = "{!Opportunity.StageName}";

var newRecords = [];

var caseRecordType = sforce.connection.query("Select Id from RecordType where SobjectType = 'Contract' and DeveloperName = 'contract'");

var records = caseRecordType.getArray("records"); 

if (status == "Closed Won") 
{ 
    var c = new sforce.SObject("Contract");
    c.RecordTypeId = records[0].Id;
    c.AccountId = "{!Opportunity.AccountId}";
    c.CompanySignedId = "{!Opportunity.Account_ManagerId__c}";
    c.Opportunity__c = "{!Opportunity.Id}";
    c.Contract_Type__c = "{!Opportunity.Contract_Type__c}";
    c.ContractTerm = "{!Opportunity.Contract_Term_months__c}";
    c.Product__c = "{!Opportunity.Product__c}";
    c.MRR__c = "{!VALUE(TEXT(Opportunity.New_MRR__c))}";
    c.CustomerSignedId = "{!Opportunity.Sold_To_ContactId__c}"; 

    newRecords.push(c); 
    sforce.connection.create(newRecords, 
                             { 
                                 onSuccess : function(result){ 
                                     console.log(result[0]); 
                                     console.log('Success '+result.id); 
                                     alert ('Service contract generated. Please refresh page to view latest case in Related Contract list.'); 
                                     
                                 }, 
                                     
                                     onFailure : function(){ 
                                         console.log('Error '+result[0]); 
                                     } 
                                 
                             }); 
    
} 
else 
{ 
    alert ('Opportunity must be closed won before a service contract can be generated.'); 
}

Thanks!

Regards,
Samantha
 

Hi Guys!

I am creating this custom button. What it does is that it will create a contract and push values from opportunity over, whenever it is being clicked.

Running into a problem here as I am trying to make my contract name = Opportunity contract type + Opportunity product + opportunity account name.

How do i do the concatenation?

Here is a snippet of my codes:
c.Name = "{!Opportunity.Contract_Type__c}"; + "{!Opportunity.Account}";
Any help is greatly appreciated!

Regards,
Samantha (:
 
Hi,

I have a snippet of conditional statements which are not executing ): Anyone knows what I am doing wrong?

These codes work:
//Retrieving email from email template name
            EmailTemplate ABC = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'ABC'];
            EmailTemplate domainX = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'BCS'];
            EmailTemplate efg = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'EFG'];
            EmailTemplate evpl = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'HIJ'];

            
                if (c.Product__c.contains('ABC')) {
                    templateId = ABC.Id;
                } else if (c.Product__c.equals('fib') || c.Product__c.equals('efg')){
                    templateId = efg.Id;
                } else if (c.Product__c.contains('Hosted') || c.Product__c.contains('Domain Name')){
                    templateId = domainX.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evpl.Id;
                }
            }

However, when i add in one more condition to check, it stopped working ):
Here is a snippet:
 
//Retrieving email from email template name
            EmailTemplate ABC = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'ABC'];
            EmailTemplate domainX = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'BCS'];
            EmailTemplate efg = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'EFG'];
            EmailTemplate evpl = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'HIJ'];
           
            EmailTemplate DDosWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'abc'];
            EmailTemplate fiberWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'csd'];
            EmailTemplate evplWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'sds'];
            
            if (c.Sales_Type__c.equals('Wholesale')) {
                isWholesale = true;
            } else {
                isWholesale = false;
            }
            
            if (isWholesale == false) {
                if (c.Product__c.contains('abc')) {
                    templateId = abc.Id;
                } else if (c.Product__c.equals('Fibernet') || c.Product__c.equals('Lite')){
                    templateId = efg.Id;
                } else if (c.Product__c.contains('Hosted') || c.Product__c.contains('Domain')){
                    templateId = domainX.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evpl.Id;
                }
            } else {
                if (c.Product__c.contains('abc')) {
                    templateId = DDosWS.Id;
                } else if (c.Product__c.equals('Fibernet') || c.Product__c.equals('Lite')){
                    templateId = fiberWS.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evplWS.Id;
                }
            }

What am I doing wrong in the boolean check?

Regards,
Samantha
 
Hi,

I have a snippet of code for a custom button which works great. But issue here is that it only generates the case record type tag to the profile of the current user. 

I am trying to get it to create another case record type instead but somehow the case.recordtypeid isnt working. Would appreciate any help or feedback on my snippet of codes here! (:
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} 
var status = "{!Opportunity.StageName}"; 
var newRecords = []; 
if (status == "Closed Won") 
{ 
var c = new sforce.SObject("Case"); 
c.RecordType = "0126F000000uanz"; 
c.AccountId = "{!Opportunity.AccountId}"; 
c.Type = "{!Opportunity.Type}"; 
c.Subject = "{!Opportunity.Name}"; 

newRecords.push(c); 
result = sforce.connection.create(newRecords); 
alert ('Case has been created.Please refresh page')} 
else 
{ 
alert ('Opportunity must be won before a case can be generated.'); 
}

Regards,
Samantha
Hi guys,

I have got 2 codes, 1 for the apex class with webservice and the other for my custom button. While the button seems to be running fine, the class dont seem to be executing. I am unable to find where I have gone wrong. Would appreicate any form of feedback possible.

Regards,
Samantha
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 

var email = "{!Contact.Email}"; 

if (email != null) 
{ 
sforce.apex.execute("sendWelcomeEmailtoContactEmail","sendWelcomeEmail",{caseId:'{!Case.Id}', contactId:'{!Contact.Id}'}); 
alert ('Email sent. Please refresh page and check activity history.'); 
} else { 
alert ('Contact email is empty. Please specify email and try again.'); 
}

global class sendWelcomeEmailtoContactEmail{
    
    WebService static void sendWelcomeEmail(ID caseId, ID contactId){
        
        Attachment aAtt;
        Id templateId;
        list <String> ccAdd = new List<String>();
        
        ccAdd.add('samanthachuazl@gmail.com');
                        
        try{        
            
            EmailTemplate fiberTemplate = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'receipt'];
            templateId = fiberTemplate.Id;  
            
            //Creating a new email file attachment list and file attachment object
            Messaging.EmailFileAttachment [] efaList = new List<Messaging.EmailFileAttachment> () ;
            Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
            
            efa.setFileName(aAtt.Name);
            efa.setBody(aAtt.Body);
            efa.setContentType(aAtt.ContentType);
            efaList.add(efa);              
            
            //creating a new email envelope
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            
            mail.setSenderDisplayName('Sales');
            
            if(efaList != null) {
                mail.setFileAttachments(efaList) ;
            }
            
            //mail.setToAddresses(toAdd);            
            mail.setTargetObjectId(contactId);
            mail.setWhatid(caseId);
            mail.setTemplateId(templateId);
            //mail.setPlainTextBody('hellos');
            mail.setUseSignature(false);
            mail.setCcAddresses(ccAdd);
            mail.setBccSender(false);
            mail.setSaveAsActivity(true);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
        }        
        
        catch(Exception e)
        {
            System.debug('***Catch Exception : ' + e);
        }
    }    
}
Hi

I have a working code which allows to me to send whatever is being attached to a case. However, although mail.setWhatid(caseId) clearly takes in the case id linked to the attachment being uploaded, the email activity is still not being saved in case activity history. Please advise.
List<Attachment> attList = [SELECT Id, CreatedDate, ParentId, Name, Body, ContentType, Parent.Name FROM ATTACHMENT WHERE Id in: trigger.newMap.keySet()];
    
    for (Attachment a : attList) {
        attachIdList.add(a.parentId);
    }   
    
    List<Case> caseList = [Select Id from Case where Id in: attachIdList LIMIT 1];   
    
    for (Attachment att : attList) {
        for (case c : caseList) {
            if (today.isSameDay(att.CreatedDate) && att.ParentId == c.Id) {
                caseId = att.ParentId;
                aAtt = att;
            }
        }
    }
    
    Messaging.EmailFileAttachment [] efaList = new List<Messaging.EmailFileAttachment> () ;
    Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
    
    efa.setFileName(aAtt.Name);
    efa.setBody(aAtt.Body);
    efa.setContentType(aAtt.ContentType);
    efaList.add(efa) ;   
    
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
    mail.setSenderDisplayName 'Corporate Sales Support hehehe');
    
    if(efaList != null) {
        mail.setFileAttachments(efaList) ;
    }
    mail.setToAddresses(toAdd);
    mail.setWhatid(caseId);
    //mail.setTemplateId(et.id);
    mail.setPlainTextBody('hellos');
    mail.setUseSignature(false);
    mail.setBccSender(false);
    mail.setSaveAsActivity(true);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});