• Santhosh S
  • NEWBIE
  • 45 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 11
    Replies
i have javascipt button "MassEmail" in campaign detail page,when we click the button send the email to all related campign members.In this purpose i have created one Html email template for campaign objects.But in email template i am not able display"detail page link".
========
Javascript code
==========
{!REQUIRESCRIPT('/soap/ajax/26.0/connection.js')} 
{!REQUIRESCRIPT('/js/functions.js')} 
{!REQUIRESCRIPT('/resource/Rfleet_JqyeryUI_STR/jquery1/js/jquery-1.8.3.js')} 
{!REQUIRESCRIPT('/resource/Rfleet_JqyeryUI_STR/jquery1/js/jquery-ui-1.9.2.custom.min.js')} 

var Contactids=[]; 
var recordname=[]; 
var emailids=[]; 
var contactname=[]; 

var CamMember=sforce.connection.query("SELECT CampaignId,ContactId FROM CampaignMember where CampaignId='{!Campaign.Id}'"); 
var records = CamMember.getArray("records"); 

for (var i=0; i<records.length; i++) { 
recordname = records[i]; 
Contactids.push(recordname.ContactId); 



var con=sforce.connection.query('SELECT Id,Email '+'FROM Contact where id in (\'' + Contactids.join('\',\'') + '\')'); 

var contactemail = con.getArray("records"); 

for (var i=0; i<contactemail.length; i++) { 
contactname = contactemail[i]; 
emailids.push(contactname.Id); 



for (var i=0; i<emailids.length; i++) { 

var message = new sforce.SingleEmailMessage(); 
message.replyTo = "rapsac@gmail.com"; 
message.targetObjectId=emailids[i]; 
message.templateId ="00X4E000000EMXt"; 
var result = sforce.connection.sendEmail([message]); 

if(result[0].success == 'true') { 
alert("I sent the email as you requested, master."); 
} else { 
alert("I had a booboo."); 
}
==========
email template
========
User-added image

Advanced thanks for helping:)
Hi All,

I am using Ant Script with data loader, i have data with record id and i am trying to upsert data but using the below document i can see loader_params should have externalIdField to upsert but in my case i don't have external id field. Any one tried update or upsert with record Id?

https://developer.salesforce.com/docs/atlas.en-us.dataLoader.meta/dataLoader/loader_params.htm
Hello guys,
I need to copy a value from one recordtype to another, can i do it?
With a formula field or a workflow... i don´t really know.
i have javascipt button "MassEmail" in campaign detail page,when we click the button send the email to all related campign members.In this purpose i have created one Html email template for campaign objects.But in email template i am not able display"detail page link".
========
Javascript code
==========
{!REQUIRESCRIPT('/soap/ajax/26.0/connection.js')} 
{!REQUIRESCRIPT('/js/functions.js')} 
{!REQUIRESCRIPT('/resource/Rfleet_JqyeryUI_STR/jquery1/js/jquery-1.8.3.js')} 
{!REQUIRESCRIPT('/resource/Rfleet_JqyeryUI_STR/jquery1/js/jquery-ui-1.9.2.custom.min.js')} 

var Contactids=[]; 
var recordname=[]; 
var emailids=[]; 
var contactname=[]; 

var CamMember=sforce.connection.query("SELECT CampaignId,ContactId FROM CampaignMember where CampaignId='{!Campaign.Id}'"); 
var records = CamMember.getArray("records"); 

for (var i=0; i<records.length; i++) { 
recordname = records[i]; 
Contactids.push(recordname.ContactId); 



var con=sforce.connection.query('SELECT Id,Email '+'FROM Contact where id in (\'' + Contactids.join('\',\'') + '\')'); 

var contactemail = con.getArray("records"); 

for (var i=0; i<contactemail.length; i++) { 
contactname = contactemail[i]; 
emailids.push(contactname.Id); 



for (var i=0; i<emailids.length; i++) { 

var message = new sforce.SingleEmailMessage(); 
message.replyTo = "rapsac@gmail.com"; 
message.targetObjectId=emailids[i]; 
message.templateId ="00X4E000000EMXt"; 
var result = sforce.connection.sendEmail([message]); 

if(result[0].success == 'true') { 
alert("I sent the email as you requested, master."); 
} else { 
alert("I had a booboo."); 
}
==========
email template
========
User-added image

Advanced thanks for helping:)
Hi Friends ,

I am importing a csv file using data import wizard. After Completion of import i got the below error.
System.ListException: Duplicate id in list

It shows System.ListException: Duplicate id in list: 00Qn0000006FfywEAC.

When I check the id in my objects. i found a record . I check the CSV file with this record. I found phone number field is name in some other records. That'y It shows error Duplicate Id.
Only Phone number is Same , remaining fields are different. How to over come thsi.

My code is :

public class DataImport_Class {
    public static void beforeInsert (List<Campaign_Entry__c> newrecord){
Integer count1;
    String custObjEmailDomain;
    List <Lead> inlead = new List <Lead> ();
    List <Lead> uplead = new List <Lead> ();
    List <Lead> uplead1 = new List <Lead> ();
    List <Lead> uplead2 = new List <Lead> ();
    List <Campaign> campCrt = new List <Campaign> ();
    List <Campaign> camprecds = [select name, (select Name, Status, ContactId,LeadId,Phone, MobilePhone, 
                                     CompanyOrAccount from CampaignMembers ) from Campaign];
    List <CampaignMember> campMemUpd = new List <CampaignMember>();
    List <CampaignMember> campMemcre1 = new List <CampaignMember>();
    List <CampaignMember> campMemcre2 = new List <CampaignMember>();
    List <CampaignMember> campMemcre = new List <CampaignMember>();
    List <Account> accs = [select Email_Domain__c, (select LastName,Email, otherphone, phone, Contact_Status__c,Title,
                                  MailingStreet,MailingCity,MailingState,MailingPostalCode
                                                    from Contacts) from Account];
    List <Lead> leads = [select lastname, MobilePhone, Email, Company,phone, Title ,Street,City,State,PostalCode,Status from Lead];
    List <CampaignMember> campMem = [select Name, Status, ContactId,LeadId,Phone, MobilePhone, 
                                     CompanyOrAccount from CampaignMember];
       for (Campaign_Entry__c customObjRecord: newrecord) { // Iterate over the custom object records
           if(customObjRecord.Email_Address__c!=null && customObjRecord.Email_Address__c !=''){   
                custObjEmailDomain = ((customObjRecord.Email_Address__c).split('@')[1]).split( '\\.')[0];
           }
        System.debug(customObjRecord);
        Boolean accCrtFlag = true;
if (accCrtFlag) {
            Boolean leadCrtFlag = true;
            for (Lead l: leads) {
                if (leadCrtFlag && (customObjRecord.Email_Address__c == l.email && customObjRecord.Email_Address__c !=
                        '' && customObjRecord.Email_Address__c != null) && customObjRecord.Office_Phone__c != l.phone ) // If Email ids are same
                {
                    leadCrtFlag = false;
                    Lead l1 = l;
                    
                    if (customObjRecord.Name != null && customObjRecord.Name != '')
                        l1.LastName = customObjRecord.Name;
                    if (customObjRecord.First_Name__c != null && customObjRecord.First_Name__c != '')
                         l1.FirstName = customObjRecord.First_Name__c;
                    if (customObjRecord.Business_Card_Company__c != null && customObjRecord.Business_Card_Company__c !='')
                        l1.Company = customObjRecord.Business_Card_Company__c;
                    if (customObjRecord.Office_Phone__c != '' && customObjRecord.Office_Phone__c != null)
                        l1.MobilePhone = customObjRecord.Office_Phone__c; // Update new phone Field value into other phone Field
                    if (customObjRecord.Business_Card_Title__c != null && customObjRecord.Business_Card_Title__c !='')
                        l1.Title=customObjRecord.Business_Card_Title__c;
                    if (customObjRecord.Primary_Address_Street__c != null && customObjRecord.Primary_Address_Street__c !='')
                        l1.Street=customObjRecord.Primary_Address_Street__c;
                    if (customObjRecord.Primary_Address_City__c != null && customObjRecord.Primary_Address_City__c !='')
                        l1.City=customObjRecord.Primary_Address_City__c;
                    if (customObjRecord.Primary_Address_State__c != null && customObjRecord.Primary_Address_State__c !='')
                        l1.State=customObjRecord.Primary_Address_State__c;
                    if (customObjRecord.Primary_Address_Country__c != null && customObjRecord.Primary_Address_Country__c !='')
                        l1.Country=customObjRecord.Primary_Address_Country__c;
                    if (customObjRecord.Primary_Address_Postal_Code__c != null && customObjRecord.Primary_Address_Postal_Code__c !='')
                        l1.PostalCode=customObjRecord.Primary_Address_Postal_Code__c;
                      Boolean campCrtFlag = true;
                        for (Campaign camp: camprecds){
                            if(camp.Name==customObjRecord.Campaign__c){
                                for(CampaignMember cm: camp.CampaignMembers){
                                    if(cm.LeadId==l1.Id){
                                        campCrtFlag=false;
                                    }
                                }
                                if(campCrtFlag){
                                    CampaignMember cm = new CampaignMember(CampaignId = camp.Id, LeadId = l1.Id,
                                                                           status = customObjRecord.Member_Status__c);
                                    campMemcre.add(cm);
                                }
                            }
                        }
                    uplead.add(l1); // Update the existing record in Leads
                } else if (customObjRecord.Email_Address__c != l.email  && (customObjRecord.Office_Phone__c == l.phone &&
                        customObjRecord.Office_Phone__c != '' && customObjRecord.Office_Phone__c != null)) // If phone numbers are same
                {
                    leadCrtFlag = false;
                    lead l2 = l;
                    if (customObjRecord.Name != null && customObjRecord.Name != '') // Update LastName field when new Name field value is not empty .
                        l2.LastName = customObjRecord.Name;
                    if (customObjRecord.First_Name__c != null && customObjRecord.First_Name__c != '')
                            l2.FirstName = customObjRecord.First_Name__c;
                    if (customObjRecord.Email_Address__c != null && customObjRecord.Email_Address__c != '')
                        l2.Email = customObjRecord.Email_Address__c;
                    if (customObjRecord.Business_Card_Company__c != null && customObjRecord.Business_Card_Company__c !='')
                        l2.Company = customObjRecord.Business_Card_Company__c;
                    if (customObjRecord.Business_Card_Title__c != null && customObjRecord.Business_Card_Title__c !='')
                        l2.Title=customObjRecord.Business_Card_Title__c;
                    if (customObjRecord.Primary_Address_Street__c != null && customObjRecord.Primary_Address_Street__c !='')
                        l2.Street=customObjRecord.Primary_Address_Street__c;
                    if (customObjRecord.Primary_Address_City__c != null && customObjRecord.Primary_Address_City__c !='')
                        l2.City=customObjRecord.Primary_Address_City__c;
                    if (customObjRecord.Primary_Address_State__c != null && customObjRecord.Primary_Address_State__c !='')
                        l2.State=customObjRecord.Primary_Address_State__c;
                    if (customObjRecord.Primary_Address_Country__c != null && customObjRecord.Primary_Address_Country__c !='')
                        l2.Country=customObjRecord.Primary_Address_Country__c;
                    if (customObjRecord.Primary_Address_Postal_Code__c != null && customObjRecord.Primary_Address_Postal_Code__c !='')
                        l2.PostalCode=customObjRecord.Primary_Address_Postal_Code__c;
                     Boolean campCrtFlag = true;
                        for (Campaign camp: camprecds){
                            if(camp.Name==customObjRecord.Campaign__c){
                                for(CampaignMember cm: camp.CampaignMembers){
                                    if(cm.LeadId==l2.Id){
                                        campCrtFlag=false;
                                }
                                }
                                if(campCrtFlag){
                                    CampaignMember cm = new CampaignMember(CampaignId = camp.Id, LeadId = l2.Id,
                                                                           status = customObjRecord.Member_Status__c);
                                    campMemcre.add(cm);
                                }
                            }
                        }
                    uplead.add(l2); // Update the existing record in Leads
                } else if ((customObjRecord.Email_Address__c == l.email && customObjRecord.Email_Address__c != '' &&
                        customObjRecord.Email_Address__c != null) && (customObjRecord.Office_Phone__c == l.phone &&
                        customObjRecord.Office_Phone__c != '' && customObjRecord.Office_Phone__c != null)) //  phone numbers & Email Ids are same
                {
                    leadCrtFlag = false;
                    lead l3 = l;
                    if (customObjRecord.Name != null && customObjRecord.Name != '') // Update LastName field when new Name field value is not empty .
                        l3.LastName = customObjRecord.Name;
                    if (customObjRecord.First_Name__c != null && customObjRecord.First_Name__c != '')
                         l3.FirstName = customObjRecord.First_Name__c;
                    if (customObjRecord.Business_Card_Company__c != null && customObjRecord.Business_Card_Company__c !='')
                        l3.Company = customObjRecord.Business_Card_Company__c;
                    if (customObjRecord.Business_Card_Title__c != null && customObjRecord.Business_Card_Title__c !='')
                        l3.Title=customObjRecord.Business_Card_Title__c;
                    if (customObjRecord.Primary_Address_Street__c != null && customObjRecord.Primary_Address_Street__c !='')
                        l3.Street=customObjRecord.Primary_Address_Street__c;
                    if (customObjRecord.Primary_Address_City__c != null && customObjRecord.Primary_Address_City__c !='')
                        l3.City=customObjRecord.Primary_Address_City__c;
                    if (customObjRecord.Primary_Address_State__c != null && customObjRecord.Primary_Address_State__c !='')
                        l3.State=customObjRecord.Primary_Address_State__c;
                    if (customObjRecord.Primary_Address_Country__c != null && customObjRecord.Primary_Address_Country__c !='')
                        l3.Country=customObjRecord.Primary_Address_Country__c;
                    if (customObjRecord.Primary_Address_Postal_Code__c != null && customObjRecord.Primary_Address_Postal_Code__c !='')
                        l3.PostalCode=customObjRecord.Primary_Address_Postal_Code__c;
                    
                    Boolean campCrtFlag = true;
                        for (Campaign camp: camprecds){
                            if(camp.Name==customObjRecord.Campaign__c){
                                for(CampaignMember cm: camp.CampaignMembers){
                                    if(cm.LeadId==l3.Id){
                                        campCrtFlag=false;
                                    }
                                }
                                if(campCrtFlag){
                                    CampaignMember cm = new CampaignMember(CampaignId = camp.Id, LeadId = l3.Id,
                                                                           status = customObjRecord.Member_Status__c);
                                    campMemcre.add(cm);
                                }
                            }
                        }
                    uplead.add(l3); // Update the existing record in Contacts
                }
            }
            
            if (leadCrtFlag) // Email & Phone both are different
                {
                    System.debug('lead: Both are Different');
                    count1=01;
                    lead l4 = new lead();
                    l4.LastName = customObjRecord.Name;
                    l4.FirstName = customobjrecord.First_Name__c;
                    l4.MobilePhone = customObjRecord.Other_Phone__c;
                    l4.Email = customObjRecord.Email_Address__c;
                    l4.Phone = customObjRecord.Office_Phone__c;
                    l4.Company = customObjRecord.Business_Card_Company__c;
                    l4.Title=customObjRecord.Business_Card_Title__c;
                    l4.Street=customObjRecord.Primary_Address_Street__c;
                    l4.City=customObjRecord.Primary_Address_City__c;
                    l4.State=customObjRecord.Primary_Address_State__c;
                    l4.Country=customObjRecord.Primary_Address_Country__c;
                    l4.PostalCode=customObjRecord.Primary_Address_Postal_Code__c;
                    l4.External_Lead_Id__c='Ext'+count1+customObjRecord.Office_Phone__c;
                    System.debug('Ext'+count1+customObjRecord.Office_Phone__c);
                    inlead.add(l4); // Create new Lead
                    for (Campaign camp: camprecds){
                            if(camp.Name==customObjRecord.Campaign__c){
                                    String extname='Ext'+count1+customObjRecord.Office_Phone__c;
                                    Lead lnew=new Lead(External_Lead_Id__c=extname);
                                    CampaignMember cm = new CampaignMember(CampaignId = camp.Id, Lead = lnew,
                                                                           Status=customobjrecord.Member_Status__c);
                                    campMemcre.add(cm);
                                
                            }
                        }
                    count1++;
                }
            
        }
    }

        System.debug('New Contacts'+incon);
    if (inlead.size() > 0){
        Database.saveResult[] rslt=Database.insert(inlead, false);
        for(Database.saveResult r: rslt){
            if(r.isSuccess()){
                System.debug(r.getId());
            }
            else{
                System.debug(r.getErrors());
            }
        }
    }
        
    if (uplead.size() > 0){
        Database.saveResult[] rslt=Database.update(uplead, false);
        for(Database.saveResult r: rslt){
            if(r.isSuccess()){
                System.debug(r.getId());
            }
            else{
                System.debug(r.getErrors());
            }
        }
    }
    if (campMemUpd.size() > 0){
        Database.saveResult[] rslt=Database.update(campMemUpd, false);
        for(Database.saveResult r: rslt){
            if(r.isSuccess()){
                System.debug(r.getId());
            }
            else{
                System.debug(r.getErrors());
            }
        }
    }
    
    }
}


 
school__c -->customObject
studentjoinage =system.today() - createddate; //its formula field which riturn number.
I written the batchclass,in that   if(sch.studentjoinage__c==30) then send an email.
test.starttest
   mybatchcls mb=new mybatchcls();
   database.execute();
test.stoptest;
i get 40% codecoverage, in that start method ,finish methods r coverd but in execute method after if condition which means
messaging.singleemailmessage not coverd bcoze formula field.
i need help here to cover formula field.   
Please check my below code and suggest for the same.
Page:
<apex:page standardController="FeedLinks__c" extensions="JSONParserUtil"   showheader="false" sidebar="false">
 <apex:pageBlock title="Feed News">
       <apex:pageMessages /><apex:outputText value="{!responsemsg}" />
             </apex:pageBlock>
  </apex:page>
Controller:
public class JSONParserUtil {

    public String jsonvalue { get; set; }
     public List<FeedLinks__c> lstlink{get;set;}
    public String responsemsg { get; set; }
   
    public JSONParserUtil(ApexPages.StandardController controller) {
    responsemsg='';
this.parseJSONResponse();
    }
 
    public void parseJSONResponse() {        
        Http httpProtocol = new Http();
        // Create HTTP request to send.
        HttpRequest request = new HttpRequest();
        // Set the endpoint URL.
        String endpoint = 'https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=89edf61c78424b0a8dcafc4f9739f031';
        request.setEndPoint(endpoint);
        // Set the HTTP verb to GET.
        request.setMethod('GET');
        // Send the HTTP request and get the response.
        // The response is in JSON format.
        HttpResponse response = httpProtocol.send(request);
        System.debug(response.getBody());
        if (response.getStatusCode() == 200) {
      JSONParser parser = JSON.createParser(response.getBody());
        system.debug('Parser='+parser);
        lstlink=new List<FeedLinks__c>();
        
        while (parser.nextToken() != null) {
            responsemsg+= parser.gettext();
             parser.nextToken();
             
                }
              system.debug('response msg='+responsemsg);
                
            }
        } 
        public class jsonvalue{
        
         public String title{get;set;}
         Public String description {get;set;}
        
        }
}
I am geeting Http response  like:
{"status":"ok","source":"the-next-web","sortBy":"latest","articles":[{"author":"Rachel Kaser","title":"Donuts delivered via drone is the future we all imagined","description":"This Wednesday, a Denver-based bakery, in collaboration with Texas-based company Drone Dispatch, delivered fresh donuts to the Denver city officials via drone. Recipients include policemen, ...","url":"https://thenextweb.com/insider/2017/06/01/donuts-delivered-via-drone-future-imagined/","urlToImage":"https://cdn0.tnwcdn.com/wp-content/blogs.dir/1/files/2017/06/Drone-donuts.jpg","publishedAt":"2017-06-01T03:13:11Z"},
 I am geeting Vf page output like:
{okthe-next-weblatest[authortitledescriptionurlurlToImagepublishedAt}
Excepted output format  should be like;
tille:Donuts delivered via drone is the future we all imagined
description:This Wednesday, a Denver-based bakery, in collaboration with Texas-based company Drone Dispatch, delivered fresh donuts to the Denver city officials via drone. Recipients include policemen
url:https://thenextweb.com/insider/2017/06/01/donuts-delivered-via-drone-future-imagined/
publishedAt:2017-06-01T03:13:11Z