• wbrproductions
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies

I'm attempting to restrict the delete of a Contact, via before delete trigger, by looking for a specific value in a custom picklist field.

 

I've created a trigger, as follows (on Before Delete):

trigger ContactDelete on Contact (before delete)
{
static string errSecPointContact = 'This Contact is the Security Point of Contact on the Account, and cannot be deleted. Please contact the SFDC Admin group for any questions.';
for (Contact c : trigger.old)
{
if (c.Job_Role__c == 'Security Point of Contact')
{
c.addError(errSecPointContact);
}
}
}

 

This error message displays as follows:

"Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "This Contact is the Security Point of Contact on the Account, and cannot be deleted. Please contact the SFDC Admin group for any questions.".

Click here to return to the previous page. "

That's a pretty ugly solution. How can I go about adding this error to the standard object detail page, or display this error in a more user-friendly way?

 

Thanks!

Hello,

 

I've been following 2 threads in an attempt to write a trigger that reassigns ownership of certain leads upon insert, then execute assignment rules for the ones not meeting that criteria:

 

http://boards.developerforce.com/t5/General-Development/Urgent-Lead-Assignment-Rule-Trigger-recursively-updates-itself/td-p/174995

 

- and -

 

http://boards.developerforce.com/t5/Apex-Code-Development/How-to-route-LEADs-back-through-LEAD-Assignment-rules/m-p/171285#M26391

 

The problem: this line in the trigger code:

 

lIds.add(l.Id);

 never seems to have an Id to add, so the assignment rules don't reassign anything. I may not have constructed this trigger correctly based on the example, so please let me know if you see something wrong with this.

 

Trigger code:

 

trigger LeadNamedAccountOwnership on Lead (before insert)
{
    List<Id> lIds = new List<id>();
    
    for (lead l : trigger.new)
    {
        // get lead email, lookup related domains
        if (l.Email != null && l.Email.length() > 0)
        {
            LeadCaseAssignment.leadAssignAlreadyCalled = LeadCaseAssignment.SetLeadOwnerByEmail(l);
        }
        if (!LeadCaseAssignment.leadAssignAlreadyCalled && l.IsConverted == false)
        {
            system.debug('leadId = ' + l.Id);
            lIds.add(l.Id);
        }
    }
    if (LeadCaseAssignment.leadAssignAlreadyCalled() == false)
    {
        LeadCaseAssignment.LeadAssign(lIds);
    }
}

 Helper class:

 

public with sharing class LeadCaseAssignment 
{
	public static Boolean leadAssignAlreadyCalled = false;

    public static boolean leadAssignAlreadyCalled()
    {
        return leadAssignAlreadyCalled;
    }
    
    @future
    public static void LeadAssign(List<Id> lIds)
    {
        leadAssignAlreadyCalled = true;
        
        List<Lead> leads = [   Select Id From Lead Where Id IN: lIds];

        for (lead l : leads)
        {
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule= true;
            l.setOptions(dmo);
        }
        
        //try{
        update(leads);
        //}
    }

    public static boolean SetLeadOwnerByEmail(Lead lead)
    {
        List<Account> accounts = GetDomainAccounts(lead.Email);
        
        if (accounts.size() > 0)
        {
            if (accounts.get(0).Mid_Market_Named_Region__c != '' || accounts.get(0).US_Enterprise_Region__c != '')
            {
                lead.OwnerId = accounts.get(0).OwnerId;
                return true;
            }
        }

        return false;
    }
    
    private static List<Account> GetDomainAccounts(String email)
    {
        List<Domain__c> domains = new List<Domain__c>();
        List<Account> accts = new List<Account>();
        
        String emailDomain = email.split('@').get(1).trim();

        domains = [ Select Id, Account__c, Name 
                    From Domain__c 
                    Where Name =: emailDomain];
                    
        for (Domain__c domain : domains)
        {
            accts = [   Select a.US_Enterprise_Region__c, a.Mid_Market_Named_Region__c, a.Id, a.OwnerId 
                        From Account a 
                        Where Id =: domain.Account__c limit 1];
        }

        return accts;
    }

    static testMethod void testLeadCaseAssignment()
    {
    	Test.startTest();

        TestUtility util = new TestUtility();
        Account testAccount = util.getTestAccount();
        Contact testContact = util.getTestContact(testAccount);

        Domain__c domain = new Domain__c();
        domain.Account__c = testAccount.Id;
        domain.Name = 'test.com';
        insert domain;

        Lead testLead = util.getTestLead();
        testLead.Email = 'test@test.com';
        update testLead;
                
        system.assertEquals(true, LeadCaseAssignment.leadAssignAlreadyCalled());

        List<Id> ids = new List<Id>();
        ids.add(testLead.Id);
        LeadCaseAssignment.LeadAssign(ids);

        LeadCaseAssignment.SetLeadOwnerByEmail(testLead);
        
        testLead.Email = 'test@doink.com';
        update testLead;
        
        LeadCaseAssignment.SetLeadOwnerByEmail(testLead);

        Test.stopTest();
    }
}

 

Thanks in advance,

Brian

Hello,

 

I'm working on a project to allow conversion of Cases to Accounts, Contacts and Opportunities. From the default Lead Detail page, there's a convert button that opens the Lead Conversion page, which contains a combination drop-down, lookup and view control for Account Name. The Account Name dropdown is a fuzzy match on the Lead Account Name field, then allows either a lookup or a view of the selected Account.

 

Has anyone tried to replicate this set of controls for other objects? I'd like build the same control for Cases, but not sure where to start. Screenshot of the control in question attached.

 

Thanks,

Brian

 

Convert Lead

Hello,

 

I've been following 2 threads in an attempt to write a trigger that reassigns ownership of certain leads upon insert, then execute assignment rules for the ones not meeting that criteria:

 

http://boards.developerforce.com/t5/General-Development/Urgent-Lead-Assignment-Rule-Trigger-recursively-updates-itself/td-p/174995

 

- and -

 

http://boards.developerforce.com/t5/Apex-Code-Development/How-to-route-LEADs-back-through-LEAD-Assignment-rules/m-p/171285#M26391

 

The problem: this line in the trigger code:

 

lIds.add(l.Id);

 never seems to have an Id to add, so the assignment rules don't reassign anything. I may not have constructed this trigger correctly based on the example, so please let me know if you see something wrong with this.

 

Trigger code:

 

trigger LeadNamedAccountOwnership on Lead (before insert)
{
    List<Id> lIds = new List<id>();
    
    for (lead l : trigger.new)
    {
        // get lead email, lookup related domains
        if (l.Email != null && l.Email.length() > 0)
        {
            LeadCaseAssignment.leadAssignAlreadyCalled = LeadCaseAssignment.SetLeadOwnerByEmail(l);
        }
        if (!LeadCaseAssignment.leadAssignAlreadyCalled && l.IsConverted == false)
        {
            system.debug('leadId = ' + l.Id);
            lIds.add(l.Id);
        }
    }
    if (LeadCaseAssignment.leadAssignAlreadyCalled() == false)
    {
        LeadCaseAssignment.LeadAssign(lIds);
    }
}

 Helper class:

 

public with sharing class LeadCaseAssignment 
{
	public static Boolean leadAssignAlreadyCalled = false;

    public static boolean leadAssignAlreadyCalled()
    {
        return leadAssignAlreadyCalled;
    }
    
    @future
    public static void LeadAssign(List<Id> lIds)
    {
        leadAssignAlreadyCalled = true;
        
        List<Lead> leads = [   Select Id From Lead Where Id IN: lIds];

        for (lead l : leads)
        {
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule= true;
            l.setOptions(dmo);
        }
        
        //try{
        update(leads);
        //}
    }

    public static boolean SetLeadOwnerByEmail(Lead lead)
    {
        List<Account> accounts = GetDomainAccounts(lead.Email);
        
        if (accounts.size() > 0)
        {
            if (accounts.get(0).Mid_Market_Named_Region__c != '' || accounts.get(0).US_Enterprise_Region__c != '')
            {
                lead.OwnerId = accounts.get(0).OwnerId;
                return true;
            }
        }

        return false;
    }
    
    private static List<Account> GetDomainAccounts(String email)
    {
        List<Domain__c> domains = new List<Domain__c>();
        List<Account> accts = new List<Account>();
        
        String emailDomain = email.split('@').get(1).trim();

        domains = [ Select Id, Account__c, Name 
                    From Domain__c 
                    Where Name =: emailDomain];
                    
        for (Domain__c domain : domains)
        {
            accts = [   Select a.US_Enterprise_Region__c, a.Mid_Market_Named_Region__c, a.Id, a.OwnerId 
                        From Account a 
                        Where Id =: domain.Account__c limit 1];
        }

        return accts;
    }

    static testMethod void testLeadCaseAssignment()
    {
    	Test.startTest();

        TestUtility util = new TestUtility();
        Account testAccount = util.getTestAccount();
        Contact testContact = util.getTestContact(testAccount);

        Domain__c domain = new Domain__c();
        domain.Account__c = testAccount.Id;
        domain.Name = 'test.com';
        insert domain;

        Lead testLead = util.getTestLead();
        testLead.Email = 'test@test.com';
        update testLead;
                
        system.assertEquals(true, LeadCaseAssignment.leadAssignAlreadyCalled());

        List<Id> ids = new List<Id>();
        ids.add(testLead.Id);
        LeadCaseAssignment.LeadAssign(ids);

        LeadCaseAssignment.SetLeadOwnerByEmail(testLead);
        
        testLead.Email = 'test@doink.com';
        update testLead;
        
        LeadCaseAssignment.SetLeadOwnerByEmail(testLead);

        Test.stopTest();
    }
}

 

Thanks in advance,

Brian

I created a list button that opens a popup VF page which contains a form. After the form is saved, I want the popup to close and for the parent window to be refreshed. The refresh works great on FireFox and Chrome, but IE8 is somehow opening the parent window in a new window, instead of just refreshing the existing window. I've gone through various methods of opening a new window (window.showModalDialog, window.open, etc) and have settled on window.open() in my list button. I also found a great piece of code on the forum that returns values from my controller, closes my pop up and refreshes the parent window. 

 

Why is IE8 opening a new window instead of just refreshing the existing one?

 

List button javascript&colon;

 

window.open('/apex/quickCreateProduction?id={!Contact.Id}',"window","width=460, height=375");

 Javascript in VF page (popup):

 

<script language="javascript" type="text/javascript">
if("{!$Request.success}" == "true") {
	parent.window.close();
	parent.window.opener.location.href = "/{!$Request.id}";          
}
</script>

 

Save in custom controller (after success):

 

		PageReference curPage = ApexPages.currentPage();
		curPage.getParameters().put('success','true');
		curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
		curPage.setRedirect(true);
		return curPage;

 

I could definitely use some help. Thanks in advance.

 

Adriel

  • August 20, 2010
  • Like
  • 0

Hi,

while working quite a lot with campaigns and opportunities, I'm faced with the problem to create campaign influence records for opportunities in batch (not manually)

Adding an influence for an contact or lead is quite easy; add a record to the table CampaignMember and that's it... 

 

But - in which table are records stored that define a relationship between an opportunity and a campaign? Can't find it - the prefix is 0BG - if this might help anybody.

 

Many thanks in advance!

  • March 02, 2009
  • Like
  • 0
I've been having a big issue getting the Apex data loader to run via the command line. I'm using v14.

I've encrypted the password correctly:
Code:
encrypt -e passwordSecurityToken

 The results I store in the conf file, which looks like this:
Code:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="csvLenderExtractProcess"
          class="com.salesforce.lexiloader.process.ProcessRunner"
          singleton="false">
      <description>csvLenderExtract job gets account info from salesforce and saves info into a CSV file."</description>
        <property name="name" value="csvLenderExtract"/>
        <property name="configOverrideMap">
            <map>
                <entry key="sfdc.debugMessages" value="false"/>
                <entry key="sfdc.debugMessagesFile" value="c:\Program Files\salesforce.com\Apex Data Loader 14.0\sfdcSoapTrace.log"/>
                <entry key="sfdc.endpoint" value="https://www.salesforce.com"/>
                <entry key="sfdc.username" value="user@customer.com"/>
                <!-- password specified below is invalid, please generate one using the encrypt.bat utility -->
                <entry key="sfdc.password" value="a58afc521f2f0f6a1f26adab1e6dbc740d705a086f9301310754ec6f9753d7d0" />
  <entry key="process.encryptionKeyFile" value="c:\Program Files\salesforce.com\Apex Data Loader 14.0\conf\password.key" />
                <entry key="sfdc.timeoutSecs" value="600"/>
                <entry key="sfdc.loadBatchSize" value="200"/>
                <entry key="sfdc.entity" value="Account"/>
                <entry key="sfdc.extractionRequestSize" value="500"/>
                <entry key="sfdc.extractionSOQL" value="Select Id, Name FROM Account"/>
                <entry key="process.operation" value="extract"/>
                <entry key="process.mappingFile" value="C:\Program Files\salesforce.com\Apex Data Loader 14.0\conf\accountExtractMap.sdl"/>
                <entry key="dataAccess.type" value="csvWrite"/>
                <entry key="dataAccess.name" value="C:\Program Files\salesforce.com\Apex Data Loader 14.0\data\extractLender.csv"/>
            </map>
        </property>
    </bean>
</beans>

 If I leave the sfdc.password entry in the xml it complains it's an invalid string. If I comment it out to just use the password file, I get:
Code:
1232 [csvLenderExtract] ERROR com.salesforce.lexiloader.process.ProcessRunner  -
 Invalid username, password, security token; or user locked out.                
Exception in thread "main" java.lang.RuntimeException: [LoginFault [ApiFault  ex
ceptionCode='INVALID_LOGIN'                                                     
 exceptionMessage='Invalid username, password, security token; or user locked ou
t.'                                                                             
]                                                                               
]                                                                               
                                                                                
        at com.salesforce.lexiloader.process.ProcessRunner.run(ProcessRunner.jav
a:148)                                                                          
        at com.salesforce.lexiloader.process.ProcessRunner.main(ProcessRunner.ja
va:228)                                                                         
Caused by: [LoginFault [ApiFault  exceptionCode='INVALID_LOGIN'                 
 exceptionMessage='Invalid username, password, security token; or user locked ou
t.'                                                                             
]                                                                               
]                                                                               
                                                                                
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                                                                                
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)                                                         
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:27)                                                 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:494)      
        at java.lang.Class.newInstance0(Class.java:350)                         
        at java.lang.Class.newInstance(Class.java:303)                          
        at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:563)        
        at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:475)        
        at com.sforce.ws.transport.SoapConnection.parseDetail(SoapConnection.jav
a:187)                                                                          
        at com.sforce.ws.transport.SoapConnection.createException(SoapConnection
.java:166)                                                                      
        at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:11
2)                                                                              
        at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:92)  
        at com.sforce.soap.partner.PartnerConnection.login(PartnerConnection.jav
a:864)                                                                          
        at com.salesforce.lexiloader.client.PartnerClient.connectImpl(PartnerCli
ent.java:169)                                                                   
        at com.salesforce.lexiloader.client.PartnerClient.connect(PartnerClient.
java:148)                                                                       
        at com.salesforce.lexiloader.controller.Controller.login(Controller.java
:174)                                                                           
        at com.salesforce.lexiloader.process.ProcessRunner.run(ProcessRunner.jav
a:115)                                                                          
        ... 1 more                                                              

 
Does v14.0 even work via the command line?

Thanks in advance.