• Rom_
  • NEWBIE
  • 35 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 10
    Replies
Can anyone help with Code Coverage error. Tried to update a Class (that's already in production) to include one extra field (picklist - Status__c). Test passed, but getting 0% Code Coverage when deploying to production.

Class:
public class MultiAddUSUWHold {
    private ApexPages.StandardController std;
     
    // the associated USUWHs
   public List<US_UW_Hold__c> USUWH;
      
    // the chosen USUWH id - used when deleting a USUWH
    public Id chosenUSUWHId {get; set;}
     
    public MultiAddUSUWHold(ApexPages.StandardController stdCtrl)
    {
     std=stdCtrl;
    }
     
    public ISOOffice__Merchant_Application__c getApplication_Package()
    {
     return (ISOOffice__Merchant_Application__c) std.getRecord();
    }
 
    private boolean updateUSUWHs()
    {
        boolean result=true;
        if (null!=USUWH)
           {
           List<US_UW_Hold__c> updConts=new List<US_UW_Hold__c>();
              try
              {
               update USUWH;
              }
              catch (Exception e)
              {
                 String msg=e.getMessage();
                 integer pos;
                  
                 // if its field validation, this will be added to the messages by default
                 if (-1==(pos=msg.indexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION, ')))
                 {
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, msg));
                 }
                  
                 result=false;
              }
           }
            
           return result;
    }
     
    public PageReference saveAndExit()
    {
     boolean result=true;
    result=updateUSUWHs();
      
     if (result)
     {
        // call standard controller save
        return std.save();
     }
     else
     {
      return null;
     }
    }
     
    public PageReference save()
    {
     Boolean result=true;
     PageReference pr=Page.USUWHolds;
     if (null!=getApplication_Package().id)
     {
      result=updateUSUWHs();
     }
     else
     {
      pr.setRedirect(true);
     }
      
     if (result)
     {
        // call standard controller save, but don't capture the return value which will redirect to view page
        std.save();
           ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Changes saved'));
     }
        pr.getParameters().put('id', getApplication_Package().id);
      
     return pr;
    }
 
    public void newUSUWH()
    {
       if (updateUSUWHs())
       {
          US_UW_Hold__c cont=new US_UW_Hold__c(Stip__c='', Application_Package__c=getApplication_Package().id);
          insert cont;
         
          // null the USUWHs list so that it is rebuilt
          USUWH=null;
       }
    }
     
    public void deleteUSUWH()
    {
       if (updateUSUWHs())
       {
          if (null!=chosenUSUWHId)
          {
             US_UW_Hold__c cont=new US_UW_Hold__c(Id=chosenUSUWHId);
              delete cont;
        
           // null the USUWHs list so that it is rebuilt
              USUWH=null;
              chosenUSUWHId=null;
          }
       }
    }
     
   public List<US_UW_Hold__c> getUSUWHs()
    {
       if ( (null!=getApplication_Package().id) && (USUWH == null) )
       {
           USUWH=[SELECT Id, Name, Stip__c, Received__c, Status__c, CreatedDate, Application_Package__r.Id
                         FROM US_UW_Hold__c 
                         WHERE Application_Package__r.Id = : getApplication_Package().ID
                         ORDER BY CreatedDate];
       }
                           
       return USUWH;
    }
}

Test:
@isTest(SeeAllData=true)
private class USUWHoldTest 
{
    public static testMethod void MultiAddUSUWHold()
    {
        ISOOffice__Merchant_Application__c App = new ISOOffice__Merchant_Application__c();
        App.Name =  'Test for US UW Holds';
        insert App;
        
        
        US_UW_Hold__c U = new US_UW_Hold__c();
        U.Stip__c = 'CRM Testing Stip';
        U.Received__c = true;
        U.Status__c = 'Received';
        U.Application_Package__c = App.Id;
        insert U;
                        
    }
}

Tried to take off SeeAllData on test class, same results.
Anyone have idea on how to resolve this? Any help will be much appreciated :)​
  • September 28, 2017
  • Like
  • 0
Hello, looking for a way to change a text input field on a Visualforce page to be displayed as an output field after something is entered in that field and save button is pressed. Or generally a way to make the field read-only once it is not null. Hoping to avoid using a controller. Any help much appreciated.
  • April 05, 2016
  • Like
  • 0
Not a developer, but somehow managed to write a working trigger in sandbox. Trying to deploy to production, says no code coverage. Can someone please help. What do I need to do to successfuly deploy to prodution. 
Trigger:
trigger updateRelatedLead on Task (after insert,after update) {

 List<Id> LeadIds = new List<Id>();
 List<Lead> LeadList = new List<Lead>();

  for(Task t :trigger.new)
    {
	if(t.whoId!=null)
	{
        Schema.SObjectType tType= t.whoId.getSObjectType();
        if(tType == Lead.Schema.SObjectType)
        {
            LeadIds.add(t.WhoId);
        }
    }
	}
	//Querying the related Lead based on whoId on Task
	Map<Id,Lead> LeadMap =  new Map<Id,Lead>([select id,Latest_Follow_Up__c,Task_Subject__c,Task_Comment__c from Lead where id in:LeadIds]);
	
	for(Task t :Trigger.new)

		for(Lead l : LeadMap.Values())
		{
			l.Latest_Follow_Up__c = t.Due_Date_Time__c;
            l.Task_Subject__c = t.Subject;
            l.Task_Comment__c = t.ISOOffice__Comment__c;
			LeadList.add(l);
		}
	// updating the Lead
    if(LeadList.isEmpty() == false) update LeadList;
	}

 
  • January 26, 2016
  • Like
  • 0
Trying to deploy this trigger to production. Received following error message:
 Methods defined as TestMethod do not support Web service callouts 
Stack Trace: null

 
trigger updateOppField on Account(before insert, before update){
     for(Account acc : trigger.new){
         if(acc.Text_ID__c != null){
             acc.A_Opportunity__c = acc.Text_ID__c;
         }
     }
 }
Any ideas/solutions will be greatly appreciated.

 
  • October 28, 2015
  • Like
  • 0
Text_ID__c - text field with id of an Opportunity
A_Opportunity__c - lookup field to Opportunity

Both fields are in standard Account object. How can I populate the lookup field with the id in the text field? Will not work with workflow or process builder, guess I need Apex trigger (with which I have little experience). Can anyone provide code for this to at least put me on the right track? Would greatly appreciate it :)
  • October 28, 2015
  • Like
  • 0

Hello all,

 

Is it possible to setup inbound emails (using Email Services) to save to a new record in a custom object or Activity History and populate a lookup field in that object with a text string in that email?

 

Purpose:

We have a custom object Tickets__c that we send out emails from. The emails sent from a Ticket get saved in Activity History, I need a way to save and relate incomming emails (responses) to the Tickets as well.

 

Thank you so much for any help you can provide.

  • December 10, 2013
  • Like
  • 0
Can anyone help with Code Coverage error. Tried to update a Class (that's already in production) to include one extra field (picklist - Status__c). Test passed, but getting 0% Code Coverage when deploying to production.

Class:
public class MultiAddUSUWHold {
    private ApexPages.StandardController std;
     
    // the associated USUWHs
   public List<US_UW_Hold__c> USUWH;
      
    // the chosen USUWH id - used when deleting a USUWH
    public Id chosenUSUWHId {get; set;}
     
    public MultiAddUSUWHold(ApexPages.StandardController stdCtrl)
    {
     std=stdCtrl;
    }
     
    public ISOOffice__Merchant_Application__c getApplication_Package()
    {
     return (ISOOffice__Merchant_Application__c) std.getRecord();
    }
 
    private boolean updateUSUWHs()
    {
        boolean result=true;
        if (null!=USUWH)
           {
           List<US_UW_Hold__c> updConts=new List<US_UW_Hold__c>();
              try
              {
               update USUWH;
              }
              catch (Exception e)
              {
                 String msg=e.getMessage();
                 integer pos;
                  
                 // if its field validation, this will be added to the messages by default
                 if (-1==(pos=msg.indexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION, ')))
                 {
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, msg));
                 }
                  
                 result=false;
              }
           }
            
           return result;
    }
     
    public PageReference saveAndExit()
    {
     boolean result=true;
    result=updateUSUWHs();
      
     if (result)
     {
        // call standard controller save
        return std.save();
     }
     else
     {
      return null;
     }
    }
     
    public PageReference save()
    {
     Boolean result=true;
     PageReference pr=Page.USUWHolds;
     if (null!=getApplication_Package().id)
     {
      result=updateUSUWHs();
     }
     else
     {
      pr.setRedirect(true);
     }
      
     if (result)
     {
        // call standard controller save, but don't capture the return value which will redirect to view page
        std.save();
           ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Changes saved'));
     }
        pr.getParameters().put('id', getApplication_Package().id);
      
     return pr;
    }
 
    public void newUSUWH()
    {
       if (updateUSUWHs())
       {
          US_UW_Hold__c cont=new US_UW_Hold__c(Stip__c='', Application_Package__c=getApplication_Package().id);
          insert cont;
         
          // null the USUWHs list so that it is rebuilt
          USUWH=null;
       }
    }
     
    public void deleteUSUWH()
    {
       if (updateUSUWHs())
       {
          if (null!=chosenUSUWHId)
          {
             US_UW_Hold__c cont=new US_UW_Hold__c(Id=chosenUSUWHId);
              delete cont;
        
           // null the USUWHs list so that it is rebuilt
              USUWH=null;
              chosenUSUWHId=null;
          }
       }
    }
     
   public List<US_UW_Hold__c> getUSUWHs()
    {
       if ( (null!=getApplication_Package().id) && (USUWH == null) )
       {
           USUWH=[SELECT Id, Name, Stip__c, Received__c, Status__c, CreatedDate, Application_Package__r.Id
                         FROM US_UW_Hold__c 
                         WHERE Application_Package__r.Id = : getApplication_Package().ID
                         ORDER BY CreatedDate];
       }
                           
       return USUWH;
    }
}

Test:
@isTest(SeeAllData=true)
private class USUWHoldTest 
{
    public static testMethod void MultiAddUSUWHold()
    {
        ISOOffice__Merchant_Application__c App = new ISOOffice__Merchant_Application__c();
        App.Name =  'Test for US UW Holds';
        insert App;
        
        
        US_UW_Hold__c U = new US_UW_Hold__c();
        U.Stip__c = 'CRM Testing Stip';
        U.Received__c = true;
        U.Status__c = 'Received';
        U.Application_Package__c = App.Id;
        insert U;
                        
    }
}

Tried to take off SeeAllData on test class, same results.
Anyone have idea on how to resolve this? Any help will be much appreciated :)​
  • September 28, 2017
  • Like
  • 0
I uploaded a CSV file via the Leads Obeject. I got a notification/email that it was successful (no errors), all fields mapped correctly. But when I click on leads, nothing is listed there. 

The uploaded data isn't listed anywhere, its like it disappeared. I did this several times with the same result. Where did my data go?
I am attempting to create a new record on a custom object called Notes__c when an Activity record is created via Email to Salesforce. I have posted the process builder I am using. This process works when editing an Activity but not on record creation. Any ideas? Thanks!

User-added image

User-added image
Not a developer, but somehow managed to write a working trigger in sandbox. Trying to deploy to production, says no code coverage. Can someone please help. What do I need to do to successfuly deploy to prodution. 
Trigger:
trigger updateRelatedLead on Task (after insert,after update) {

 List<Id> LeadIds = new List<Id>();
 List<Lead> LeadList = new List<Lead>();

  for(Task t :trigger.new)
    {
	if(t.whoId!=null)
	{
        Schema.SObjectType tType= t.whoId.getSObjectType();
        if(tType == Lead.Schema.SObjectType)
        {
            LeadIds.add(t.WhoId);
        }
    }
	}
	//Querying the related Lead based on whoId on Task
	Map<Id,Lead> LeadMap =  new Map<Id,Lead>([select id,Latest_Follow_Up__c,Task_Subject__c,Task_Comment__c from Lead where id in:LeadIds]);
	
	for(Task t :Trigger.new)

		for(Lead l : LeadMap.Values())
		{
			l.Latest_Follow_Up__c = t.Due_Date_Time__c;
            l.Task_Subject__c = t.Subject;
            l.Task_Comment__c = t.ISOOffice__Comment__c;
			LeadList.add(l);
		}
	// updating the Lead
    if(LeadList.isEmpty() == false) update LeadList;
	}

 
  • January 26, 2016
  • Like
  • 0
Text_ID__c - text field with id of an Opportunity
A_Opportunity__c - lookup field to Opportunity

Both fields are in standard Account object. How can I populate the lookup field with the id in the text field? Will not work with workflow or process builder, guess I need Apex trigger (with which I have little experience). Can anyone provide code for this to at least put me on the right track? Would greatly appreciate it :)
  • October 28, 2015
  • Like
  • 0

Hello all,

 

Is it possible to setup inbound emails (using Email Services) to save to a new record in a custom object or Activity History and populate a lookup field in that object with a text string in that email?

 

Purpose:

We have a custom object Tickets__c that we send out emails from. The emails sent from a Ticket get saved in Activity History, I need a way to save and relate incomming emails (responses) to the Tickets as well.

 

Thank you so much for any help you can provide.

  • December 10, 2013
  • Like
  • 0

Hello Gurus,

 

I hope you are well.

 

I got a request to attach inbound emails to certain SF records if the email has been sent from SF. Similiar to the email2salesforce functionality but for custom objects.

 

What I am trying to achieve is that I want to look for the record ID in the textbody of the email. The user sends out an email using a template containing the record ID and if someone respondes (which will be sent to a routing address)  the class should look for the record ID and attach it appropriately. I hope that made sense ?!

 

What I found is the following and it does work fine for contacts:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_inbound_using.htm

 

I modified the following part to:

-------------------------------------

try {
      Contact vCustom = [SELECT Id, Name, Email
        FROM CustomObject__c
        WHERE Id = :email.TextBody
        LIMIT 1];
      
      // Add a new Task to the contact record we just found above.
      newTask.add(new Task(Description =  myPlainText,
           Priority = 'Normal',
           Status = 'Inbound Email',
           Subject = email.subject,
           IsReminderSet = true,
           ReminderDateTime = System.now()+1,
           WhatId =  vCustom.Id));
      insert newTask;    
-----------------------------------     

 

However, the error I am getting is "Variable does not exist: TextBody". According to the WSDL the field does exist though.

 

Can you please let me know what I do wrong? If you have an easier solution on how to attach incoming emails (to custom objects) , then please let me know!

 

Any questions please let me know!

 

Thanks in advance and have a great day,

Christian

 

I am trying to do more than one substitution in a field update formula and am having difficulty getting it correct.   This is what I have:

 

OR(Contains(Name ,'Duplicate -'), SUBSTITUTE(Name,"Duplicate -"),

     (Contains(Name ,' - Duplicate'), SUBSTITUTE(Name," - Duplicate"),"")))

 

All help is greatly appreciated.

 

Thanks