• Brian Ford
  • NEWBIE
  • 155 Points
  • Member since 2014


  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 28
    Replies
Hi All,
      I have one object which contains two field,i.e. Contry_Code__c & VAT_Rate__c which contains data like
Country Code           VAT Rate
USD                             0.20
IND                              0.19
EURO                           0.15

and i make this two fields on standard object.so how can fetch the VAT Rate  while i select Contry code(It may be Runtime or While Saving Data)
So please help me to solve this assignment.
Regards,
Sam.
If a user with the Sales Member profile saves an opportunity, they should get an error message if they don't enter text in the field Execuitve Summary.

I have this validation rule but it does not work after I log in as the user with this profile.

AND( 
$Profile.Name <> "Sales Member", 
( Executive_Summary__c = ""), 
ISBLANK(Executive_Summary__c) 
)
Hi all ,

User is getting below error next to convert field when converting lead to an account . Not sure which installed package is responsible for this.

Error: System.DmlException: Update failed. First exception on row 0 with id 00QE000000S7ufSMAR; first error: PACKAGE_LICENSE_REQUIRED, License Required: [] (System Code)

Thanks.
  • November 03, 2014
  • Like
  • 0

{!requireScript("/soap/ajax/24.0/connection.js")} var lead = new sforce.SObject("Lead"); lead.Id = "{!Lead.Id}"; lead.Status = "Left VM - Email"; result = sforce.connection.update([lead]); if (result[0].getBoolean("success")) { window.parent.location.href = "/00T/e?followup=1&title=Call$retURL=%2F{!Lead.Id}&who_id= {!Lead.Id}&tsk5=Left+Voicemail&tsk6=Left+a+voicemail+for+{!Lead.Name}&tsk5_fu=FU+VM+w+ {!Lead.Name}+from+{!Lead.Company}&tsk4_fu={!TODAY()+2}";} else { alert("failed to update lead " + result[0]); }

I have the above custom button for leads. It allows reps to click the button, change the status, and create pre-populated tasks.
 

My question is, after save, is clicked on the task, it redirects to the user's home page. How can I make it redirect back to the lead?

I have a before update trigger on the opportunity. I would like to count the number of contact roles on each opportunity in the trigger as well as indicate on the opportunity if at least one of the contact roles is flagged as a primary contact.

My original solution used a SOQL for loop inside a for loop and was running through my governor limits:
trigger ContactRole on Opportunity (before update) {

for (Opportunity o : trigger.new) {
        Integer count = 0;
        Boolean hasPrimary = FALSE;
        for (OpportunityContactRole ocr : [SELECT Id, isPrimary 
                                           FROM OpportunityContactRole 
                                           WHERE OpportunityId =:o.Id]) {
            count++;
            if (ocr.isPrimary)
                hasPrimary = TRUE;
    	}
		
        o.Number_of_Contact_Roles__c = count;
        o.Has_Primary_Contact__c = hasPrimary; 
    }
}

So I've created this work around. The problem is that the last 2 lines that should update 2 fields on the opportunity aren't updating the opportunity. In my debug log it shows that the fields are being updated but those changes aren't being written to the database. I'm sure there's a simple solution here that I'm not seeing. Thanks for your help.
for (Opportunity o : [SELECT Id, Has_Primary_Contact__c, Number_of_Contact_Roles__c, 
    					  (SELECT Id, isPrimary FROM OpportunityContactRoles)
    					  FROM Opportunity WHERE Id IN :trigger.newMap.keyset()]) {
    	Integer count = 0;
		Boolean hasPrimary = False;
        for (OpportunityContactRole ocr : o.OpportunityContactRoles) {
        	count++;
            if (ocr.isPrimary)
                hasPrimary = TRUE;
        }
        
        o.Number_of_Contact_Roles__c = count;
        o.Has_Primary_Contact__c = hasPrimary;
		System.debug('opportunity: ' + o);
	}

 
I deployed a class with 98% coverage and 10 minutes later I deployed another class with 89% coverage but on the 2nd deployment I received the following error:

Your organization's code coverage is 0%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.

Below the error message is a list of all 64 triggers we have in production. I've gone through and spot checked a few of these triggers and they do have coverage. Our system-wide coverage is 71% but my current deployment should raise that number to 75%. I haven't seen this error before, so any suggestions would help.
I have a trigger on the Opportunity that creates a new Case when a custom opportunity field is marked True. At the bottom, I grab associated custom objects (Software_Key__c) from the opportunity and relate them to the new case.

When I test the trigger, line 59 is returning too many SOQL queries. No idea why because it isn't in a for loop. Anyone see what I'm missing?


Trigger: 
trigger CreateCase on Opportunity (after update) {

    List<Opportunity> newOpps = Trigger.new;
    Map<Id, Opportunity> oldOpps = Trigger.oldMap;
    
    List<Case> caseList = new List<Case>();
   
    Map<Id, Id> ocrMap = new Map<Id, Id>();
    List<OpportunityContactRole> ocrList = [SELECT Id, ContactId, OpportunityId
                                            FROM OpportunityContactRole
                                            WHERE OpportunityId IN :newOpps AND IsPrimary = true];
    for (OpportunityContactRole ocr : ocrList)
    {
    	ocrMap.put((Id) ocr.OpportunityId, (Id) ocr.ContactId);    
    }
    
	for (Opportunity opp : newOpps)
	{
		Opportunity beforeUpdate = oldOpps.get(opp.Id);

	   if (!beforeUpdate.Health_Check_Trigger__c && opp.Health_Check_Trigger__c && opp.New_Renew__c == 'New')
           {
		Case thisCase = new Case();
		thisCase.AccountId = opp.AccountId;
		thisCase.Subject = '14-Day Health Check';
            	thisCase.Health_Check__c = true;
            	thisCase.OpportunityId__c = opp.Id;
            	thisCase.OwnerId = '00Ga00000045f3pEAA';
            	thisCase.RecordTypeId = '012a0000001NcLLAA0';
            
		try
	        {
	            thisCase.ContactId = ocrMap.get(opp.Id);
	        }
	        catch(Exception e){}
            
	        caseList.add(thisCase);
             }
    }

    if (!caseList.isEmpty())
    {
     	try
        {
        	insert caseList;
        }
        catch (Exception e){}   
    }

    Map<Id, Id> caseMap = new Map<Id, Id>();
    for (Case c : caseList)
    {
        caseMap.put((Id) c.OpportunityId__c, (Id) c.Id);
    }
 
    List<Software_Key__c> skList = [SELECT Id, CaseId__c, Opportunity__c 
                                    FROM Software_Key__c 
                                    WHERE Opportunity__c IN :caseMap.keySet()];

    List<Software_Key__c> skToUpdate = new List<Software_Key__c>();
    for (Software_Key__c sk : skList)
    {
        sk.caseId__c = caseMap.get(sk.Opportunity__c);
        skToUpdate.add(sk);
    }
    try
    {
        update skToUpdate;
    }
    catch (Exception e){}


}


I have a trigger that creates a case for all new business opportunities in a closed stage with a closed date of 14 days from the current day. The trigger works as expected in my sandbox and I have 90% coverage with my test class.

In production the trigger isn't being invoked. I have a system.debug on line 10 that isn't logging. Any ideas what's causing the different behavior between my sandbox and production environments?


Trigger

trigger createCaseFollowup on Opportunity (before update) {

    Opportunity[] opps = Trigger.new;
    List<Case> caseList = new List<Case>();

    for(Opportunity op : opps)
    {
        Opportunity oldOpp = Trigger.oldMap.get(op.Id);

        System.debug('old: ' + oldOpp.Closed_14_Days__c + ' new: ' + op.Closed_14_Days__c);

        //We only want the Opportunities that have the Closed_14_Days__c set to "true" and it being a New Business Opp
        if (op.Closed_14_Days__c && op.New_Renew__c == 'New' && !OldOpp.Closed_14_Days__c)
        {
            //Creating a blank case for assignment
            Case thisCase = new Case();
            //Standardizing that it is a health check
            thisCase.health_check__c = true;
            thisCase.AccountId = op.AccountId;
            thisCase.Subject = '14-Day Health Check';
            thisCase.OwnerId = '00GM0000000zzBx';
            //This SOQL query is used to determine the Contact that was the primary Contact for this Op. In a Try-Catch due to the fact some Ops may not have primary contacts
            try
            {
                OpportunityContactRole ocr = [SELECT Id, ContactId 
                                              FROM OpportunityContactRole 
                                              WHERE OpportunityId = :op.Id AND IsPrimary = true];
                thisCase.ContactId = ocr.ContactId;
            }
            catch(Exception e){}

            try
            {
            RecordType thisRecord = [SELECT Id FROM RecordType WHERE Name='Client Health Check'][0];
            thisCase.RecordTypeId = thisRecord.Id;
            }
            catch(Exception e){}

            //Adding this newly created case to the previously instantiated list
            caseList.Add(thisCase);
        }
        else {}
    }

    //Check to see if a Case was generated. If not, don't worry about it.
    if(caseList.size() > 0)
    {
       
        try
        {
        insert caseList;
        }
        catch (Exception e)
        {
        }
    }
}


I have a trigger on the opportunity that requires at least 3 contact roles to be associated with any opportunity moving to a closed stage. I've created a test class for the trigger but it's not covering the try {} catch {} statements in my class.

The try{} statement should fail and the catch (exception) should be run. Need help troubleshooting.

Trigger:
trigger RequireContactRoles on Opportunity (before insert, before update) {
    
    List<Opportunity> oppsToProcess = new List<Opportunity>();

    // figure out which opportunities have transitioned to meet criteria
    for (Opportunity opp : trigger.new) {
       // check if transitioned to closed/won, otherwise ignore
       if ( (opp.StageName == '5- Closed' || opp.StageName == '6- Win') && ( trigger.oldMap.get(opp.id).StageName != '6- Win' || trigger.oldMap.get(opp.id).StageName != '5- Closed') && (opp.Override_Contact_Req__c = FALSE) ) {
          oppsToProcess.add(opp);
       }
    }

    Map<Id, Integer> ocrCountByOppId = new Map<Id, Integer>();
    
    List<AggregateResult> aggs = [SELECT OpportunityId oppId, count(id) idCount FROM OpportunityContactRole GROUP BY OpportunityId];

    for (AggregateResult ar : aggs) {
        ocrCountByOppId.put((Id) ar.get('oppId'), (Integer) ar.get('idCount'));
    }

    for (Opportunity opp : oppsToProcess) {
       Integer ocrCount = ocrCountByOppId.get(opp.id);
       if (ocrCount == null || ocrCount < 3) {
           opp.addError(' You need at least 3 contact roles to close the opportunity');
        }
    }
}

Test Class:
@isTest(SeeAllData=true)
public class RequireContactRolesTEST {
    
    static testMethod void testContactRole() {

        //create an account
        Account acc = new Account();
        acc.Name = 'Acc-ContactRoles';
        acc.BillingCountry = 'United States';
        insert acc;
		
        //create 2 contacts
        List<Contact> cons = new List<Contact>();
        
        Contact con1 = new Contact();
        con1.FirstName = 'ContactRoles1';
        con1.LastName = 'Surname1';
        con1.AccountId = acc.Id;
        cons.add(con1);
        
        Contact con2 = new Contact();
        con2.FirstName = 'ContactRoles2';
        con2.LastName = 'Surname2';
        con2.AccountId = acc.Id;
        cons.add(con2);
        insert cons;
        
        //create product
		Product2 prod = new Product2();
        prod.Name = 'contact role prod';
        prod.isActive = true;
        insert prod;
        
        //create pricebookentry
        List<Pricebook2> pb = [SELECT Id, Name, IsStandard, IsActive FROM Pricebook2 WHERE IsStandard = true LIMIT 1];
            for (Pricebook2 pricebook : pb) {
                if (!pricebook.isActive) {
                    pricebook.isActive = true;
                }
            }
        
        PricebookEntry pbe = new PricebookEntry();
        pbe.Pricebook2Id = pb[0].id;
        pbe.Product2Id = prod.id;
        pbe.UnitPrice = 400;
        pbe.UseStandardPrice = false;
        pbe.IsActive = true;
        insert pbe;
            
        //create campaign for required opp field
        Campaign cam = new Campaign();
        cam.Name = 'cam - contact role test';
        insert cam;

        //create an opportunity
        Opportunity opp = new Opportunity();
        opp.Name = 'Opp-ContactRoles';
        opp.AccountId = acc.Id;
        opp.StageName = 'S- Suspect';
        opp.Amount = 10000;
        opp.New_Renew__c = 'New';
        opp.Campaign_Source__c = cam.Id;
        opp.CloseDate = System.Today();
        insert opp;
        
        OpportunityLineItem oli = new OpportunityLineItem();
        oli.OpportunityId = opp.id;
        oli.PricebookEntryId = pbe.id;
        oli.Quantity = 1;
        oli.UnitPrice = 250;
        insert oli;
        
        //add 2 contact roles and make 1 the primary
        List<OpportunityContactRole> conRoles = new List<OpportunityContactRole>();
        
        OpportunityContactRole ocr1 = new OpportunityContactRole();
        ocr1.OpportunityId = opp.Id;
        ocr1.ContactId = con1.Id;
        ocr1.Role = 'Buyer';
        ocr1.IsPrimary = TRUE;
        conRoles.add(ocr1);

        OpportunityContactRole ocr2 = new OpportunityContactRole();
        ocr2.OpportunityId = opp.Id;
        ocr2.ContactId = con2.Id;
        ocr2.Role = 'Tester';
        ocr2.IsPrimary = FALSE;
        conRoles.add(ocr2);
        insert conRoles;        
           
        try {
        	Opportunity testOpp = [SELECT Id, Name, Amount, Number_of_Contact_Roles__c FROM Opportunity WHERE Id = :opp.Id];
            testOpp.Override_Contact_Req__c = false;
            testOpp.StageName = '5- Closed';
            System.debug(testOpp);
        	update testOpp;
        } catch (Exception e) {
            System.debug('I\'m in the ERROR message!');
            System.assert(e.getMessage().contains('contact roles'));
        }
        
        pb[0].isActive = false;
    }
}



I deployed a class with 98% coverage and 10 minutes later I deployed another class with 89% coverage but on the 2nd deployment I received the following error:

Your organization's code coverage is 0%. You need at least 75% coverage to complete this deployment. Also, the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.

Below the error message is a list of all 64 triggers we have in production. I've gone through and spot checked a few of these triggers and they do have coverage. Our system-wide coverage is 71% but my current deployment should raise that number to 75%. I haven't seen this error before, so any suggestions would help.
I created a trigger, and it works great in Sandbox, but when I launched it to production I receieved the following error:

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger autostaff caused an unexpected exception, contact your administrator: autostaff: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Staff__c, original object: User: []: Trigger.autostaff: line 19, column 1 

My trigger is written as follows:If creates a record on the staff object when a user is created 

trigger autostaff on User (after insert) {

List <Staff__c> newstaff = new list <Staff__c> ();

for (User U : Trigger.new){

Staff__c Staff = new Staff__c();

Staff.Employee__c = U.ID;



Staff.Name      = U.Full_Name__c;

newstaff.add(Staff);

}

insert newStaff;

}

From what I have read I need a to add System.runAs as part of my code, but I am not sure how that should be writttten...

Any help is appreaciated.... Please and thank you :) 

 
i have two object  child(class) and parent(student) 
 
student         class
----------------------------
name           name
address        student(lookup)
rollno          rollno
------------------------------
in above to obj if student name and class name will match  then it copy rollno from class and put into student 
please tell me how to get this 
thanks,
devendra
Hi,

I want to see Lead/Contact details along with the campaign member record, as well as the activityhistory. 

an anyone please send me code? or Any help Link..

Thanks
Hello. Is it possible (and how) to display (render) a VF page on another VF page?

Example:
<apex:page>   

<apex:pageblock>
</apex:pageblock>


Render Visualforce here


<apex:pageblock>
</apex:pageblock>

</apex:page>

 
How do i increase my code to readability to the viewrs , to get repsonse. 
in a proper format (line numbers,...etc)
Hi All,

The below mentioned fields are to be created in PROJECT(Custom Object)
     
    OBJECT                             DATA TYPE                                             VALUE                                            
1. Total Certified                        Number                       Equal to number of WON Opportunities associated with this project
2.Total Leads Generated            Look up (Number)        Equal to number of Leads. Can be calculated by adding up all the leads generated by the                                                                                 campaigns under this project.
3.Total Actual Balance                   Currency (Formula)      Total Actual Balance equals budget minus expenses for all completed Campaigns
4.Total Projected Closing Balance / Currency (Formula)  Total Projected Closing Balance equals Total Actual Balance minus all expenses for                                                                                         ongoing or future Campaigns
5.Total Delta                                Currency (Formula)   Total Delta is equal to Total Projected Closing Balance minus budget. (Total Delta can be                                                                                   a  positive or negative number)
6.Total Allocated Resources         Number                     Equal to the total number of Users who are owners of a campaign or a campaign task                                                                                       under this project.

Can anyone please help me with this.

Thanks,
Chandu



 
How to set values from database on to Visualforce page? Can some one guide
Hi All,
      I have one object which contains two field,i.e. Contry_Code__c & VAT_Rate__c which contains data like
Country Code           VAT Rate
USD                             0.20
IND                              0.19
EURO                           0.15

and i make this two fields on standard object.so how can fetch the VAT Rate  while i select Contry code(It may be Runtime or While Saving Data)
So please help me to solve this assignment.
Regards,
Sam.
Hi all, I'm new to SFDC. I am currently working on a few record types in Campaign object, and I do know we can go to Setup to see which fields are the required fields for a particular record type. However, it is quite time consuming to see one field by one field, and one record type by one record type. Is there anyone could advise if there is a simpler / quicker way to retrieve / consolidate all required and optional fields for each record type in Campaign object? Thank you. 
  • November 04, 2014
  • Like
  • 0
If a user with the Sales Member profile saves an opportunity, they should get an error message if they don't enter text in the field Execuitve Summary.

I have this validation rule but it does not work after I log in as the user with this profile.

AND( 
$Profile.Name <> "Sales Member", 
( Executive_Summary__c = ""), 
ISBLANK(Executive_Summary__c) 
)
I have a trigger with insert fee(after insert) to application. The trigger will implement adding each fee amount and then add to each application.
Like fee1: amount $400 add to Application1
       fee2: amount $400 add to Application2
       ......
       fee500: amount $400  add to Application500

I use data loader with input csv file which contains 500 fees and lookup to those application ids. (500 application ids)
Set batch size to 200.

The expected result is for each application amount should be $400. However,
the actual result is  $80,000 for each application. (batch size 20 * $400 = 80,000)

If setting the batch size is 20, the actual result is $8,000 for each application. (batch size 20 * $400 = 8,000)

Does anyone tell me how to solve this problem?








The expected result in 
This formula works for the USA states.  But for Netherlands, it shows up as null.

IF(OR(ISBLANK(State),ISBLANK(Country)), "", 
IF(CONTAINS("Alaska:Washington:California:Oregon:Hawaii:Nevada", State ), "US - WEST", 
IF(CONTAINS("Netherlands:Norway", Country ), 
"EUR",
"")))


The IF(OR( should look at IF statement as separate?
How can we change the background of the VF pages with an image? Is there any configuration or simple piece of code that can achieve this?
Hi all ,

User is getting below error next to convert field when converting lead to an account . Not sure which installed package is responsible for this.

Error: System.DmlException: Update failed. First exception on row 0 with id 00QE000000S7ufSMAR; first error: PACKAGE_LICENSE_REQUIRED, License Required: [] (System Code)

Thanks.
  • November 03, 2014
  • Like
  • 0
Hi,
I have a following code on entitlement process and want to exeute if only if case is new or case field priority is changed, how do i modify it?

Thanks


CODE:

global class myMilestoneTimeCalculator implements Support.MilestoneTriggerTimeCalculator {   
     global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId){
        Case c = [SELECT Priority, Priority_On_Complete__c  FROM Case WHERE Id=:caseId limit 1];
              
        if (c.Priority_On_Complete__c == null)  {
          if (c.Priority != null && c.Priority.equals('P1'))
              return 3;
          else 
               if (c.Priority != null && c.Priority.equals('P2')) 
            return 6;
       else 
        if (c.Priority != null && c.Priority.equals('P3')) 
            return 9;
         else return 0;
        }
        else  {
            if (c.Priority_On_Complete__c.equals('P1'))
              return 3;
         else 
        if (c.Priority_On_Complete__c.equals('P2')) 
            return 6;
        else 
        if (c.Priority_On_Complete__c.equals('P3')) 
            return 9;
        else return 0;
            
        }
                        
     }
}
hi all,

1.After a button click on VF,a standard create page opens up.
2.After the record is save,i want the user to redirect back to the VF page it had come from

How do i do that?

Any help is appreciated
Thanks