• ankur khattri
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 21
    Questions
  • 39
    Replies
I have a custom page.There is a link lookup field.On click of that link popup appears then i select a field to be used it is not able to fetch on button click.Did i miss anything?
Here is my code below:-
JAVASCRIPT
<script type="text/javascript">
        function OpenServicePopup(winUrl)
        {
            var searchBoxValue = document.getElementById('lksrch').value;
            var finalUrl = winUrl+"&lksrch="+searchBoxValue;
            var newwindow=window.open(finalUrl,'popup','height=400,width=400,scrollbars=yes');
            newwindow.focus();
            return false; 
        }
    </script>
VISUALFORCE PAGE
<apex:commandLink value="Add" style="width:100px;" onclick="OpenServicePopup('/apex/lookuppage?woID='+'{!parentWoId}');"/> 
global class EmailReceive implements Messaging.InboundEmailHandler
 {
 
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
                                                       Messaging.InboundEnvelope env){
 
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    
    
    String[] emailBody = email.plainTextBody.split('\n');
    system.debug('------------emailbody------'+emailBody);
    //String firstName = emailBody[0].substring(5);
    String lastName= emailBody[0].substring(2);
    String phoneNumber = emailBody[0].substring(6);
    String city = emailBody[0].substring(6);
    String status = emailBody[0].substring(3);
    String company= emailBody[0].substring(2);
    Lead[] newLead = new Lead[0];
     try {
     if (newLead .size() == 0)
    {
       newLead.add(new Lead(LastName = lastName,Phone = phoneNumber, City = city,Company=company ));
       insert newLead;        
    }
    }
   catch (QueryException e) {
       
   }
   
   result.success = true;
   return result;
  }
}
disable value of the picklist if that value is selected.
i have 10 picklist and they have same value.i want that if one value is selected from the first picklist then it should get disable from other picklists.
there is a mass update button in the cases.And when mass update button is clicked the fliter criteria changes for eg:-if we select all cases then it changes to all open cases.Is there any way to keep the same view after mass update is done(there is a button of mass update in js.)
<apex:page >
    <head>
        <meta name = "viewport" content = "width=device-width, initial-scale=1"/>
        <link href = "css/bootstrap.css" rel = "stylesheet" type = "text/css"/>
        <link href="css.css" rel="stylesheet" type="text/css"/>
        <link rel = "stylesheet" href = "http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"/>
        <link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'/>
        <title>Comment Box</title>
    </head>
    
    <html style="height: 100%;">
        <head>
            <meta name = "viewport" content = "width=device-width, initial-scale=1"/>
            <link href = "css/bootstrap.css" rel = "stylesheet" type = "text/css"/>
            <link href="css.css" rel="stylesheet" type="text/css"/>
            <link rel = "stylesheet" href = "http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"/>
            <link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'/>
            
             <style>
                 #p.ex {
                height: 1034px;
                width: 100px;
                }
                 #body {
                width: 1054px;
                height: 1054px;
                background-color: #F4F4F4;
                }
                #wrap{
                border: 1px solid lightgray;
                alignment-adjust: central;
                width: 1000px;
                margin-left: 50px;
                margin-top: 10px;
                padding-bottom: 50px;
                }
                h1{
                /*color: blue-violet;*/
                text-align: center;
                }
                
                h3.heading{
                margin-left: 20px;
                background-color: #fafafa;
                font-size: 25px;
                float: left;
                padding-left: 40px;
                position: relative;
                width: 405px;
                height: 40px;
                padding-top: 5px;
                
                }
                /*#upper_blank{
                border-bottom: 3px solid #ee5d10;
                margin-top: 40px;
                margin-right: 480px;
                width: 520px;
                padding-right: 480px;
                }*/
                #name{
                margin-left: 20px;
                box-shadow: 0 2px 0 #e6e6e6;
                height: 40px;
                padding-left: 10px;
                width: 500px;
                }
                #name2{
                margin-left: 20px;
                padding-left: 10px;
                height:50px ;
                width:50px ;
                }
                #email{
                margin-left: 20px;
                box-shadow: 0 2px 0 #e6e6e6;
                height: 40px;
                padding-left: 10px;
                width: 500px;
                }
                #url{
                margin-left: 20px;
                box-shadow: 0 2px 0 #e6e6e6;
                height: 40px;
                padding-left: 10px;
                width: 500px;
                }
                #comment{
                margin-left: 20px;
                box-shadow: 0 2px 0 #e6e6e6;
                height: 40px;
                padding-left: 10px;
                width: 650px;
                height: 200px;
                }
                #commentSubmit{
                margin-left: 20px;
                width: 100px;
                height: 30px;
                color: white;
                font-size: 10px;
                background-color: #ee5d10;
                margin-bottom: 30px;
                padding-left: 10px;
                border-radius: 0px;
                }
                #commentSubmit:hover {
                background-color: #d65e1f;
                }
                h3.second_heading{
               /* margin-left: 0;
                margin-top: 30px;
                font-size: 20px;
                width: 250px;
                height: 50px;
                padding-top: 10px;
                padding-left: 55px;*/
                
                margin-left: 900px;
                margin-top: 100px;
                padding-top: 0px;
                padding-left: 0px;
                width: 30px;
                height: 10px;
                background-color: #ee5d10;
                align: right;
                font-size: 10px;
                color: white;
                border-radius: 0px;
                }
                #middle{
                border: 1px solid lightgray;
                width: 1000px;
                height: 200px;
                background-color: #F7F7F7;
                margin-left: 45px;
                text-align: left;
                margin-top: 10px;
                }
                .blank{
                border-bottom: 3px solid #ee5d10;
                margin-top: 40px;
                margin-left: 50px;
                margin-right: 480px;
                width: 520px;
                padding-right: 480px;
                }
                #inner_reply{
                margin-left: 800px;
                margin-top: 160px;
                width: 100px;
                height: 30px;
                background-color: #ee5d10;
                text-align: center;
                font-size: 18px;
                color: white;
                border-radius: 8px;
                }
            </style>
            
            <script>
                   function previewFile()
                   {
                   var preview = document.querySelector('img'); //selects the query named img
                   var file    = document.querySelector('input[type=file]').files[0]; //sames as here
                   var reader  = new FileReader();
                   reader.onloadend = function ()
                   {
                   preview.src = reader.result;
                   }
                   if (file)
                   {
                       reader.readAsDataURL(file); //reads the data as a URL
                   } else
                   {
                   preview.src = "";
                   }
                  }
                  previewFile();  //calls the function named previewFile()
                  </script>
            
        </head>
        <body style="height: 100%;">
            <!------------container------->
            
            <div class="container">
            
            <!-------Wrap------------>
            <div id="wrap">
           
            <div class="row">
            <div class="col-md-5">
            </div>
            <div class="col-md-7">
            <div id="upper_blank"></div>
            </div>
            </div>
            
            
            <!------------Form Start---------->
            
            <div id='form'>
            <div class="row">
            <div class="col-md-12">
            
            <form action="" method="POST" id="commentform">
            
            <input type="file" onchange="previewFile()"/><br></br>
            <img src="" alt="Image preview..." id="name2"/>
            
            <div id="comment-name" class="form-row">
            <input type = "text" placeholder = "Name (required)" name = "dname"  id = "name" />
            </div>
            <div id="comment-message" class="form-row">
            <textarea name = "comment" placeholder = "Message" id = "comment" ></textarea>
            </div>
            <a href="#"><input type="submit" name="dsubmit" id="commentSubmit" value="Submit Comment"/></a>
 
            </form>
            
            </div>
            </div>
            </div>
            </div>
            
            <!-------------------Reply Section------->
            <div id="second">
            <div class="row">
            <div class="col-md-2">
            <h3 class="second_heading">Q&amp;A</h3>
            </div>
            <div class="col-md-10">
            <div class="blank"></div>
            </div>
            </div>
            </div>
            <div id="middle">
            <form>
            <a href="#"><input type = "text" value = "reply" name = "dreply" id = "inner_reply"/></a>
            </form>
            </div>
            
            </div>
        </body>
    </html>
    
</apex:page>
public with sharing class ChildCloneHandler implements ITrigger
{       
    Map<Id,Account> accountMap = new Map<Id,Account>();
    Map<Id,list<Contact>> lstMap = new Map<Id,list<Contact>>();
    list<Account> lstAccount = new list<Account>();
    set<Id> acctIds = new set<Id>();
    Set<Id> tobeReverted = new Set<Id>();
    public string errString;
    //list<id> lstAccountId = new  list<id>();
    //list<Account> accToInsert = new list<Account>();
    //list<Contact> conToInsert = new list<Contact>();
    //list<Contact> cont = new list<Contact>();
    
    public ChildCloneHandler()
    {
         
    }
    public void beforeUpdate(SObject oldSo, SObject so)  
    {
        
    }
    public void bulkBefore()
    {
        
    }
    public void bulkAfter()
    {
        //checkin if it is update
        if(Trigger.new != null)
        {
        if(Trigger.IsUpdate)
        {
            system.debug('----chhh-----');
            Set<id> setid = new Set<id>();
            //iterating over Account
            for(SObject Item:Trigger.new)
            {
                Account acc = (Account) Item;
                if(Trigger.oldMap.containsKey(acc.Id))
                {
                    Account oldAcc = (Account) Trigger.oldMap.get(acc.Id);
                    //if field is updated or not if yes then we will collect the id for further process
                    if(oldAcc.ChildClone__c == false && acc.ChildClone__c == true)
                    {
                        setid.add(acc.id);
                    }
                }
            }
            //retriving field that is updated ChildClone__c
            lstAccount = [select id,Name, Description,Type, Phone, Fax,
            AccountNumber,BillingAddress,Industry,(select LastName,
            Title,Department,Birthdate,MailingAddress,Languages__c,Level__c
            from Contacts) from Account where id IN: setid];
            
            for(Account a : lstAccount)
            {
                if(a.Contacts != null && a.Contacts.size()>0)
                {
                    //storing value in map for id and contact
                    lstMap.put(a.id, a.Contacts);
                }
            }
        }
        }
    }
    public void beforeInsert(SObject so)
    {
        
    }   
    public void beforeDelete(SObject so)
    {
        
    }
    public void afterInsert(SObject so)
    {
    
    }
    public void afterUpdate(SObject oldSo, SObject so)
    {
         Account OrderRecOld = (Account) oldSo;
         Account OrderRecNew = (Account) so;
         //checking if ChildClone__c was false and is true after update
         if(OrderRecOld.ChildClone__c == false && OrderRecNew.ChildClone__c == true)
         {
            //clonning account and contacts
            Account clonedAcc = OrderRecNew.clone(false);
            clonedAcc.ChildClone__c = false;
            //accToInsert.add(clonedAcc);
            //link old account and new account to compare their child(contacts)
            accountMap.put(OrderRecNew.id, clonedAcc);  
            
         }
    }
    public void afterDelete(SObject so)
    {
        
    }
    public void andFinally()
    {
        //insert accToInsert;
        //cloned account to be inserted
        if(accountMap.values().size()>0 )
        {   
            //result of an insert or update DML operation is returned by a Database method.
            Database.SaveResult[] srList1 = Database.insert(accountMap.values(), false);
            Integer i = 0;
            for(Id id : accountMap.KeySet())
            {
                // Returns a Boolean that is set to true if the DML operation was successful for this object, false otherwise.
                if (srList1[i].isSuccess() == false)
                {
                    // Operation was successful, so get the ID of the record that was processed
                    //System.debug('Successfully inserted account. Account ID: ' + id.getId());
                    errString += 'Error with record '+id+': '+srList1[i].getErrors()[0].getMessage()+'</br>';
                    //To remove elements while iterating a list, create a new list, then copy the elements you wish to keep. Alternatively, add the elements you wish to remove to a temporary list and remove them after you finish iterating the collection.
                    accountMap.remove(id);
                    //To add elements while iterating a list, set or map, keep the new elements in a temporary list, set, or map and add them to the original after you finish iterating the collection.
                    tobeReverted.add(id);
                }
                //loop for the contacts
                 i++;
            }
            //list for the contacts to be inserted
            list<Contact> conListToBeInserted = new list<Contact>();
            // (keyset)Returns a set that contains all of the keys in the map.
            //When executing loop,the Apex runtime engine assigns variable to each element in list_or_set, and runs the code_block for each value.
            for(id i1 : accountMap.keySet())
            {
                //clonedAcc
                Account clonedAcc = accountMap.get(i1);
                system.debug('----aba-----'+clonedAcc.id);
                // retrieve items.....storing value in map for id and contact    
                list<Contact> toBeClonedCon = lstMap.get(i1);
                for(Contact c : toBeClonedCon)
                {
                    Contact conToClone = new Contact();
                    // false to deep clone
                    conToClone = c.clone(false);
                    conToClone.AccountId = clonedAcc.id;
                    conListToBeInserted.add(conToClone);
                }
            }
            system.debug('----aba1-----'+conListToBeInserted);
            if(conListToBeInserted != null && conListToBeInserted.size()>0)
            {
                
                //insert contacts;
                //insert conListToBeInserted;
                Database.SaveResult[] srList = Database.insert(conListToBeInserted, false);
                // Iterate through each returned result
                for (Database.SaveResult sr : srList)
                {
                    if (sr.isSuccess())
                    {
                        // Operation was successful, so get the ID of the record that was processed
                        System.debug('Successfully inserted account. Account ID: ' + sr.getId());
                    }
                    else
                    {
                        // Operation failed, so get all errors                
                        for(Database.Error err : sr.getErrors())
                        {
                            System.debug('The following error has occurred.');                    
                            System.debug(err.getStatusCode() + ': ' + err.getMessage());
                            System.debug('Account fields that affected this error: ' + err.getFields());
                        }
                    }
                }
            }
            
            if(errString != '')
            {
                system.debug('----asasasa---'+accountMap);
                //reverting  Orginal Accounts updates when exception occurs while cloning them
                HelperClass.updateAccount(tobeReverted);
                //deleting Cloned Accounts when their Product has exception while creation
                If(accountMap != null && accountMap.values().size() > 0)
                delete accountMap.values();
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresses = new String[] {'ankur.khattri@cynoteck.com'};
                mail.setToAddresses(toAddresses);
                //mail.setBccSender(false);
                mail.setSubject('subject');
                mail.setHtmlBody(errString);
                Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
            }
        }
    }
}
I have a custom page.There is a link lookup field.On click of that link popup appears then i select a field to be used it is not able to fetch on button click.Did i miss anything?
Here is my code below:-
JAVASCRIPT
<script type="text/javascript">
        function OpenServicePopup(winUrl)
        {
            var searchBoxValue = document.getElementById('lksrch').value;
            var finalUrl = winUrl+"&lksrch="+searchBoxValue;
            var newwindow=window.open(finalUrl,'popup','height=400,width=400,scrollbars=yes');
            newwindow.focus();
            return false; 
        }
    </script>
VISUALFORCE PAGE
<apex:commandLink value="Add" style="width:100px;" onclick="OpenServicePopup('/apex/lookuppage?woID='+'{!parentWoId}');"/> 
global class EmailReceive implements Messaging.InboundEmailHandler
 {
 
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
                                                       Messaging.InboundEnvelope env){
 
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    
    
    String[] emailBody = email.plainTextBody.split('\n');
    system.debug('------------emailbody------'+emailBody);
    //String firstName = emailBody[0].substring(5);
    String lastName= emailBody[0].substring(2);
    String phoneNumber = emailBody[0].substring(6);
    String city = emailBody[0].substring(6);
    String status = emailBody[0].substring(3);
    String company= emailBody[0].substring(2);
    Lead[] newLead = new Lead[0];
     try {
     if (newLead .size() == 0)
    {
       newLead.add(new Lead(LastName = lastName,Phone = phoneNumber, City = city,Company=company ));
       insert newLead;        
    }
    }
   catch (QueryException e) {
       
   }
   
   result.success = true;
   return result;
  }
}
disable value of the picklist if that value is selected.

I have a bit of a tricky scenario.

 

I have a custom VF page to display information about a custom object.  The page uses a custom controller.  The custom object is the child of Opportunity.  The VF page is rendered as PDF.  What I want to accomplish is this: Insert the PDF page as an Attachment on the Opportunity that the custom object is related to.  Does anybody know the best/easiest way to do this?  I'm a bit of a Salesforce/VisualForce noob so any help is greatly appreciated.

 

Thanks!

  • April 25, 2013
  • Like
  • 0