• BigSmoke
  • NEWBIE
  • 50 Points
  • Member since 2011

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 8
    Replies

This is my first real "project" regarding salesforce and apex so I'm not too familiar with it. What I would like to do is have a trigger use the asset's ID as a asset name if one isn't given. After doing some reading I think I have a good idea on what needs to be done but I keep getting a "DescriptionResourcePathLocationTypeSave error: Invalid initial type LIST<IT_Asset__c> for MAP<Name,String>" returned when I save it. Any ideas?

 

trigger AssetNamePopulate on IT_Asset__c (before insert, before update) 
{
	
	Set<Id> aids = new Set<Id> ();
	for (IT_Asset__c asset : Trigger.new) 
	{
		aids.add(asset.name); 
		
	}
    
	Map<Id, string> m = new Map<Id, string>([Select name, asset_name__c from IT_Asset__c where name in :aids]);

	for (IT_Asset__c asset : Trigger.new) 
	{
        if (asset.asset_name__c == null) 
        {
        	if (m.containsKey(asset.name)) 
        	{
        		asset.asset_name__c = m.get(asset.name);
        	}
        }
     }
	
	
}

 

Hi,

 

I had quite a harrowing weekend trying to deploy a lot of code from a full sandbox to production.  One of the problems I had was slowness.  Using Eclipse and deploying to live took as much as 45 minutes, only to come back with a failure.  I found this particularly frustrating because when everything works in a full copy sandbox, you expect it to work in production.

 

A deployment whose steps took 20 minutes against a full sandbox took 9 hours against production because of errors.  So I'd take four or five minutes to try something to resolve the error and then I'd have to wait another 40 for the deployment to fail.  Even when I was loading only one small class with one small unit test, it still took a long time.

 

I was wondering if I'm the only one experiencing this, and if it's an Eclipse thing or a Salesforce thing.

 

Any tips would be most appreciated.

Hi,

 

I'm trying to write a class that will autoconvert certain leads to existing opportunities without creating an opportunity, given a lead, a contact Id, an account Id, and an owner Id.

 

I'm using the following code to troubleshoot my problem:

public class autoConvertLead {

	// use this lead as a test
    public PageReference cL() {
		Id id = '00QM0000001LJrl';
		set<Id> idSet = new set<Id>{id};
		
        convertList(idSet);
        return null;
    }


    public void convertList(set<Id> leads) {

LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus 
 where MasterLabel like '%auto%match%' and IsConverted=true limit 1];

        Lead[] leadList = [select Id, account__c, contact__c, contact__r.AccountId,  
        account__r.ownerId from Lead 
                where Id in :leads and isConverted = false];
                    
        for (Lead lead : leadList) {

        system.assert(lead.account__c != null);
        system.assert(lead.contact__c != null);
        system.assert(lead.account__c == lead.contact__r.AccountId);   
                                     
        Database.LeadConvert lc = new database.LeadConvert();
            lc.setLeadId(lead.id);
            lc.setDoNotCreateOpportunity(true); 
          //  lc.setOwnerId(lead.account__r.ownerId);
            lc.setAccountId(lead.account__c);
            lc.setContactId(lead.contact__c);
            lc.setOverwriteLeadSource(false);
			lc.setSendNotificationEmail(false);
    		lc.setConvertedStatus(convertStatus.MasterLabel);

        system.assert(convertStatus.MasterLabel != null);
        system.debug(lc);
                
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        }
    }
}

 

 

I'm getting "INVALID_STATUS, invalid convertedStatus: Convert - Auto-match to Existing Contact: []: Class.autoConvertLead.convertList: line 36, column 58".

 

I'm taking all the precautions in my code.  I'm ensuring the status value is valid first before using it.:

LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus 
 where MasterLabel like '%auto%match%' and IsConverted=true limit 1];

 

I'm ensuring the lead has the requisite IDs for everything else.  

 

I'm able to convert a clone of the same lead (same record type too)  through the usual steps in the Salesforce.com UI and converting the lead that way, selecting exactly the same Status and I'm having no problem with that.

 

There isn't very much in the way of postings around this topic.

 

Are there any lead conversion wizards out there??

 

Thanks.

I've got a situation where I want to display competitors on a Visualforce page -- if there are any.

 

My competitors are stored in Account and there's an object called Competitor__c which links the Account to itself many to many.

 

On my visualforce page, I've got two datatables that render the lists of competitors as per getIncumbents and getNonIncumbents.

 

 

        public list<Competitor__c> getIncumbents() {
                 return getCompetitors(account.Id, true);
     
         }

        public list<Competitor__c> getNonIncumbents() {
                 return getCompetitors(account.Id, false);
        }


        public list<Competitor__c> getCompetitors(Id accId, boolean incumbent) {
        // pass true for incumbents and false for non-incumbents
        list<Competitor__c> comps = new list<Competitor__c>();

        comps = [Select Opportunity__r.StageName, Opportunity__r.Name, 
        Opportunity__c, Notes__c, LastModifiedDate, LastModifiedById, 
        Incumbent__c, Incumbent_Value__c, Incumbent_Renewal_Date__c, 
        Competitor__r.Name, Competitor__c, Competing_Product_Area__c 
        from Competitor__c c 
        where Account__c = :accId and Incumbent__c = :incumbent];

        if (comps.size() > 0) {
        	return comps;
        	}
        else return null;
    }

 

 

The situation is that it's perfectly normal for there to not be any competitors.  When there are competitors it all works fine.  When there aren't there are nullPointer exceptions.

 

What does one do when returning nothing back is AOK??

 

 

 

            <apex:dataTable rendered="{! NOT(err)}" value="{!incumbents}" var="c" styleClass="tableClass" columnswidth="200px,200px" cellpadding="4" border="1">                <apex:column >
                        <apex:facet name="header">Competitors (incumbent)</apex:facet>
                        <apex:outputText value="{!c.Competitor__r.Name}"/>
                </apex:column>

                <apex:column >
                        <apex:facet name="header">Notes</apex:facet>
                        <apex:outputText value="{!c.Notes__c}"/>
                </apex:column>

                <apex:column >
                        <apex:facet name="header">Value</apex:facet>
                        <apex:outputField value="{!c.Incumbent_Value__c}" />
                </apex:column>

                <apex:column >
                        <apex:facet name="header">Renewal Date</apex:facet>
                        <apex:outputText value="{0,date,MMM d yyyy}">
                             <apex:param value="{!c.Incumbent_Renewal_Date__c}" />
                        </apex:outputText>
                                 
                </apex:column>

                <apex:column >
                        <apex:facet name="header">Product Area</apex:facet>
                        <apex:outputText value="{!c.Competing_Product_Area__c}"/>
                </apex:column>
            </apex:dataTable>
<p/><hr/><p/>

            <apex:dataTable rendered="{! NOT(err)}"  value="{!nonincumbents}" var="c" styleClass="tableClass" columnswidth="200px,200px" cellpadding="4" border="1">                <apex:column >
                        <apex:facet name="header">Competitors (non-incumbent)</apex:facet>
                        <apex:outputText value="{!c.Competitor__r.Name}"/>
                </apex:column>

                <apex:column >
                        <apex:facet name="header">Notes</apex:facet>
                        <apex:outputText value="{!c.Notes__c}"/>
                </apex:column>

                <apex:column >
                        <apex:facet name="header">Opportunity</apex:facet>
                        <apex:outputText value="{! if(c.Opportunity__r.Name != null,c.Opportunity__r.Name, ' -- ') }"/>
                </apex:column>


                <apex:column >
                        <apex:facet name="header">Stage</apex:facet>
                        <apex:outputText value="{!c.Opportunity__r.StageName}"/>
                </apex:column>

                <apex:column >
                        <apex:facet name="header">Product Area</apex:facet>
                        <apex:outputText value="{!c.Competing_Product_Area__c}"/>
                </apex:column>
            </apex:dataTable>

 

There must be something simple here I'm just not doing. 

 

THANKS!!!

 

 

Hi,

 

Does anyone have any interesting thoughts on the old conundrum of making sure that Opportunities don't get edited after close?  Even if they do get edited for certain reasons, most businesses would not want opportunity products deleted after opportunities are closed.

 

I've always changed the record type on closed opps and assigned a read-only page layout.  This still allows for line items to be deleted.    This doesn't work so well anymore as I've got too many record types that would need corresponding "Closed" record types.

 

I've been considering:

 

1. Using Approvals to lock the record

2. Using a trigger to throw an error

 

Are there any other interesting ways you all go about this?  Maybe some validation rule I wasn't thinking of??

 

I've read other posts on this topic, but they're many years old.

Hi,

 

I've got a really simple trigger here that's giving me a little grief.  I've got child records off Opportunities called "Opportunity Allocations".  When an opportunity is created, we assume the allocation to the owner is at 100%.  Later, we might allocate other percentages to the owner, plus members of the sales team.

 

After insert on Opportunity, I create a row in Opportunity_Allocation__c, supplying OpportunityId and Opportunity.OwnerId.  For some reason I can't figure out, the Opportunity.OwnerId field won't populate on the child record.

 

The child record field is called "Sales_Team_Member__c and I've set it up as a lookup to User.  So I should be able to simply populate OwnerId into it or any other primary key for any other record in User object.  But it comes up null when the trigger fires.

 

So I decided to add a text field in called "STM" and I also put Opportunity.OwnerId in that field.  That works.

 

Here's the code.  The only bit that doesn't work properly is the beginning, inside the first if.   The rest of the trigger works as it should.  The rest of the trigger reassigns the owner's share of allocation every time the owner of the opportunity works.

 

I expected to have more trouble with the latter half of the code but that works.  The trouble's in the first 18 or so lines.

 

 

trigger insUpdOpportunity on Opportunity (after insert, after update) {
	
	List<Opportunity_Allocation__c> oaList = new List<Opportunity_Allocation__c>();
	
	if(Trigger.isInsert) {
		for (Opportunity o : trigger.new) {
			
			Opportunity_Allocation__c oa = new Opportunity_Allocation__c (
				Opportunity__c = o.Id,
				IsOwner__c = true,
				Percentage_Of_Revenue__c = 100,
				Region__c = 'XXX',
				Sales_Team_Member__c = o.OwnerId,
				STM_txt__c = o.OwnerId			
				);
			
			system.debug('this is oa:' + oa);		
			oaList.add(oa);			
		}
		
		insert oaList;
	
	
	}  // end if

	
	if(Trigger.isUpdate) {
		Opportunity[] oldOpp = trigger.old;
		Opportunity[] newOpp = trigger.new;
		

		// build the map of opp to new opp owner
		map<Id, Id> oppMap = new map<Id, Id>();		

		for (Integer i = 0; i < newOpp.size(); i++ ) {
			
			if (oldOpp[i].OwnerId != newOpp[i].OwnerId) {
				oppMap.put(newOpp[i].Id, newOpp[i].OwnerId)	;
			}

		}

		// build the list of opportunity allocations to modify
		
		oaList = [select Id,Opportunity__c, Sales_Team_Member__c 
					from Opportunity_Allocation__c
					where Opportunity__c in :Trigger.newMap.keyset() 
					 and IsOwner__c = true];


		// loop over the list and change the Sales_Team_Member 
							
		for (Opportunity_Allocation__c oa : oaList) {
				 
				oa.Sales_Team_Member__c = oppMap.get(oa.Opportunity__c);
		}

	//upsert the changed values (if any)
	if (oaList.size() > 0) 
		upsert oaList;
	
	}  // end if


}

 

 

 

What am I doing wrong?

 

Thanks!!

Hi Migration Tool experts!!

 

I've just begun using the Migration Tool and after a lot of initial frustrations, I'm really pleased with just how much time it's been saving me.

 

Now the big question:  how to undeploy things.  I've put a bunch of metadata into a developer's org that I've piped out of two different production orgs.  This was a great use of this tool.  I can go and create a different developer's org if I want, but I was wondering if it were easy enough to just clear out all the customisations I've put in.  It's easy to get rid of anything relating to custom objects in this way, I'm sure.  But  I'd like to get rid of all customisations of every stripe on the standard objects.

 

The documentation is a little bit scant on this, other than making mention to destructiveChanges.xml.

 

Any tips?

 

Thanks!!

 

Hi,

 

I'm trying to write a class that will autoconvert certain leads to existing opportunities without creating an opportunity, given a lead, a contact Id, an account Id, and an owner Id.

 

I'm using the following code to troubleshoot my problem:

public class autoConvertLead {

	// use this lead as a test
    public PageReference cL() {
		Id id = '00QM0000001LJrl';
		set<Id> idSet = new set<Id>{id};
		
        convertList(idSet);
        return null;
    }


    public void convertList(set<Id> leads) {

LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus 
 where MasterLabel like '%auto%match%' and IsConverted=true limit 1];

        Lead[] leadList = [select Id, account__c, contact__c, contact__r.AccountId,  
        account__r.ownerId from Lead 
                where Id in :leads and isConverted = false];
                    
        for (Lead lead : leadList) {

        system.assert(lead.account__c != null);
        system.assert(lead.contact__c != null);
        system.assert(lead.account__c == lead.contact__r.AccountId);   
                                     
        Database.LeadConvert lc = new database.LeadConvert();
            lc.setLeadId(lead.id);
            lc.setDoNotCreateOpportunity(true); 
          //  lc.setOwnerId(lead.account__r.ownerId);
            lc.setAccountId(lead.account__c);
            lc.setContactId(lead.contact__c);
            lc.setOverwriteLeadSource(false);
			lc.setSendNotificationEmail(false);
    		lc.setConvertedStatus(convertStatus.MasterLabel);

        system.assert(convertStatus.MasterLabel != null);
        system.debug(lc);
                
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        }
    }
}

 

 

I'm getting "INVALID_STATUS, invalid convertedStatus: Convert - Auto-match to Existing Contact: []: Class.autoConvertLead.convertList: line 36, column 58".

 

I'm taking all the precautions in my code.  I'm ensuring the status value is valid first before using it.:

LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus 
 where MasterLabel like '%auto%match%' and IsConverted=true limit 1];

 

I'm ensuring the lead has the requisite IDs for everything else.  

 

I'm able to convert a clone of the same lead (same record type too)  through the usual steps in the Salesforce.com UI and converting the lead that way, selecting exactly the same Status and I'm having no problem with that.

 

There isn't very much in the way of postings around this topic.

 

Are there any lead conversion wizards out there??

 

Thanks.

This is my first real "project" regarding salesforce and apex so I'm not too familiar with it. What I would like to do is have a trigger use the asset's ID as a asset name if one isn't given. After doing some reading I think I have a good idea on what needs to be done but I keep getting a "DescriptionResourcePathLocationTypeSave error: Invalid initial type LIST<IT_Asset__c> for MAP<Name,String>" returned when I save it. Any ideas?

 

trigger AssetNamePopulate on IT_Asset__c (before insert, before update) 
{
	
	Set<Id> aids = new Set<Id> ();
	for (IT_Asset__c asset : Trigger.new) 
	{
		aids.add(asset.name); 
		
	}
    
	Map<Id, string> m = new Map<Id, string>([Select name, asset_name__c from IT_Asset__c where name in :aids]);

	for (IT_Asset__c asset : Trigger.new) 
	{
        if (asset.asset_name__c == null) 
        {
        	if (m.containsKey(asset.name)) 
        	{
        		asset.asset_name__c = m.get(asset.name);
        	}
        }
     }
	
	
}

 

Hi,

 

I've got a really simple trigger here that's giving me a little grief.  I've got child records off Opportunities called "Opportunity Allocations".  When an opportunity is created, we assume the allocation to the owner is at 100%.  Later, we might allocate other percentages to the owner, plus members of the sales team.

 

After insert on Opportunity, I create a row in Opportunity_Allocation__c, supplying OpportunityId and Opportunity.OwnerId.  For some reason I can't figure out, the Opportunity.OwnerId field won't populate on the child record.

 

The child record field is called "Sales_Team_Member__c and I've set it up as a lookup to User.  So I should be able to simply populate OwnerId into it or any other primary key for any other record in User object.  But it comes up null when the trigger fires.

 

So I decided to add a text field in called "STM" and I also put Opportunity.OwnerId in that field.  That works.

 

Here's the code.  The only bit that doesn't work properly is the beginning, inside the first if.   The rest of the trigger works as it should.  The rest of the trigger reassigns the owner's share of allocation every time the owner of the opportunity works.

 

I expected to have more trouble with the latter half of the code but that works.  The trouble's in the first 18 or so lines.

 

 

trigger insUpdOpportunity on Opportunity (after insert, after update) {
	
	List<Opportunity_Allocation__c> oaList = new List<Opportunity_Allocation__c>();
	
	if(Trigger.isInsert) {
		for (Opportunity o : trigger.new) {
			
			Opportunity_Allocation__c oa = new Opportunity_Allocation__c (
				Opportunity__c = o.Id,
				IsOwner__c = true,
				Percentage_Of_Revenue__c = 100,
				Region__c = 'XXX',
				Sales_Team_Member__c = o.OwnerId,
				STM_txt__c = o.OwnerId			
				);
			
			system.debug('this is oa:' + oa);		
			oaList.add(oa);			
		}
		
		insert oaList;
	
	
	}  // end if

	
	if(Trigger.isUpdate) {
		Opportunity[] oldOpp = trigger.old;
		Opportunity[] newOpp = trigger.new;
		

		// build the map of opp to new opp owner
		map<Id, Id> oppMap = new map<Id, Id>();		

		for (Integer i = 0; i < newOpp.size(); i++ ) {
			
			if (oldOpp[i].OwnerId != newOpp[i].OwnerId) {
				oppMap.put(newOpp[i].Id, newOpp[i].OwnerId)	;
			}

		}

		// build the list of opportunity allocations to modify
		
		oaList = [select Id,Opportunity__c, Sales_Team_Member__c 
					from Opportunity_Allocation__c
					where Opportunity__c in :Trigger.newMap.keyset() 
					 and IsOwner__c = true];


		// loop over the list and change the Sales_Team_Member 
							
		for (Opportunity_Allocation__c oa : oaList) {
				 
				oa.Sales_Team_Member__c = oppMap.get(oa.Opportunity__c);
		}

	//upsert the changed values (if any)
	if (oaList.size() > 0) 
		upsert oaList;
	
	}  // end if


}

 

 

 

What am I doing wrong?

 

Thanks!!

Hi Migration Tool experts!!

 

I've just begun using the Migration Tool and after a lot of initial frustrations, I'm really pleased with just how much time it's been saving me.

 

Now the big question:  how to undeploy things.  I've put a bunch of metadata into a developer's org that I've piped out of two different production orgs.  This was a great use of this tool.  I can go and create a different developer's org if I want, but I was wondering if it were easy enough to just clear out all the customisations I've put in.  It's easy to get rid of anything relating to custom objects in this way, I'm sure.  But  I'd like to get rid of all customisations of every stripe on the standard objects.

 

The documentation is a little bit scant on this, other than making mention to destructiveChanges.xml.

 

Any tips?

 

Thanks!!