• Tack
  • NEWBIE
  • 15 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
Hi,

I'm working on development custom object integration app.
I can implement below code in apex.
 
Lead lc1 = new Lead();
                    
                    lc1.Company = HogeObjectSelects[idx].record.Name;
                    lc1.LastName = HogeObjectSelects[idx].record.LastName__c;
                    lc1.FirstName = HogeObjectSelects[idx].record.FirstName__c;
                    lc1.email = HogeObjectSelects[idx].record.EmailAddress__c;
                    lc1.Status = 'Open - Not Contacted';
                    lc1.OwnerId = HogeObjectSelects[idx].record.OwnerId;
                upsert lc1;
sure, this is hard-code.
The app users are not able to change mapped fields...
Even though I provide mapping rule on GUI,
I can not implement the code.
 
My above idea is similar to general feature "Map Custom Lead Field".
https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_mapleads.htm&language=en
Could you please provide your sample code or reference?
 
Thanks,
Tack
 
  • November 12, 2014
  • Like
  • 0
Dear Developers,

I would like to implement mass convert custom object to lead page on APEX.

As first, I wrote following program.
It is not able to show error message when you don't select any records from a list view.

>ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select one record at least');
<apex:page StandardController="CustomObj__c" extensions="CheckDupClass" recordSetVar="DupRecords" id="Page">
    <apex:form id="form">
        	<apex:pageBlock id="step1" title="Selected Records" mode="edit" >
      			<apex:pageBlockTable value="{!selectedItems}" var="m">
          			<apex:column value="{!m.Name}" />
          			<apex:column value="{!m.LastName__c}" />
          			<apex:column value="{!m.FirstName__c}" />
                    <apex:column value="{!m.EmailAddress__c}" />
      			</apex:pageBlockTable>
            	<apex:pageBlockButtons location="bottom">   
               		<apex:commandButton value="Execute"  action="{!Ex_CheckDupClass}"/>
               		<apex:commandButton value="Cancel" action="{!cancel}"/>
        		</apex:pageBlockButtons>
     		</apex:pageBlock>
    </apex:form>
</apex:page>
public with sharing class CheckDupClass {

	public List<CustomObj__c> selectedItems{get;set;}
	
    public CheckDupClass(ApexPages.StandardSetController controller) {
       	List<CustomObj__c> ubId = (List<CustomObj__c>)controller.getSelected();
       	this.selectedItems=[select Id, Name, LastName__c, FirstName__c, EmailAddress__c, OwnerId 
                            		  from CustomObj__c where Id IN :ubId ORDER BY Name ASC LIMIT 10];
        	if (selectedItems.size() <= 0)
			{
			 //Want to show error message when user didn't select any records and display the page.
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select one record at least');
        	}
    }
	
    //Insert records in lead module
    public void Ex_CheckDupClass(){
    	Map<String,CustomObj__c> targetEmailMap = new Map<String,CustomObj__c>();
    
        for(CustomObj__c selectedItem : selectedItems){
            if(selectedItem.EmailAddress__c != null){
                if(!targetEmailMap.containsKey(selectedItem.EmailAddress__c)){
                    targetEmailMap.put(selectedItem.EmailAddress__c,selectedItem);
                }else{
                    targetEmailMap.get(selectedItem.EmailAddress__c).addError('The email address exists in leads module')
                }
            }
        }
        
	    if(targetEmailMap.size() !=0){
        	List<Lead> leads = [SELECT id, email FROM Lead WHERE email in :targetEmailMap.keyset()];
        if (leads.size() > 0) {
            for(Lead lead: leads){
               targetEmailMap.get(lead.email).addError('The email address exists in leads module');
             }
        }else{
            //Execute insert operation when no duplication
            for (Integer i = 0; i < selectedItems.size(); i++){
            Lead lc1 = new Lead();
            		lc1.Company = selectedItems[i].Name;
            		lc1.LastName = selectedItems[i].LastName__c;
            		lc1.FirstName = selectedItems[i].FirstName__c;
            		lc1.email = selectedItems[i].EmailAddress__c;
            		lc1.Status = 'Open - Not Contacted';
            		lc1.OwnerId = selectedItems[i].OwnerId;
            	insert lc1;
        	}       
        }
    }
}
    
    
    public PageReference cancel() {
		String retUrl = Apexpages.currentPage().getParameters().get('retUrl');
		if (retUrl == '')
		{
			return new PageReference('/');
		}
		else
		{
			return new PageReference(retUrl);
		}	
	}      
}

In above code, you can insert all selected records if emails are not duplicated.
It means that you can not insert any records if there are the email address in lead module already.

I can not find the information I wanted in help page and past topic.
(I am so sorry my searching way is not good)
Could you please support me to resolve above issues?

Could you please let me know if you need more details?

Best Regards,
Tack 

  • August 19, 2014
  • Like
  • 0
Hi,

I'm working on development custom object integration app.
I can implement below code in apex.
 
Lead lc1 = new Lead();
                    
                    lc1.Company = HogeObjectSelects[idx].record.Name;
                    lc1.LastName = HogeObjectSelects[idx].record.LastName__c;
                    lc1.FirstName = HogeObjectSelects[idx].record.FirstName__c;
                    lc1.email = HogeObjectSelects[idx].record.EmailAddress__c;
                    lc1.Status = 'Open - Not Contacted';
                    lc1.OwnerId = HogeObjectSelects[idx].record.OwnerId;
                upsert lc1;
sure, this is hard-code.
The app users are not able to change mapped fields...
Even though I provide mapping rule on GUI,
I can not implement the code.
 
My above idea is similar to general feature "Map Custom Lead Field".
https://help.salesforce.com/apex/HTViewHelpDoc?id=customize_mapleads.htm&language=en
Could you please provide your sample code or reference?
 
Thanks,
Tack
 
  • November 12, 2014
  • Like
  • 0
Dear Developers,

I would like to implement mass convert custom object to lead page on APEX.

As first, I wrote following program.
It is not able to show error message when you don't select any records from a list view.

>ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select one record at least');
<apex:page StandardController="CustomObj__c" extensions="CheckDupClass" recordSetVar="DupRecords" id="Page">
    <apex:form id="form">
        	<apex:pageBlock id="step1" title="Selected Records" mode="edit" >
      			<apex:pageBlockTable value="{!selectedItems}" var="m">
          			<apex:column value="{!m.Name}" />
          			<apex:column value="{!m.LastName__c}" />
          			<apex:column value="{!m.FirstName__c}" />
                    <apex:column value="{!m.EmailAddress__c}" />
      			</apex:pageBlockTable>
            	<apex:pageBlockButtons location="bottom">   
               		<apex:commandButton value="Execute"  action="{!Ex_CheckDupClass}"/>
               		<apex:commandButton value="Cancel" action="{!cancel}"/>
        		</apex:pageBlockButtons>
     		</apex:pageBlock>
    </apex:form>
</apex:page>
public with sharing class CheckDupClass {

	public List<CustomObj__c> selectedItems{get;set;}
	
    public CheckDupClass(ApexPages.StandardSetController controller) {
       	List<CustomObj__c> ubId = (List<CustomObj__c>)controller.getSelected();
       	this.selectedItems=[select Id, Name, LastName__c, FirstName__c, EmailAddress__c, OwnerId 
                            		  from CustomObj__c where Id IN :ubId ORDER BY Name ASC LIMIT 10];
        	if (selectedItems.size() <= 0)
			{
			 //Want to show error message when user didn't select any records and display the page.
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select one record at least');
        	}
    }
	
    //Insert records in lead module
    public void Ex_CheckDupClass(){
    	Map<String,CustomObj__c> targetEmailMap = new Map<String,CustomObj__c>();
    
        for(CustomObj__c selectedItem : selectedItems){
            if(selectedItem.EmailAddress__c != null){
                if(!targetEmailMap.containsKey(selectedItem.EmailAddress__c)){
                    targetEmailMap.put(selectedItem.EmailAddress__c,selectedItem);
                }else{
                    targetEmailMap.get(selectedItem.EmailAddress__c).addError('The email address exists in leads module')
                }
            }
        }
        
	    if(targetEmailMap.size() !=0){
        	List<Lead> leads = [SELECT id, email FROM Lead WHERE email in :targetEmailMap.keyset()];
        if (leads.size() > 0) {
            for(Lead lead: leads){
               targetEmailMap.get(lead.email).addError('The email address exists in leads module');
             }
        }else{
            //Execute insert operation when no duplication
            for (Integer i = 0; i < selectedItems.size(); i++){
            Lead lc1 = new Lead();
            		lc1.Company = selectedItems[i].Name;
            		lc1.LastName = selectedItems[i].LastName__c;
            		lc1.FirstName = selectedItems[i].FirstName__c;
            		lc1.email = selectedItems[i].EmailAddress__c;
            		lc1.Status = 'Open - Not Contacted';
            		lc1.OwnerId = selectedItems[i].OwnerId;
            	insert lc1;
        	}       
        }
    }
}
    
    
    public PageReference cancel() {
		String retUrl = Apexpages.currentPage().getParameters().get('retUrl');
		if (retUrl == '')
		{
			return new PageReference('/');
		}
		else
		{
			return new PageReference(retUrl);
		}	
	}      
}

In above code, you can insert all selected records if emails are not duplicated.
It means that you can not insert any records if there are the email address in lead module already.

I can not find the information I wanted in help page and past topic.
(I am so sorry my searching way is not good)
Could you please support me to resolve above issues?

Could you please let me know if you need more details?

Best Regards,
Tack 

  • August 19, 2014
  • Like
  • 0