• ziaullahkhaksar
  • NEWBIE
  • -1 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 12
    Replies

Hi everyone,

 

I just started using couple months ago and now have just started exploring triggers.

I am looking to create new lead records after case has been closed if it fulfills certain criterias.

Hope someone could help me out here; details are as below.

 

To create new Lead record when from Case object:-

 

Status=Closed

and

Receive_survey_form_future_promotions__c=True

and

(E_mail_c or SuppliedEmail)!=null

 

The Lead record field name mapping for insertion are as follows:-

From Case object ==> To Lead object

Name_c or SuppliedName ==> LastName

E_mail_c or SuppliedEmail ==> Email

Contact_Number__c ==> MobilePhone

 

Lead status will always be New.

Lastly, the lead will only be created if a search based on the email from (E_mail_c or SuppliedEmail) isn't existant in any Lead records.

 

Hope to hear from someone and thanks in advance.

 

P.S. Just wondering, can an email message be triggered to a particular default email if the Lead record isn't created due to its existance in Lead already?

 

Regards,

Ravin

  • February 21, 2012
  • Like
  • 0
Hi All I am trying run the scheduler every minuter and it does not seem to run and and not able to see the instance in the logs . Is there any we need to start the scheduler /or any other setting needs to be done . How will this scheduler be called ? Help really appreciated ., below is the code Tom global class Scheduled_Account_Migrate { global void execute(SchedulableContext SC) { Migrate_Account_Class_Batch Acc = new Migrate_Account_Class_Batch(); // Acc.setPCAccount(); String sch = '0 * * * * * *'; system.schedule('Merge Job', sch, Acc); } }

Hi,

 

Can i acess java script varible value in a VF page Controller Apex class.

 

Suppose in my VF page , a java script variable   " var a='some thing'" . Now i want to store this variable in a Apex Controller class varible...

 

Is it possible...?

 

  • October 17, 2011
  • Like
  • 0

Hi,

I am a beginner with apex scheduling and I want to send email to the contacts on their respective birthdays.

I have developed a code but somehow it is not working.

Any help or suggestion appreciated. Thank you in advance.

 

******************************************************************************

Code  -

******************************************************************************

global class ContactmailScheduler implements Schedulable
{
    global void execute(SchedulableContext ctx)
    {
           SendMassEmail Objsme = new SendMassEmail();
           Objsme.sendmail();
    }     
        
}

******************************************************************************

public with sharing class SendMassEmail   
{
    List<Id> ConIdList = new List<Id>();
        
    public void sendmail()
    {
        ContactmailScheduler nd = new ContactmailScheduler();  
        String asd = '0 0 13 * * ?';
        System.schedule('Send mail',asd,nd);
    
        List<Contact> cntlst = [Select c.Birthdate,c.Id,c.Name from Contact c where c.active__c =true AND
        c.Birthdate = THIS_MONTH ];
          
          if(cntlst.Size()> 0 )
        {
            for(Contact objCon : cntlst )
              {    
                  if(objCon.Birthdate.day()== Date.today().day())
                   ConIdList.add(objCon.Id);
              }
        }
            
        Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
        mail.setTargetObjectIds(ConIdList);
        mail.setTemplateId('00X90000000SuQ8');
        mail.setUseSignature(true);
        Messaging.sendEmail(new messaging.Massemailmessage[] {mail});    
    }
                
}

  • June 02, 2011
  • Like
  • 0

Hi,

 

I've been trying to deploy something but I keep getting the following error:

 

Failure Message: "System.NullPointerException: Attempt to de-reference a null object", Failure Stack Trace: "Class.callOut.main: line 70, column 13 External entry point"

 

line 70:

 

 

if (getLead.Web_Form_Source__c.substring(0, 2) == 'X0') {

 code:

 

 

public class callOut {
public static boolean isApexTest=false;
    public static HttpRequest buildWebServiceRequest(String pid, String gid, String pass, String getLead, String password){
        // Build the XML Request
        string body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:reg="http://webservice">' +
                          '<soapenv:Header/>' +
                          '<soapenv:Body>' +
                              '<reg:RegisterUserWithAutoId>' +
                                  '<reg:partnerID>'+pid+'</reg:partnerID>' +
                                  '<reg:partnerGuid>'+gid+'</reg:partnerGuid>' +
                                  '<reg:partnerPassword>'+pass+'</reg:partnerPassword>' +
                                  '<reg:clientName>'+getLead+'</reg:clientName>' +
                                  '<reg:clientPassword>'+password+'</reg:clientPassword>' +
                              '</reg:RegisterUserWithAutoId>' +
                          '</soapenv:Body>' +
                      '</soapenv:Envelope>';
        system.debug(body);

        //construct an HTTP request
        HttpRequest req = new HttpRequest();
        req.setHeader('content-type', 'text/xml; charset=utf-8');
        req.setHeader('Host','mitsweb.iitech.dk');
        req.setEndpoint('http://webservice');
        req.setMethod('POST');
        req.setBody(body); 
        return req;
    }
    
    public static String invokeWebService(Http h, HttpRequest req){
        //Invoke Web Service
        if(!isApexTest)
        {
        try{
        HttpResponse res = h.send(req);
        return res.getBody();
        }
        catch(Exception e){
        throw e;
        }
        }
        else{
        return '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><RegisterUserWithAutoId_testResponse xmlns="webservice"><RegisterUserWithAutoId_testResult><registrationResponse clientid="0" success="True" xmlns=""><clientName value="getLead" success="True" errorCode="0"/><password success="True" errorCode="0"/><loginName value="0" success="True" errorCode="0"/></registrationResponse></RegisterUserWithAutoId_testResult></RegisterUserWithAutoId_testResponse></soap:Body></soap:Envelope>';}
    }
    
    public static void handleWebServiceResponse(string xml, String password, String id){
        //Parse and apply logic to the res message
                    //string xml = res.getBody();
            string xmlRegex = '^.*clientid="';
            pattern xmlPattern = pattern.compile(xmlRegex);
            matcher xmlMatcher = xmlPattern.matcher(xml);
            List<String> result = xml.split(xmlRegex);
            List<String> result2 = result[1].split('\"');
            
            
            Lead getLead = [select id,name,email,Web_Form_Source__c from lead where id = :id];
            
            getLead.ClientPassword__c = password;
            getLead.ClientID__c = result2[0];
            update getLead;
      
            //send email
            SendMail.newLead(getLead.id, getLead.email, getLead.Web_Form_Source__c);          
    }
    
    @Future(callout=true)
    public static void main(Id id){
        
        Lead getLead = [select name,email,Web_Form_Source__c from lead where id = :id];
        
        if (getLead.Web_Form_Source__c.substring(0, 2) == 'X0') {
            string password = EncodingUtil.convertToHex(Crypto.generateDigest('MD5',Blob.valueOf(getLead.name + Crypto.getRandomInteger()))).substring(0, 8);
            
            String pid;
            String gid;
            String pass;
            
            //apply business logic
            if        (getLead.Web_Form_Source__c == 'X00001' || 
                       getLead.Web_Form_Source__c == 'X00002' ||
                       getLead.Web_Form_Source__c == 'X00003') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
            
            // 4293938 Citi Bank Retail 1-2011
            } else if (getLead.Web_Form_Source__c == 'X00014' ||
                      getLead.Web_Form_Source__c == 'X00015' ||
                      getLead.Web_Form_Source__c == 'X00016') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
                         
            // 4293946 Citi Bank Retail 2-2011
            } else if (getLead.Web_Form_Source__c == 'X00017' ||
                      getLead.Web_Form_Source__c == 'X00018' ||
                      getLead.Web_Form_Source__c == 'X00019') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
                         
            // 4293948 Citi Bank Retail3-2011 Fee Based
            } else if (getLead.Web_Form_Source__c == 'X00020' ||
                      getLead.Web_Form_Source__c == 'X00021' ||
                      getLead.Web_Form_Source__c == 'X00022') {
                         pid = 'xxxx';
                         gid = 'xxxx';
                         pass = 'xxxx';
            }
            
            //now need to make web service callout

            //build the http request
            Http h = new Http();
            HttpRequest req = buildWebServiceRequest(pid, gid, pass, getLead.name, password);
   
            //invoke web service call 
            string xmlres = invokeWebService(h, req);
   
            //handling the response
            handleWebServiceResponse(xmlres, password, id);    
        }
    }
    
    static testMethod void testWebService(){
        //build the http request
        isApexTest=true;
        Lead l = new Lead();
        l.Email='test@test.com';
        l.Web_Form_Source__c='X00001';
        l.LastName='LastName';
        insert l;
    }
}

 

Someone please help me, I can't figure out what's wrong.

 

 

 

Can any one give sample example on schedule apex class???

Hi Friends,

 

I have similar code to update no. of contacts in Account for Contacts insert and deletion but only got error message "Attempt to de-reference a null object".  Who can tell me why?  Thanks.

 

Code for update

 

trigger UpdateAccountNoOfBabiesbeforedeleteContact on Contact (before delete) {
    Contact[] tempnew = trigger.new;
    for(integer i =0; i<tempnew.size();i++){
        list<Account> accountList = [Select id,No_of_Contacts__c from Account where id = :tempnew[i].Account.id];
        for(Account c : accountList){
            if(c.No_of_Contacts__c ==NULL){
                c.No_of_Babies__c = 0;}
                else {
                integer tempint = integer.valueof(string.valueof(c.No_of_Contacts__c));
                tempint--;
                c.No_of_Contacts__c = decimal.valueof(tempint);
                update c;
            }//end else
        }//end for
     }//end for
}

Hi there.
I was wondering could anyone help me out.
Im trying to send an email when a visualforce page is loaded.
I have changed the email addresses for the purpose of this post.
 
Basically I have a simple visualforce page which consists of:
 
<apex:page controller="EmailCardListController" action="sendMail" title="Email Card List">
   <apex:outputText value="{!emailSent}" />
</apex:page>
 
and a relatively simple controller that sends an email (taken pretty much from the Apex pdf guide)
 
public class EmailCardListController {
    //Did the email send successfully?
    public Boolean emailSent { get; set; }
    //Create the email handler;
    public Messaging.SingleEmailMessage mailHandler = new Messaging.SingleEmailMessage();
   
    //The recipient
    String[] emailRecipient = new String[] {'jbloggs@acme.com'};
    public void sendMail() {
   
        //set the recipient
        mailHandler.setToAddresses(emailRecipient);
       
        //set the reply email address
        mailHandler.setReplyTo('jbloggs@acme.com');
       
        //set the display name
        mailHandler.setSenderDisplayName('Keith Nixon');
       
        //set the subject
        mailHandler.setSubject('Card List');
       
        //set the template ID
        //mailHandler.setTemplateId('00X200000015XFL');
       
        mailHandler.setHtmlBody('This is a simple email from me');
       
        try {
            Messaging.sendEmail(new Messaging.Email[] { mailHandler });
            emailSent = true;
        }catch(EmailException e) {
            System.debug(e.getMessage());
            emailSent = false;
        }
    }  
}
 
Unfortunately when I call up the VisualForce page, I get the following error:
 
Illegal view ID sendMail. The ID must begin with /
 
 
  • November 26, 2008
  • Like
  • 0
I am creating a visualforce page for leads.

I have the following in my controller:

Code:
Lead lead;

public Lead getLead(){
    if(lead == null) lead = [select id, name, Persona__c from Lead where id= :ApexPages.currentPage().getParameters().get('id')];
    return lead;
}

public List<Question__c> getQuestions(){
    return [select id, Question_Value__c from Question__c where Persona__c = :lead.Persona__c];
}

 Now on the Page it shows the Question ids if I just put {!Questions}.

But as soon as I try to put the questions into a pageblock I get the error: System.NullPointerException: Attempt to de-reference a null object. The error points to the return statement in the last method above.

Here is the section of the page:

Code:
<apex:pageBlockTable value="{!Questions}" var="q">
             <apex:column value="{!q.Question_Value__c}"/>
         </apex:pageBlockTable>

 
Any idea how to put the data into a table appropriately?