• Jeremy.Nottingh
  • SMARTIE
  • 800 Points
  • Member since 2008

  • Chatter
    Feed
  • 30
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 152
    Replies

I have a fairly simple selectoption that I use on a VF page. How do I create a unit test for it:

 

 

   public List<SelectOption> getLocationItems() {

    List<SelectOption> options = new List<SelectOption>();

       options.add(new SelectOption('On-Phone','On-Phone'));

       options.add(new SelectOption('In-Person','In-Person'));

       return options;

   }

 

 

   public List<SelectOption> getAE_LocationItems() {
    List<SelectOption> options = new List<SelectOption>();
       options.add(new SelectOption('On-Phone','On-Phone'));
       options.add(new SelectOption('In-Person','In-Person'));
       return options;
   }public List<SelectOption> getAE_LocationItems() {     List<SelectOption> options = new List<SelectOption>();        options.add(new SelectOption('On-Phone','On-Phone'));        options.add(new SelectOption('In-Person','In-Person'));        return options;    }

 

  • August 09, 2010
  • Like
  • 0

Hello Once Again All,

 

I am really struggling with trying to understand how to get around these exhausting limits!  I have over 16,000 records as of today that are in production/sandbox.  I need to iterate through them all and this number is going to grow.  How can I manipulate the code below to get around the limits.  I just am not getting these work around requirements yet.  I will but I am just a little slow on catch the ball sometimes.  I appreciate your support.

 

This code is all around another post that I submitted on how to produce a report that shows Opportunities that have no related Opportunity Partner Records.  The work around was to add a custom checkbox field on the opportunity object and use apex to check it no parters exist and uncheck it if one or more does exists.  The code below a small portion of this.  If I am this thing working I would like to post the enter class code in here for others because I saw this question by others.

 

opps = [ select id, MissingPartner__c, (select id from OpportunityPartnersFrom) 
                                      from Opportunity ];
        }                        
                                  
        for (Opportunity o : opps) {            
            if ( o.OpportunityPartnersFrom.size() > 0 ) {
                o.MissingPartner__c = false;    //Opportunity has partner record(s)
                
            } else {                                        
                o.MissingPartner__c = true;     //Opportunity is missing partner record(s)            
            }                
        }

 

 

 

Hi,

 

Have a visualforce page rendered as a PDF.

 

I now want to batch produce if possible PDF's.

 

Is this possible?

 

Thanks

 

Ross

Okay folks, I know this is a n00b question but I can't remember if or how to initialize a string with a set of arguments.

 

What I want to do is something like this

 

 

List<String> alphabet = { 'a' , 'b' , 'c' ...  };

 

How can I do this?

 

Hello!

 

We are in the professional services business, and we often work with organizations with multi-level hierarchies (3 to 4 levels is very average). I was wondering if anyone knows how one can create a script to automatically find out the ultimate parent of any account / contact / project, and store the result in a field on every entity.

 

this would allow us to create savvy rollups in our reporting and dashboarding. any help will be much appreciated.

 

thanks,

Pranav

Hi All,

 

I'm wondering if this code should work or am I doing something wrong.  So I only want to display a section header if there is text in the section.

 

 

 

<apex:outputPanel id="output1" rendered="{ISNULL(!Position.Values__c)}"> 

<apex:outputLabel value="Values Statement"></apex:outputLabel></h4></apex:outputPanel> <br/><br/> <apex:outputText value="{!Position.Values__c}" id="thevaluessection"/><br/>

 

 

I have an object, Position, and it has several different field.  This object is used to display info on a webpage so when the salesforce user doesn't fill in the 'Values' field, I don't want that section to appear on the webpage.

 

Thanks in advance.

 

Hi,

 

I have a custom object product_inventory__c which has a lookup field to  product.

 

I have another custom object order_line__c which has a lookup field to  product.

 

The requirement is,every time an order line is created,i need to check in the product inventory if any record exists for that product.

 

If record  in product inventory does not exist ,I need to create a new product_inventory_record for the product.

 

 

To achieve this ,I tried writing a trigger on order_line__c object,that would create a new product_inventory record if it is not present.

 

 

 

But since product inventory and order line do not share a master detail relationship,Iam not sure how this goes.i tried writing the following sample code:

 

trigger inventory on Order_Line__c(after insert) {

 

Order_Line__c ol=trigger.new;

 

for (Order_Line__c neworder: Trigger.New) {


Integer i=[select count() from Product_Inventory__c where Product__c :=ol.Product__c];

if(i=0)
{

Product_Inventory__c.add(new Product_Inventory__c(
product__c=neworder.product));

}

}
}

 

This is erroring out of course because i have not mapped any id's....but iam not sure how to do that since i just want to compare if any record with the product is existing

Please help...

 

 

 

Hello.

 

I've attemped the following logic numerous times (as a trigger, trigger calling apex, batchable, @future) and every attempt I've run into governor limits. I'm not sure how to achieve what I'm looking to do.

 

Basically, I have a custom object called Gift, that contains a lookup to Account. The Account object has a string field called TAGS_Applic_Codes that contains a 5-character unique identifier to a legacy system. In our legacy system, though, it's possible for a single account to have multiple codes (different addresses, for example, will each have their own code, and thus be a separate Account record in Salesforce). As such, the Account object also contains a string field called Related_TAGS_App_Codes that contains a comma delimited listing of all of the TAGS applic codes that should be treated together.

 

The Gift object contains a currency field called Total_Cost, and the Account object contains a field called X2010_Gift_Expenditure_Total. What I'm looking to accomplish is that whenever a gift record is created, I want to calculate the total of all of the gifts for that particular Account AND any related accounts through that additional field, and store them in the X2010_Gift_Expenditure_Total field on the Account object (and related records).

 

Below is a semi-functional Trigger version of my code, so you can see my thought process. In this particular version, I'm getting a "too many query rows" error, but my governor errors have ranged from that, to "too many SOQL queries: 21", to limits on batchables and @future calls.

 

 

 

trigger trigUpdateCompanyGiftTotal on Gift__c (after insert, after update, after delete) {


List<Id> changedAccountIds = new List<Id>();
List<Account> changedAccounts = new List<Account>();
List<Account> allAccounts = new List<Account>();
List<Gift__c> allGifts = new List<Gift__c>();
Map<Id,Account> linkedAccounts = new Map<Id,Account>();

// Store all accounts and gifts to avoid governor limits
for (Account acc: [SELECT id, name FROM account]) {
allAccounts.add(acc);
}
allGifts = [SELECT Id FROM Gift__c];


//Loop on each changed gift entry. For deletes, need trigger.old
if (Trigger.isDelete) {
for(Gift__c g : Trigger.old){
if (g.Company_Firm__c <> Null) {
changedAccountIds.add(g.Company_Firm__c);
}
}
} else {
for(Gift__c g : Trigger.new){
changedAccountIds.add(g.Company_Firm__c);
}
}


// In triggers, lookup fields do not contain references to the entire object... they only contain the Id.
// So, need to get the actual changed Account objects from the stored IDs.
for (Id changedId: changedAccountIds) {
changedAccounts = [SELECT Id,Related_TAGS_App_Codes__c FROM Account WHERE Id=:changedId];
}

for (Account a: changedAccounts) {
//Determine if any related accounts by a nested loop over the full account list
if (a.Related_TAGS_App_Codes__c <> null && a.Related_TAGS_App_Codes__c.length() > 0) {
for (Account accLinkCheck: allAccounts) {
if (a.Related_TAGS_App_Codes__c.contains(accLinkCheck.Tags_Applic__c)) {
linkedAccounts.put(a.Id,accLinkCheck);
}
}
} else {
linkedAccounts.put(a.Id,a);
}
}


// Loop on all gifts, adding the totals and storing it back in the account and any related accounts
Decimal totalGift2009 = 0;
Decimal totalGift2010 = 0;

for (Gift__c g: allGifts) {
if (linkedAccounts.containsKey(g.Company_Firm__c)) {
if (g.Date__c.year() == 2009) {
totalGift2009 = totalGift2009 + g.Total_Cost__c;
}
if (g.Date__c.year() == 2010) {
totalGift2010 = totalGift2010 + g.Total_Cost__c;
}
}
}


// Update the total for each account
for (Account acc: linkedAccounts.values()) {
acc.X2009_Gift_Expenditure_Total__c = totalGift2009;
acc.X2010_Gift_Expenditure_Total__c = totalGift2010;
update acc;
}

}

 

My last resort would be to eliminate the trigger portion of this and just have a batch process that runs the update at set intervals, but I'd really prefer to avoid that and have it update when a Gift record is added/changed. I just don't see a way to do it without hitting some sort of governor limit.

 

Any advice is greatly appreciated. Thank you.

 

 

-Greg

Hi

 

I have written an email to apex code , where a contact is created  as soon as an email is recieved to the email service depending on the email content.

 

Everything works fine , since all the value are string ...so it creates a contact.

 

The issue I am having is there a Birthdate field which is a date field, how can i pass this date field as a string to the system.

 

I would appreciate your help.

 

thank you

 

  • July 12, 2010
  • Like
  • 0

Good morning, I am hoping someone can set me straight on what I am attempting to do here. 

 

  • I have a custom object Work Order that has a lookup relationship to Opportunity. 
  • There can be many Work Orders related to one opportunity. 
  • On Opportunity, I have a custom field that is populated via a trigger to count all of the Work Orders associated

I have a second trigger that is meant to

  • identify those Work Orders that are closed and,
  • if the count of Closed Work Orders = the count of all Work Orders
  • update the Opportunity Stage to Completed

I am getting lost on how to write the logic to compare the COUNT of the closed Work Orders to the value in the Opportunity field.  I'd appreciate any help!!!  Thanks.

 

trigger trigWorkorderCloseOpp on Work_Order__c (after insert, after update) {

    //************************************************
    // Build a LIST of Opportunity ID's that may
    // need closing
    //************************************************

	set <id> oppIDs = new set <id>();
	list <Opportunity> opportunity = [SELECT ID FROM Opportunity WHERE ID in:oppIDs];

	
    if(Trigger.isInsert || Trigger.isUpdate){
        for(Work_Order__c w : trigger.new){
            if(w.Opportunity__c != null && w.stage__c == 'Work Order Closed - Quickbooks')
            {oppIDs.add(w.Opportunity__c);
            } else if (w.Opportunity__c != null && w.stage__c == 'Job Completed')
            {oppIDs.add(w.Opportunity__c);
            
            }

	        }

      // INSERT/UPDATE Trigger

    if(Trigger.isDelete || Trigger.isUpdate){
        for(Work_Order__c w : trigger.old){
           if(w.Opportunity__c != null && w.stage__c == 'Work Order Closed - Quickbooks')
            {oppIDs.add(w.Opportunity__c);
            } else if (w.Opportunity__c != null && w.stage__c == 'Job Completed')
            {oppIDs.add(w.Opportunity__c);
             }
        }
    }

    if(oppIDs .size() > 0) {
    
        Map<ID, Opportunity> oppMap = new Map<ID, Opportunity>([Select id, WO_Count__c, StageName from Opportunity Where Id in :oppIds]);  	
    	
    	Opportunity d = null;
    		
    	for (AggregateResult ar : [SELECT ID, Opportunity__c, COUNT(Id)total FROM Work_Order__c WHERE Opportunity__c in: oppIds GROUP BY Opportunity__c])
    	
    		{
    			String dID = (String)dr.get('Opportunity__c');
    			Integer a = Integer.valueOf(ar.get('total'));
    			if(oppMap.get(dID) == null)
    			 d = new Opportunity(ID=string.valueOf(ar.get('Opportunity__c')));
    			
    			else
    			if(oppMap.containskey(dID)&& a.equals(Opportunity.WO_Count__c))
        		d = oppMap.get(dID);
    			
    			
    		}

    		d = opps.get(dID);
    		d.StageName = 'Job Completed';
    		
    		update opps.values();
    		
    }
    }
}		

 

 

 

I am trying to round a percentage to 2 decimal places using the ROUND function, however the result returned is to the nearest whole number.

 

Any help would be most appreciated.

Does anyone know how? there is no standard controller for Tasks...

Before I begin, let me say that we're trying to avoid using JavaScript at all costs. We'd really like JavaScript to just be a last resort.

 

So, I have the following bit of code within a wrapper class in VisualForce:

 

                        <apex:selectList size="1">
                               <apex:selectOptions value="{!cond.PicklistValues}"/>
                        </apex:selectList>

 

PicklistValues is a function that returns a custom select list ( SelectOption[] ) for each object. The select list is different depending on one of the settings of the object.

 

Now, here's the question... How do I read off what the Picklist is set to in Apex? when the user hits save, I want to map their Picklist selection to an actual attribute.

 

Thanks for all the help!

I am showing two triggers below; Trigger 2 at the bottom of the page works, except it performs the operation on all records, so I am trying in Trigger 1 to only access those records that have changed.  I have a lookup relationship between two custom objects Master_Lookup (parent) and Child_Detail (child), where a Master_Lookup could have many Child_Details, but a Child_Detail has only one Master_Lookup.  The first for loop using Trigger.new fills the set with a null value for the ID of the Master_Lookup instead of a valid ID.  I know there is a Master_Lookup associated with this Child_Detail so I can't understand why it has a null ID.  Can someone help me out.  Thanks.

 

Trigger 1:

trigger updateOnQtyCountTotal on Child_Detail__c (after insert, after update) {
    // Form a set of affected MasterLookupRecords to avoid duplicates
    Set<id> masterLookupIds = new Set<id>();
    for (Child_Detail__c myChildDetailRecord : Trigger.new){
        masterLookupIds.add(myChildDetailRecord.Master_Lookup__r.Id);
    }
    for (id value : masterLookupIds) {
        System.debug('Set = ' + value);
    }
    String queryString = 'SELECT Id, Total_Quantity__c, Total_Price__c, ' +
                         'Total_Count__c, (SELECT Quantity__c, Total_Price__c ' +
                         'from Child_Detail__r) from Master_Lookup__c where Id in :masterLookupIds';
    Master_Lookup__c[] myMasterLookup = Database.query(queryString);
    for (Master_Lookup__c masterLookupRecord : myMasterLookup) {
        sObject[] childRecordsFromMaster = masterLookupRecord.getSObjects('Child_Detail__r');
        Decimal runningQuantityTotal = 0;
        Decimal runningPriceTotal = 0;
        Decimal runningItemsTotal = 0;
        // Prevent a null relationship from being accessed
        if (childRecordsFromMaster != null) {
            for (sObject childRecord : childRecordsFromMaster){
                runningQuantityTotal += (Decimal)childRecord.get('Quantity__c');
                runningPriceTotal += (Decimal)childRecord.get('Total_Price__c');
                runningItemsTotal++;
            }
        }
        masterLookupRecord.Total_Quantity__c = runningQuantityTotal;
        masterLookupRecord.Total_Price__c = runningPriceTotal;
        masterLookupRecord.Total_Count__c = runningItemsTotal;
    }
    upsert myMasterLookup;
}

 

Trigger 2:
/*trigger updateOnQtyCountTotal on Child_Detail__c (after insert, after update) {
    // Use parent-child relationship to find all quantities for each Master_Lookup
    String queryString = 'SELECT Id, Total_Quantity__c, Total_Price__c, ' +
                         'Total_Count__c, (SELECT Quantity__c, Total_Price__c ' +
                         'from Child_Detail__r) from Master_Lookup__c';
    Master_Lookup__c[] myMasterLookup = Database.query(queryString);
    for (Master_Lookup__c masterLookupRecord : myMasterLookup){
        sObject[] childRecordsFromMaster = masterLookupRecord.getSObjects('Child_Detail__r');
        Decimal runningQuantityTotal = 0;
        Decimal runningPriceTotal = 0;
        Decimal runningItemsTotal = 0;
        // Prevent a null relationship from being accessed
        if (childRecordsFromMaster != null) {
            for (sObject childRecord : childRecordsFromMaster){
                runningQuantityTotal += (Decimal)childRecord.get('Quantity__c');
                runningPriceTotal += (Decimal)childRecord.get('Total_Price__c');
                runningItemsTotal++;
            }
        }
        masterLookupRecord.Total_Quantity__c = runningQuantityTotal;
        masterLookupRecord.Total_Price__c = runningPriceTotal;
        masterLookupRecord.Total_Count__c = runningItemsTotal;
    }
    upsert myMasterLookup;
}*/

  • June 26, 2010
  • Like
  • 0

So, I have a Rules object. Within the Rules object is an array of Condition objects. Each Condition Object has an associated Attribute_Definition object.

 

I'm trying to get the name of the Attribute_Definition object associated with each condition object.

 

                Rule_Condition__c[] condList = [select Attribute_Definition__c, Operator__c,
                                            Text_Value__c, Number_Value__c, IndexVar__c  
                                     from Rule_Condition__c where Configuration_Rule__c = :bmRule.Id];
                for (Integer j = 0; j<condList.size(); j++) {
                    if (('' +j).equals(s)) {
                        Attribute_Definition__c attrDef = new Attribute_Definition__c(condList[j].Attribute_Definition__c);
                        return attrDef.Name + ' OPERATOR val '; // RETURN THE ENGLISH
                        //return condList[j].Attribute_Definition__c + ' OPERATOR val '; // RETURN THE ENGLISH
                    }
                }
                
                return '!]error03 - ' + s;

 

 

Based on some brief testing, I know that s and j are firing true. If I remove the .Name tag, it'll pring out a01A0000001aR1vIAE

 

Error is this:

Error: Compile Error: Illegal assignment from Id to SOBJECT:Attribute_Definition__c at line 84 column 26

 

 

Thanks in advance

I'm trying to implement my first trigger.  I have a lookup relationship between MasterLookup and ChildDetail objects.  Here is the trigger:

 

trigger updateOnQtyCountTotal on Master_Lookup__c (before insert, before update) {
    // Use parent-child relationship to find all quantities for each Master_Lookup
    String queryString = 'SELECT Id, Total_Quantity__c, (SELECT Quantity__c from Child_Detail__r) from Master_Lookup__c';
    Master_Lookup__c[] myMasterLookup = Database.query(queryString);
    for (Master_Lookup__c masterLookupRecord : myMasterLookup){
        sObject[] childRecordsFromMaster = masterLookupRecord.getSObjects('Child_Detail__r');
        Decimal runningTotal = 0;
        // Prevent a null relationship from being accessed
        if (childRecordsFromMaster != null) {
            for (sObject childRecord : childRecordsFromMaster){
                runningTotal += (Decimal)childRecord.get('Quantity__c');
            }
        }
        masterLookupRecord.Total_Quantity__c = runningTotal;
    }
}

 

The last line is not updating the Total_Quantity__c field when I view the MasterLookup object after making a change to the object.  It is clearly running the code in the trigger when I view the log, but the field is always blank.  This must be an obvious error, but I can't find it and searching the documentation has not helped.  Thanks.

  • June 25, 2010
  • Like
  • 0

I've written a trigger that is working fine for single record updates and inserts:

 

trigger OpportunityUpdateFromOppProduct on OpportunityLineItem (after insert, after update) {
    	
    	List<OpportunityLineItem> olis = [Select Id, OpportunityId, Service_Code__c, Is_Full_Service__c From OpportunityLineItem Where OpportunityId =: Trigger.new[0].OpportunityId];
    
    	Set<String> serviceCodeNames = new Set<String>();
    	for (OpportunityLineItem oli : olis) {
        	serviceCodeNames.add(oli.Service_Code__c);
    	}
    
    	Map<String, String> scMap = new Map<String, String>();
    
    	for (Service_Code__c sc : [Select Name, Opportunity_Service_Field_Name__c From Service_Code__c Where Name in: serviceCodeNames]) {
        	scMap.put(sc.Name, sc.Opportunity_Service_Field_Name__c);
    	}
    
    	Map<String, OpportunityLineItem> oliMap = new Map<String, OpportunityLineItem>();
    
    	Opportunity tmpOpp = [Select Id, Type From Opportunity Where Id =: Trigger.new[0].OpportunityId];
    
    	Map<Id, Opportunity> oppsToUpdate = new Map<Id, Opportunity>();
    
    	String oppServiceFieldName = null;
    
    	string serviceFieldValue = null;
    	
    	Boolean alreadyExists;
    	
    	Boolean isFull = true;
    	
    	String str;
    
    	if (tmpOpp.Type.contains('Syndicated')) {
    	
    		for (OpportunityLineItem oli : olis) {
    			
    			if (oliMap.containsKey(oli.Service_Code__c)) {
    				alreadyExists = true;
    			}
    			else {
    				alreadyExists = false;
    			}
    			
    			oliMap.put(oli.Service_Code__c, oli);

    			if (alreadyExists) {
    				
    				if (isFull != false) {
        
        				oppServiceFieldName = scMap.get(oli.Service_Code__c);

        				if (oli.Is_Full_Service__c == 'True') {
            				serviceFieldValue = 'Full';
        				}
        				else {
            				serviceFieldValue = 'Partial';
        				}
        				tmpOpp.put(oppServiceFieldName, serviceFieldValue);
    				}
    			}
    			else {
    				
    				str = oliMap.get(oli.Service_Code__c).Is_Full_Service__c;
    				
    				
    				if (str == 'Full') {
    					isFull = true;
    				}
    				else {
    					isFull = false;
    				}

    				oppServiceFieldName = scMap.get(oli.Service_Code__c);

        				if (oli.Is_Full_Service__c == 'True') {
            				serviceFieldValue = 'Full';
        				}
        				else {
            				serviceFieldValue = 'Partial';
        				}
        				tmpOpp.put(oppServiceFieldName, serviceFieldValue);
    				}
    			oppsToUpdate.put(tmpOpp.Id, tmpOpp);
    		}
    	}
    	update oppsToUpdate.values();
}

 I was trying to bulkify the trigger so it would handle bulk updates using data loader.  I modified the trigger to the following:

 

trigger OpportunityUpdateFromOppProduct on OpportunityLineItem (after insert, after update) {
    	
    	Set<Id> opIds = new Set<Id>();
    	for (OpportunityLineItem oli : Trigger.new) {
    		opIds.add(oli.OpportunityId);
    	}
    
    	List<OpportunityLineItem> olis = [Select Id, OpportunityId, Service_Code__c, Is_Full_Service__c From OpportunityLineItem Where OpportunityId in: opIds];
    
    	Set<String> serviceCodeNames = new Set<String>();
    	for (OpportunityLineItem oli : olis) {
        	serviceCodeNames.add(oli.Service_Code__c);
    	}
    
    	Map<String, String> scMap = new Map<String, String>();
    
    	for (Service_Code__c sc : [Select Name, Opportunity_Service_Field_Name__c From Service_Code__c Where Name in: serviceCodeNames]) {
        	scMap.put(sc.Name, sc.Opportunity_Service_Field_Name__c);
    	}
    
    	Map<String, OpportunityLineItem> oliMap = new Map<String, OpportunityLineItem>();
    	
    	Map<Id, Opportunity> mapOpp = new Map<Id, Opportunity>();
	
		for (Opportunity o : [Select Id, Type From Opportunity Where Id in: opIds]) {
			mapOpp.put(o.Id, o);
		}
    
    	Map<Id, Opportunity> oppsToUpdate = new Map<Id, Opportunity>();
    
    	String oppServiceFieldName = null;
    
    	string serviceFieldValue = null;
    	
    	Boolean alreadyExists;
    	
    	Boolean isFull = true;
    	
    	String str;
    	
    	for (Id i : mapOpp.keyset()) {
    
    		if (mapOpp.get(i).Type.contains('Syndicated')) {
    		
    			Opportunity tmpOpp = mapOpp.get(i);
    	
    			for (OpportunityLineItem oli : olis) {
    			
    				if (oliMap.containsKey(oli.Service_Code__c)) {
    					alreadyExists = true;
    				}
    				else {
    					alreadyExists = false;
    				}
    			
    				oliMap.put(oli.Service_Code__c, oli);

    				if (alreadyExists) {
    				
    					if (isFull != false) {
        
        					oppServiceFieldName = scMap.get(oli.Service_Code__c);

        					if (oli.Is_Full_Service__c == 'True') {
            					serviceFieldValue = 'Full';
        					}
        					else {
            					serviceFieldValue = 'Partial';
        					}
        					tmpOpp.put(oppServiceFieldName, serviceFieldValue);
    					}
    				}
    				else {
    				
    						str = oliMap.get(oli.Service_Code__c).Is_Full_Service__c;
    				
    						if (str == 'Full') {
    							isFull = true;
    						}
    						else {
    							isFull = false;
    						}

    						oppServiceFieldName = scMap.get(oli.Service_Code__c);

        					if (oli.Is_Full_Service__c == 'True') {
            					serviceFieldValue = 'Full';
        					}
        					else {
            					serviceFieldValue = 'Partial';
        					}
        					tmpOpp.put(oppServiceFieldName, serviceFieldValue);
    					}
    				oppsToUpdate.put(tmpOpp.Id, tmpOpp);
    			}
    		}
    	}
    	update oppsToUpdate.values();
}

 

It processes correctly for one record, but fails to update correctly for subsequent records.

 

I think the problem is occuring within this section of the code:

 

Set<String> serviceCodeNames = new Set<String>();
    	for (OpportunityLineItem oli : olis) {
        	serviceCodeNames.add(oli.Service_Code__c);
    	}
    
    	Map<String, String> scMap = new Map<String, String>();
    
    	for (Service_Code__c sc : [Select Name, Opportunity_Service_Field_Name__c From Service_Code__c Where Name in: serviceCodeNames]) {
        	scMap.put(sc.Name, sc.Opportunity_Service_Field_Name__c);
    	}

 

 Can anyone help with how I can correctly get this bulkified?

Hello everyone!!

 

In my company, we would like to have a limit close date for our opportunities of three monhs.

 

Is there any way (preferibly without encoding) to restrict the opportunity close date until three months from today?

 

Thanks in advance!!

I am working on a fairly basic Quote template using the new standard Quote object, and all is well until I get tot he <apex:repeat> section where I want to list all the Quote Line Items associated with the Quote.

 

I have this:

 

 

<apex:repeat var="line" value="{!Quote.QuoteLineItem}">

 

 And I am getting this error message:  

 

 

Error: Invalid field QuoteLineItem for SObject Quote

 

I am using the standard Quote controller.  I also get a similar error when I try to use  __r after QuoteLineItem.

 

Can someone please tell me what I am doing wrong here?

 

Thanks

 

 

Hello

 

My organization has a few customized address fields which required me to create workflow/field update checkboxes related to these specific addresses.  I am trying to set up a validation rule that will prevent users from saving a record if more than one "Preferred Address" checkbox is selected.

 

Specifically, the 3 checkbox fields I have created are:

Mother Preferred Address

Father Preferred Address

Guardian Preferred Address

 

I haven't had any luck figuring out the formula that would allow me to set up this validation rule.  Any suggestions?

 

Many thanks! 

I am displaying a datatable for a wrapper class that includes a "Selected" checkbox and a custom object, Oppdoc__c. There is a datetime input box(bound to custom object Query__c to use the date picker gadget), and I want to display the records that have CreatedDate greater than or equal to the datetime input. This works, enter a datetime and hit the Refresh button, and the list updates.

 

I also have a Select All checkbox, and if clicked, it should check or uncheck all the boxes currently in the table. However, if this is checked, it resets the entire table to the default state, ignoring the query field. It seems as though the apex code is losing the value of the Query object when SelectAll is invoked. Here is my code:

 

Controller:

public class OppDocTricks { private static OppDoc__c doc; private static Shipment__c shp; private static String pagebreakstring = 'page-break-after: always;'; private static Integer maxdocs; private static Query__c tempq; //to use for query info / date picker private static boolean IsAllSelected = false; private static list<xdoc> displaylist {get;set;} public static Query__c getQuery() { if (tempq == null){ system.debug('resetting tempq right now'); tempq = new Query__c(); } if (tempq.After_Date__c == null) tempq.After_Date__c = datetime.now().adddays(-90); return tempq; } public static void setQuery(Query__c q) { tempq = q; } public boolean getIsAllSelected() { return IsAllSelected; } public void setIsAllSelected(Boolean AllSelected){IsAllSelected = AllSelected;} public OppDocTricks() { if (ApexPages.currentPage().getParameters().get('id') != null) doc = [select id, name from OppDoc__c where id = :ApexPages.currentPage().getParameters().get('id')]; } public class xdoc { OppDoc__c d; boolean Selected; public xdoc( OppDoc__c oppdoc) { d=oppdoc;} public OppDoc__c getOppDoc() { return d; } public boolean getSelected() { return Selected; } public void setSelected(boolean sb) { Selected = sb; } } public static list<xdoc> getQueryinvs() { map<String, id> rtmap = new map<String, id>(); util.mapRecordTypes(rtmap, 'OppDoc__c'); tempq = getQuery(); system.debug('tempq '+ tempq.After_Date__c); if (displaylist != null){ for (xdoc x : displaylist){ system.debug('xd ' + x.d.CreatedDate); } } if (displaylist == null){ displaylist = new list<xdoc>(); for (OppDoc__c odoc : [select CreatedDate, Status__c, Shipto_Name__c, ShiptoZip__c, ShiptoState__c, ShiptoLine2__c, ShiptoLIne1__c, ShiptoCountry__c, ShiptoCity__c, Shipping_Address__c, Purchase_Total__c, Purchase_Order__c, Name, DueDate__c, Document_Notes__c, Date__c, Current_Due_Total__c, Current_Due_Subtotal__c, BilltoZip__c, BilltoState__c, BilltoName__c, BilltoLine2__c, BilltoLine1__c, BilltoCountry__c, BilltoCity__c, Accounting_Entry_Total__c, opportunity__r.Hope_Order_Number__c, opportunity__r.Opportunity_Number__c, Opportunity__r.Name, (select Name, Type__c, Total_Amount__c, Purchase_Quantity__c, Purchase_Net_Amount__c, Product_Code__c, Entry_Date__c, Description__c, Currently_Due__c From Line_Items__r) from OppDoc__c where recordtypeId = :rtmap.get('Invoice') and CreatedDate >= :tempq.After_Date__c]) { system.debug('newxdoc created ' + odoc.CreatedDate); xdoc newxdoc = new xdoc(odoc); //newxdoc.Selected = true; displaylist.add(newxdoc); } }else{//(must not be null) for (Integer counter = 1; counter == displaylist.size(); counter++){ system.debug('counter ' + counter + ' qinv ' + displaylist[counter].d.CreatedDate); if (displaylist[counter].d.CreatedDate < tempq.After_Date__c){ displaylist.remove(counter); } } } return displaylist; } public static void RefreshQuery() { displaylist = null; system.debug('tempq ' + tempq); } public void SelectAll() { system.debug('selectall anyone? isallselected is ' +IsAllSelected); for (xdoc d : displaylist) { system.debug('d selected before ' + d.Selected); d.SetSelected(IsAllSelected); system.debug('d selected after ' + d.Selected); } } }

 

Visualforce page:

 

<apex:page controller="OppDocTricks" cache="true" title="OppDoc Query page" > <style> .OppDocTable{ font-size: 12px; text-align: right; padding: 20px; } </style> <apex:form > <apex:pageblock title="Query OppDocs"> <apex:outputpanel id="table"> <apex:datatable styleclass="OppDocTable" value="{!Queryinvs}" var="inv"> <apex:column > <apex:facet name="header" > <apex:inputcheckbox value="{!IsAllSelected}" > <apex:actionSupport rerender="table" event="onclick" action="{!SelectAll}" status="redrawStatus"/> </apex:inputcheckbox> </apex:facet> <apex:inputcheckbox value="{!inv.Selected}"/> </apex:column> <apex:column value="{!inv.OppDoc.CreatedDate}"> <apex:facet name="header"> <apex:actionStatus id="redrawStatus" startText=" (refreshing...)" /> </apex:facet> </apex:column> </apex:datatable> Show Invoices created since: <apex:inputfield value="{!Query.After_Date__c}" /> <apex:commandbutton value="Refresh list" action="{!RefreshQuery}" status="redrawStatus"/> </apex:outputpanel> <br/> </apex:pageblock> </apex:form> </apex:page>

 

 

Thanks for your help,

Jeremy Nottingham

I have a fairly simple selectoption that I use on a VF page. How do I create a unit test for it:

 

 

   public List<SelectOption> getLocationItems() {

    List<SelectOption> options = new List<SelectOption>();

       options.add(new SelectOption('On-Phone','On-Phone'));

       options.add(new SelectOption('In-Person','In-Person'));

       return options;

   }

 

 

   public List<SelectOption> getAE_LocationItems() {
    List<SelectOption> options = new List<SelectOption>();
       options.add(new SelectOption('On-Phone','On-Phone'));
       options.add(new SelectOption('In-Person','In-Person'));
       return options;
   }public List<SelectOption> getAE_LocationItems() {     List<SelectOption> options = new List<SelectOption>();        options.add(new SelectOption('On-Phone','On-Phone'));        options.add(new SelectOption('In-Person','In-Person'));        return options;    }

 

  • August 09, 2010
  • Like
  • 0

I don't understand how this limit works. I have three active triggers (all on tasks), all contains some queries.

I'd like to create some new triggers on opportunities and lineItems but no matters how simple my code is, I always get the query limit error.

What could I make wrong? My triggers doesn't come from any other trigger, so the queries cannot sum up

 

thanks for the answers

hi i was just practicing SOQL queries and i wrote a test query in apex explorer

 

 

Select Id, Name, Industry,Company_Relationship__c From Account where Company_Relationship__c='Employee' and Lead_Created_Date__c=System.today()

 

 

and when i tried to execute i am getting an error can anyone tell me where my error is.

 

error: unexpected token 'system.today()'

I have limited (very) programming knowledge and need some help with a trigger so any assistance would be greatly appreciated. 

 

I have 2 custom objects which are part of a managed package(Docusign for salesforce).

How it works is you click "Send" from a Contact and it opens a new window called an envelope [dsfs__DocuSign_Envelope__c] which is a master object with the contact listed as a recipient  [dsfs__DocuSign_Envelope_Recipient__c] which is the child object

 

 

I would like to add an additional standard recipient every time "send" is launched. I did attempt to create a trigger which is listed below but this doesn't work. Please be gentle with your criticism as i'm humiliatated even posting it but here goes;

 

trigger dse on dsfs__DocuSign_Envelope_Recipient__c (after insert) {
    List<dsfs__DocuSign_Envelope_Recipient__c> dser = new List<dsfs__DocuSign_Envelope_Recipient__c>();
    //For each envelope processed by the trigger, add a new  recipient
    for (dsfs__DocuSign_Envelope_Recipient__c newdser: Trigger.New) {
            dser.add(new dsfs__DocuSign_Envelope_Recipient__c(
                        dsfs__DocuSign_Signer_Type__c ='Carbon Copy',
                        dsfs__DSER_ContactID__c = '003Q000000BhWpP'));
        }
}

 

 

 

  • August 04, 2010
  • Like
  • 0

Hello Once Again All,

 

I am really struggling with trying to understand how to get around these exhausting limits!  I have over 16,000 records as of today that are in production/sandbox.  I need to iterate through them all and this number is going to grow.  How can I manipulate the code below to get around the limits.  I just am not getting these work around requirements yet.  I will but I am just a little slow on catch the ball sometimes.  I appreciate your support.

 

This code is all around another post that I submitted on how to produce a report that shows Opportunities that have no related Opportunity Partner Records.  The work around was to add a custom checkbox field on the opportunity object and use apex to check it no parters exist and uncheck it if one or more does exists.  The code below a small portion of this.  If I am this thing working I would like to post the enter class code in here for others because I saw this question by others.

 

opps = [ select id, MissingPartner__c, (select id from OpportunityPartnersFrom) 
                                      from Opportunity ];
        }                        
                                  
        for (Opportunity o : opps) {            
            if ( o.OpportunityPartnersFrom.size() > 0 ) {
                o.MissingPartner__c = false;    //Opportunity has partner record(s)
                
            } else {                                        
                o.MissingPartner__c = true;     //Opportunity is missing partner record(s)            
            }                
        }

 

 

 

 

The hierarchy of objects for this problem is Account - Contract - Invoice - Shipment.  
Contract is detail to master with account,
Invoice is detail to master with contract and lookup with account. and
Shipment is detail to master with invoice and lookup with both contract and account.  

The code below  populates the account field on the shipment record when the shipment record is created for the first time.  The problem that I am trying to solve is how to populate the contract field also at the same time that the account field is populated because currently I have to enter the contract number manually even though the shipment record belongs to one and only one contract through the invoice record.

/*Salesforce.com Extension Doug copied OLI_Serial_Number Trigger
This trigger is used to populate Account field on Shipment__c custom object
*/
trigger updateShipmentInfo on Shipment__c (before insert) {

    Set<Id> shipIds=new Set<Id>();
    Set<Id> conIds=new Set<Id>();
    
    for(Shipment__c ship:Trigger.new){
        shipIds.add(ship.Id);
        conIds.add(ship.contract__c);
    }
    
    if(shipIds.size() > 0){
    Map<Id,Contract> conMap = new Map<Id,Contract>([select AccountId from contract where id in:conIds]);
    
        for(Shipment__c ship:Trigger.new){
            ship.put(Shipment__c.Account__c, conMap.get(ship.contract__c).accountId);
        }
    }
}

 

Any help will be much appreciated!

 

Thanks

 

Doug

Hello,

 

I'm new to Apex coding and was wondering how a VF page would look for creating a button that would export data in an opportunity.   I'm trying to give my users the ability to hit the button in an opportunity and export company name, address, sales order # into a Network Access Database or an Excel Spreadsheet.  We'll use this database to create call tags via UPS to return an order (completed Opportunity). 

 

Sean

  • August 02, 2010
  • Like
  • 0

Hi,

 

Have a visualforce page rendered as a PDF.

 

I now want to batch produce if possible PDF's.

 

Is this possible?

 

Thanks

 

Ross

Would like to extend the capability of the "View All" button under the Activity History section to only return activities assigned to certain users.

 

Where can I get the source code for the View Activity History? 

 

How would I go about creating the filter?

 

I've developed using Apex but I am new to VF.

 

-Thanks

I want to display the header for a visual force page.  I put showHeader="true"  in the "<apex:page" line, but the header does not show unless I have a "<apex:detail/>" item on the page.

 

I know the name of the object row and want that displayed in the header, but I want to format the rest of the page without using the detail view.

 

Is there anyway that this can be done?

 

Thanks,

JR

  • July 27, 2010
  • Like
  • 0

Hello all,

 

I checked out the forums and I can't seem to find a solution to this. On person accounts (in Enterprise Edition), I have an auto-number field but I only want increment for my "customers" record type and not my "employee" record type. Right now it is auto-numbering for both even though I want it to increment when it's the customer record type.  Can someone help me with this/point me into the right direction or have some custom code that can do this?

 

Thanks much!

-Billy

  • July 13, 2010
  • Like
  • 0

I have two fields..

 

1- Date_Time_1_c

2- Date_Time_2_c

 

I want the default value of Date_time_2_c to be Date_Time_1_c+1 hour. How do I use addhours here? or is there any other solution?

 

Thanks,

Shariq

Hi,

 

I have made a visualforce page which displays a table of data. I have also put some filters there for which the number of rows of the data in the visualforce page varies.

 

Now I want a mechanism in place by which I can export the data showing at a partcular moment can be exported to a excel sheet/csv with column headers which can be saved locally.

 

a help and a guideline will be much appreciated.

 

cheers

 

Praz

  • May 13, 2010
  • Like
  • 0