• Akshu
  • NEWBIE
  • 30 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 5
    Replies
Three object are :Ship__c,port__c.shipment__c
ship__c has lookup with port{shipToport__c}
shipment__c  has lookup with port as well as ship portLookupD__c & shipLookupD__c respectively.

Requirement:
1.Create ship1 record has five shipment1,.....shipment5.
2.when ship updating shipToport__c value
3.copied all shipment of ship [from ship to port] 
as well as delete shipment only from ship.
 
  • February 21, 2022
  • Like
  • 0
 Create 3 objects Ships, Ports, and Shipment. Ship object has 4 fields Name, Number of Shipments, Lookup to Ship, Lookup to Prots. Ports has 3 fields, name of the port, number of shipments, Status. Shipment object has lookup to Ships as well as ports. When a Ship is docked to a port, the status of the port changes from ‘idle’ to ‘engaged’.

Assume that multiple ships have docked the port and write a code which copies all the shipments from docked ships to the port. 
  • February 02, 2022
  • Like
  • 0
Create 3 objects Airplanes, Schedules, and Flights. Airplane object has 2 fields Name of airplane, number of seats. Schedules object has 4 fields, start date, End date, Post Date (formula field Start Date minus 30- days) and lookup to Airplane object. An Airplane can have multiple schedules. Flight object has lookup to schedules as well as Airplane and 2 additional fields as Flight start date and flight end date.

Write a code that will run every day on Schedule and when the Post Date is less than or equal to today, create a record of flight object. 
  • February 02, 2022
  • Like
  • 0
**************************controller*********************
public class SignDemo{
    
    public static String Lastname {get;set;}
    public static  Blob sign {get;set;}
    public static String Firstname {get;set;}
    public static String  MailingStreet {get;set;}
    public static String  Email {get;set;}
    public static Integer  Phone {get;set;}
      
    public static String recordId {get;set;}
    public static String mode {get;set;}
    public static String signUrl {get;set;}  
    public static Contact contact {get;set;}
    
    
    public SignDemo() {
        recordId = apexpages.currentpage().getparameters().get('id');
        
        if(recordId != null){
            contact  = [Select id,LastName,FirstName,MailingCity,Account.Name,MailingStreet,MailingState,MailingPostalCode,Phone,Email                            
                        FROM Contact where id =:recordId];
        }
        mode  = apexpages.currentpage().getparameters().get('mode');
        system.debug('mode'+mode);
        if(mode=='view'){
            
            List<Attachment> myAtt = [Select id,name from Attachment where ParentId =:recordId and name = 'Sign.png' limit 1];
            system.debug('myAtt '+myAtt );
            signUrl =  '/servlet/servlet.FileDownload?file='+myAtt[0].id;
        }
    }  
    
    public PageReference UpdateRecord1(){
        try{
            System.debug('@@@@UpdateRecord');
            update contact;
        }catch(Exception e){
            System.debug('@@@@'+e.getMessage());
        }
        return null;
    }
    
    public static PageReference saveRecord(){
               SignDemo.GenerateImage(Apexpages.currentPage().getParameters().get('base64File'),Apexpages.currentPage().getParameters().get('fileName'));

        
        PageReference errorPage = new PageReference('/apex/SignDemo?id='+Apexpages.currentPage().getParameters().get('fileName')+'&mode=view');
        errorPage.setRedirect(true);
        return errorPage;
        //return null;
    }
    
    
    //Create attachment and return id of the attachment.  
    public static void GenerateImage(string dataurl,String recID){
        
        system.debug('@@GenerateImage');
        List<Attachment> myAtt = [Select name from Attachment where ParentId =:recID and name = 'Sign.png' limit 1];
        
        if(myAtt.size()>0){
            Delete myAtt;
        }                
        Attachment myAttach = new Attachment();
        myAttach.name = 'Sign.png';
        myAttach.ParentId =recID ;  //Add ID of the parent object for the attachment (Account,Contact,etc..)
        myAttach.body = ((Blob) EncodingUtil.base64Decode(dataurl.split(',')[1]));
        insert myAttach;
  
     }
     
  }
 
**********************vf page*****************
<apex:page controller="SignDemo" docType="html-5.0" showheader="false" sidebar="false" standardStylesheets="true">
    
    <script src="https://github.com/soulwire/sketch.js/blob/master/js/sketch.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>       
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.rawgit.com/mobomo/sketch.js/master/lib/sketch.min.js"></script> 
    <apex:form >
        <html>
            <head>
                <style>
                    .form {               
                    outline: none;
                    min-width:4px;
                    }
                    @page { size: A4 landscape; }
                    p.dotted {
                    border-style: dotted;
                    }
                    p.dashed {
                    border-style: dashed;
                    }
                    p.solid {
                    border-style: solid;
                    }
                    p.double {
                    border-style: double;
                    }
                    p.groove {
                    border-style: groove;
                    }
                    p.ridge {
                    border-style: ridge;
                    }
                    p.inset {
                    border-style: inset;
                    }
                    p.outset {
                    border-style: outset;
                    }
                    p.none {
                    border-style: none;
                    }
                    p.hidden {
                    border-style: hidden;
                    }
                    p.mix {
                    border-style: dotted dashed solid double;
                    }
                    .boxcss {
                    width: 220px;
                    padding: 10px;
                    border: 1px solid gray;
                    margin: 0;
                    }
                    p {
                    text-indent: 50px;
                    }
                    input {
                    border: 0;
                    outline: 0;
                    background: transparent;
                    border-bottom: 1px solid black;
                    }
                    .inputpick{
                    border: 0;
                    outline: 0;
                    background: transparent;
                    border-bottom: 1px solid black;
                    }
                    th {
                    text-align: center;
                    font-weight: bold;white-space: normal;font-weight: bold;
                    border: 1px solid black;
                    border-collapse: collapse;
                    body{
                    font-family: Tahoma, Verdana, Segoe, sans-serif;
                    font-weight: normal;
                    }
                    .logo {
                    float: left;
                    }
                    .header {
                    margin-top: 15px;
                    font-size: 16px;
                    text-align: center;
                    font-weight: bold;
                    }
                    .Sub-header-top{
                    font-size: 13px;
                    text-align: center;
                    font-weight: bold;
                    }
                    .content{
                    font-size:14px;
                    }
                    li{
                    margin-top:5px;
                    margin-bottom:5px;
                    }
                    .weight{
                    font-weight: bold;
                    }
                    }
                    
                </style>
            </head>
            <body>
                
                <div style="width:70%; margin-top: 50px; margin-bottom:50px; margin-right: 80px; margin-left: 80px;">
                    <div class="container">
                        
                        <ol type="1">
                            
                            <li style="text-indent: 10px;">Trustee’s last name: <input type="text" id="LastName" class="form" placeholder="lname" value="{!contact.LastName}" onkeypress="this.style.width = ((this.value.length + 1) * 8) + 'px';"/> Trustee’s first name:<input type="text" id="FirstName" placeholder="fname" value="{!contact.FirstName}"/></li><br/>
                            
                            <li style="text-indent: 10px;">Position on board (i.e., chair, treasurer, committee chair, member, etc.):------------------------------</li><br/>
                            
                            <li style="text-indent: 10px;">Name of charter school(s):<apex:inputField value="{!contact.Account.Name}"/></li><br/>  
                            
                            <li style="text-indent: 10px;">Address of charter school(s):___________________________________________________________
                                
                                ____________________________________________________________ </li><br/>
                            
                            <li style="text-indent: 10px;">Trustee’s Business Address:
                                
                                <br/> Street :<input type="text" id="MailingStreet" placeholder="fname" value="{!contact.MailingStreet}"/>
                                
                                <br/>   City:<input value="{!contact.MailingCity}"/> State:<input value="{!contact.MailingState}"/> Zipcode:<input value="{!contact.MailingPostalCode}"/> </li><br/>
                            
                            <li style="text-indent: 10px;"> Business phone:<input type="text" id="phone" placeholder="fname" value="{!contact.Phone}"/> Business Email:<input type="text" id="email" name="fname" value="{!contact.Email}"/></li><br/>
                            
                            <li style="text-indent: 10px;">Is Trustee an employee of any charter school listed in response to Question 3?
                                
                                <br/> ---------------------------------<br/>
                                
                                <br/> If the answer is yes, please identify the charter school that employs the Trustee: ____________________________________________________________
                                
                            </li><br/>
                            
                            <li style="text-indent: 10px;"> Did you and/or an immediate family member have a financial interest in any charter school located in the Commonwealth of Massachusetts during the previous calendar year?<br/>
                                
                                <br/> -----------------------------------------------<br/>
                                
                                <br/>If the answer is yes, identify each such charter school below.
                                
                            </li><br/>
                            
                        </ol>
                        
                        <table style="width:100% " >
                            <tr>
                                <td>
                                    <apex:outputPanel rendered="{!mode == 'view'}">
                                        
                                        <apex:image id="theImage" value="{!signUrl}" width="100" height="100"/>
                                        
                                    </apex:outputPanel>
                                    
                                    <apex:outputPanel rendered="{!mode == 'edit'}">
                                        
                                        <canvas id="Sign" onclick="save()" style="border:2px solid; border-radius:10px 10px 10px 10px;height: 150px;width: 300px;background:white; border-color:lightgray" ></canvas>
                                        
                                        <input type="button" value="Clear"  onclick="clearSketch()" />
                                        
                                    </apex:outputPanel>
                                    
                                </td>
                                
                                <td><apex:outputText value="{0,date,MM/dd/yy}">
                                    
                                    <apex:param value="{!today()}" />
                                    
                                    </apex:outputText></td>
                                
                            </tr>
                            
                            <tr>
                                
                                <td> Signature</td>
                                
                                <td>Date</td>                              
                                
                            </tr>
                            
                        </table> <br/>
                        
                        <div>Please retain a copy for your record</div><br/><br/>
                        
                        <apex:outputPanel id="resultPanel" rendered="{!mode == 'view'}">
                            
                            <apex:commandButton value="Download"/>
                            
                        </apex:outputPanel>
                        
                        <apex:outputPanel rendered="{!mode == 'edit'}">
                            
                            <apex:commandButton onclick="save()"  value="Save"/>
                            
                        </apex:outputPanel>
                        <apex:actionFunction name="searchServer" action="{!saveRecord}" reRender="resultPanel">
                            <apex:param name="base64File"  value="" />
                            <apex:param name="fileName" value="" /> 
                            
                            <apex:param name="Firstname" assignTo="{!Firstname}" value="" /> 
                            <!--<apex:param name="" assignTo="{!}" value="" /> 
                            <apex:param name="" assignTo="{!}" value="" /> 
                            <apex:param name="" assignTo="{!}" value="" /> 
                            <apex:param name="" assignTo="{!}" value="" /> 
                            <apex:param name="" assignTo="{!}" value="" /> -->
                            

                        </apex:actionFunction>
                        <script>   
                        
                        // $('id').css('width',((input.getAttribute('placeholder').length + 1) * 8) + 'px');
                        
                        $(window).on('load', function () {      
                            
                            var mode = '{!mode}';
                            
                            if(mode =='edit'){
                                
                                clearSketch();
                                
                                $('#Sign').sketch(); // associating sketch function with canvas.
                                
                            }
                            
                        });
                        
                        // clear canvas on clear button.
                        
                        function clearSketch(){         
                            
                            $('#Sign').replaceWith('<canvas id="Sign" style="border:2px solid; border-radius:10px 10px 10px 10px;height: 150px;width: 300px;background:white; border-color:lightgray"></canvas>');
                            
                            $('#Sign').sketch();
                            
                        } 
                        
                        function save(){
                          
                            // Get Data URL from the canvas i.e. signed by the user.
                            
                            var dataUrl = document.getElementById('Sign').toDataURL();
                             console.log("response",dataUrl);
                           
                            var FName = document.getElementById('FirstName').value;
                            console.log("response",FName);
                            alert(FName);
                            
                            var LName = document.getElementById('LastName').value;
                            console.log("response",LName);
                            var eEmail = document.getElementById('email').value;
                            console.log("response",eEmail);
                            var pPhone = document.getElementById('phone').value;
                            console.log("response",pPhone);
                            
                            // use Remote Action function to generate image.
                            
                            
                            var recordid = '{!recordId}';
                            
                            alert(recordid);
                            
                            // action funcation with parameter
                            
                            searchServer(dataUrl,recordid);
                            //searchServer(dataUrl,recordid);
                            
                        }
                        </script>
                    </div>
                </div>
            </body>
        </html>
        
    </apex:form>
</apex:page>

 
  • August 19, 2021
  • Like
  • 0
-as well as how to access all(bulk) field of Vf form for edit and updation

-also save upadated record.
-vf page in edit mode to view mode
  • August 19, 2021
  • Like
  • 0
*****************controller****************
/*
https://mindful-koala-aud8rz-dev-ed--c.visualforce.com/apex/AssignmentForm?id=0035g00000C1PHe&mode=edit
*/
public class SignDemo{
    
    public static String Lastname {get;set;}
    public static String Firstname {get;set;}
    public static String MailingCity {get;set;}
    public static String MailingStreet {get;set;}
    public static String MailingState {get;set;}
    public static String MailingPostalCode {get;set;}
    public static String Email {get;set;}
    public static Integer Phone {get;set;}
    
    public static  Blob sign {get;set;}
    
    
    //public  String  dataBody {get;set;}
    // public  String  fileName {get;set;}
    
    public static String recordId {get;set;}
    public static String mode {get;set;}
    public static String signUrl {get;set;}  
    public static Contact contact {get;set;}
    
    
    public SignDemo() {
        recordId = apexpages.currentpage().getparameters().get('id');

        if(recordId != null){
            contact  = [Select id,LastName,FirstName,MailingCity,Account.Name,MailingStreet,MailingState,MailingPostalCode,Phone,Email                            
                        FROM Contact where id =:recordId];
        }
        mode  = apexpages.currentpage().getparameters().get('mode');
        system.debug('mode'+mode);
        if(mode=='view'){
            
            List<Attachment> myAtt = [Select id,name from Attachment where ParentId =:recordId and name = 'Sign.png' limit 1];
            system.debug('myAtt '+myAtt );
            signUrl =  '/servlet/servlet.FileDownload?file='+myAtt[0].id;
            
        }
    }  
    
    public PageReference UpdateRecord1(){
        try{
            System.debug('@@@@UpdateRecord');
            update contact;
        }catch(Exception e){
            System.debug('@@@@'+e.getMessage());
        }
        return null;
    }
    
    public static PageReference saveRecord(){
        
        //System.debug('passed value==>'+ Apexpages.currentPage().getParameters().get('myParam'));
        //system.debug('@@saveRecord'+ Apexpages.currentPage().getParameters().get('base64File')+' 2 -'+Apexpages.currentPage().getParameters().get('fileName'));
        
        // Lastname =Apexpages.currentPage().getParameters().get('Lastname');
        //Firstname =Apexpages.currentPage().getParameters().get('Firstname');
        //SignDemo.GenerateData(Apexpages.currentPage().getParameters().get('Firstname'));
        
        //Firstname=Apexpages.currentPage().getParameters().get('Firstname');
       SignDemo.GenerateImage(Apexpages.currentPage().getParameters().get('base64File'),Apexpages.currentPage().getParameters().get('fileName'));

        PageReference errorPage = new PageReference('/apex/SignDemo?id='+Apexpages.currentPage().getParameters().get('fileName')+'&mode=view');
        errorPage.setRedirect(true);
        return errorPage;
        //return null;
    }
    
    
    //Create attachment and return id of the attachment.  
    public static void GenerateImage(string dataurl,String recID){
        
        system.debug('@@GenerateImage');
        List<Attachment> myAtt = [Select name from Attachment where ParentId =:recID and name = 'Sign.png' limit 1];
        
        if(myAtt.size()>0){
            Delete myAtt;
        }                
        Attachment myAttach = new Attachment();
        myAttach.name = 'Sign.png';
        myAttach.ParentId =recID ;  //Add ID of the parent object for the attachment (Account,Contact,etc..)
        myAttach.body = ((Blob) EncodingUtil.base64Decode(dataurl.split(',')[1]));
        insert myAttach;
       /* Contact cs = new Contact();
        cs.FirstName = contact.FirstName;
        cs.LastName = contact.LastName;
        cs.Phone=contact.Phone;
        cs.Email=contact.Email;
        cs.MailingStreet=contact.MailingStreet;
         
        upsert cs;*/
     }
     
    
}


***********************vf page***************
<apex:page controller="SignDemo"  docType="html-5.0" showheader="false" sidebar="false" standardStylesheets="true">
    
    <script src="https://github.com/soulwire/sketch.js/blob/master/js/sketch.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>       
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.rawgit.com/mobomo/sketch.js/master/lib/sketch.min.js"></script> 
    <apex:form >
        <html>
            <head>
                <style>
                    .form {               
                    outline: none;
                    min-width:4px;
                    }
                    @page { size: A4 landscape; }
                    p.dotted {
                    border-style: dotted;
                    }
                    p.dashed {
                    border-style: dashed;
                    }
                    p.solid {
                    border-style: solid;
                    }
                    p.double {
                    border-style: double;
                    }
                    p.groove {
                    border-style: groove;
                    }
                    p.ridge {
                    border-style: ridge;
                    }
                    p.inset {
                    border-style: inset;
                    }
                    p.outset {
                    border-style: outset;
                    }
                    p.none {
                    border-style: none;
                    }
                    p.hidden {
                    border-style: hidden;
                    }
                    p.mix {
                    border-style: dotted dashed solid double;
                    }
                    .boxcss {
                    width: 220px;
                    padding: 10px;
                    border: 1px solid gray;
                    margin: 0;
                    }
                    p {
                    text-indent: 50px;
                    }
                    input {
                    border: 0;
                    outline: 0;
                    background: transparent;
                    border-bottom: 1px solid black;
                    }
                    .inputpick{
                    border: 0;
                    outline: 0;
                    background: transparent;
                    border-bottom: 1px solid black;
                    }
                    th {
                    text-align: center;
                    font-weight: bold;white-space: normal;font-weight: bold;
                    border: 1px solid black;
                    border-collapse: collapse;
                    body{
                    font-family: Tahoma, Verdana, Segoe, sans-serif;
                    font-weight: normal;
                    }
                    .logo {
                    float: left;
                    }
                    .header {
                    margin-top: 15px;
                    font-size: 16px;
                    text-align: center;
                    font-weight: bold;
                    }
                    .Sub-header-top{
                    font-size: 13px;
                    text-align: center;
                    font-weight: bold;
                    }
                    .content{
                    font-size:14px;
                    }
                    li{
                    margin-top:5px;
                    margin-bottom:5px;
                    }
                    .weight{
                    font-weight: bold;
                    }
                    }
                    
                </style>
            </head>
            <body>
                
                <div style="width:70%; margin-top: 50px; margin-bottom:50px; margin-right: 80px; margin-left: 80px;">
                    <div class="container">
                        
                        <ol type="1">
                            
                            <li style="text-indent: 10px;">Trustee’s last name: <input type="text" id="LastName" class="form" placeholder="lname" value="{!contact.LastName}" onkeypress="this.style.width = ((this.value.length + 1) * 8) + 'px';"/> Trustee’s first name:<input type="text" id="FirstName" placeholder="fname" value="{!contact.FirstName}"/></li><br/>
                            
                            <li style="text-indent: 10px;">Position on board (i.e., chair, treasurer, committee chair, member, etc.):------------------------------</li><br/>
                            
                            <li style="text-indent: 10px;">Name of charter school(s):<apex:inputField value="{!contact.Account.Name}"/></li><br/>  
                            
                            <li style="text-indent: 10px;">Address of charter school(s):___________________________________________________________
                                
                                ____________________________________________________________ </li><br/>
                            
                            <li style="text-indent: 10px;">Trustee’s Business Address:
                                
                                <br/> Street :<input type="text" id="MailingStreet" placeholder="fname" value="{!contact.MailingStreet}"/>
                                
                                <br/>   City:<input value="{!contact.MailingCity}"/> State:<input value="{!contact.MailingState}"/> Zipcode:<input value="{!contact.MailingPostalCode}"/> </li><br/>
                            
                            <li style="text-indent: 10px;"> Business phone:<input type="text" id="phone" placeholder="fname" value="{!contact.Phone}"/> Business Email:<input type="text" id="email" name="fname" value="{!contact.Email}"/></li><br/>
                            
                            <li style="text-indent: 10px;">Is Trustee an employee of any charter school listed in response to Question 3?
                                
                                <br/> ---------------------------------<br/>
                                
                                <br/> If the answer is yes, please identify the charter school that employs the Trustee: ____________________________________________________________
                                
                            </li><br/>
                            
                            <li style="text-indent: 10px;"> Did you and/or an immediate family member have a financial interest in any charter school located in the Commonwealth of Massachusetts during the previous calendar year?<br/>
                                
                                <br/> -----------------------------------------------<br/>
                                
                                <br/>If the answer is yes, identify each such charter school below.
                                
                            </li><br/>
                            
                        </ol>
                        
                        <table style="width:100% " >
                            <tr>
                                <td>
                                    <apex:outputPanel rendered="{!mode == 'view'}">
                                        
                                        <apex:image id="theImage" value="{!signUrl}" width="100" height="100"/>

                                        
                                    </apex:outputPanel>
                                    
                                    <apex:outputPanel rendered="{!mode == 'edit'}">
                                        
                                        <canvas id="Sign" onclick="save()" style="border:2px solid; border-radius:10px 10px 10px 10px;height: 150px;width: 300px;background:white; border-color:lightgray" ></canvas>
                                        
                                        <input type="button" value="Clear"  onclick="clearSketch()" />
                                        
                                    </apex:outputPanel>
                                    
                                </td>
                                
                                <td><apex:outputText value="{0,date,MM/dd/yy}">
                                    
                                    <apex:param value="{!today()}" />
                                    
                                    </apex:outputText></td>
                                
                            </tr>
                            
                            <tr>
                                
                                <td> Signature</td>
                                
                                <td>Date</td>                              
                                
                            </tr>
                            
                        </table> <br/>
                        
                        <div>Please retain a copy for your record</div><br/><br/>
                        
                        <apex:outputPanel id="resultPanel" rendered="{!mode == 'view'}">
                            
                            <apex:commandButton value="Download"/>
                            
                        </apex:outputPanel>
                        
                        <apex:outputPanel rendered="{!mode == 'edit'}">
                            
                            <apex:commandButton onclick="save()"  value="Save"/>
                            
                        </apex:outputPanel>
                        <apex:actionFunction name="searchServer" action="{!saveRecord}" reRender="resultPanel">
                            <!--<apex:param name="myParam" value=""/>-->
                            <apex:param name="base64File"  value="" />
                            
                            <apex:param name="fileName" value="" /> 
                            <!-- <apex:inputText  id="Firstname" value="{!Firstname}"     />--> 
                            <!-- <apex:inputText  id="LastName" value="{!LastName}"     />--> 
                            <!-- <apex:inputText  id="email" value="{!email}"     />--> 
                            <!-- <apex:inputText  id="phone" value="{!phone}"     />-->  
                              <!-- <apex:inputText  id="" value="{!}"     />--> 
                              <!-- <apex:inputText  id="" value="{!}"     />--> 
                              <!-- <apex:inputText  id="" value="{!}"     />--> 
                              <!-- <apex:inputText  id="" value="{!}"     />--> 
                            
                        </apex:actionFunction>
                        <script>   
                        
                        // $('id').css('width',((input.getAttribute('placeholder').length + 1) * 8) + 'px');
                        
                        $(window).on('load', function () {      
                            
                            var mode = '{!mode}';
                            
                            if(mode =='edit'){
                                
                                clearSketch();
                                
                                $('#Sign').sketch(); // associating sketch function with canvas.
                                
                            }
                            
                        });
                        
                        // clear canvas on clear button.
                        
                        function clearSketch(){         
                            
                            $('#Sign').replaceWith('<canvas id="Sign" style="border:2px solid; border-radius:10px 10px 10px 10px;height: 150px;width: 300px;background:white; border-color:lightgray"></canvas>');
                            
                            $('#Sign').sketch();
                            
                        } 
                        
                        function save(){
                            
                            // Get Data URL from the canvas i.e. signed by the user.
                            
                            var dataUrl = document.getElementById('Sign').toDataURL();
                            console.log("response",dataUrl);
                          
                           // var elms = document.querySelectorAll("[id='frm']").save();
                            //console.log("response",elms)
                          
                    

                            var FName = document.getElementById('FirstName').value;
                            console.log("response",FName);
                            /*var LName = document.getElementById('LastName').value;
                            console.log("response",LName);
                            var eEmail = document.getElementById('email').value;
                            console.log("response",eEmail);
                            var pPhone = document.getElementById('phone').value;
                            console.log("response",pPhone);
                            */
                            // use Remote Action function to generate image.
                            
                            
                            var recordid = '{!recordId}';
                            
                            alert(recordid);
                            
                            // action funcation with parameter
                            
                            searchServer(dataUrl,recordid);
                            //searchServer(dataUrl,recordid,Fname);
                            
                        }
                        </script>
                    </div>
                </div>
            </body>
        </html>
        
    </apex:form>
</apex:page>

 
  • August 17, 2021
  • Like
  • 0
/*****************************trigger***************************/
trigger NoOfcontacts on Contact (after insert, after delete) {
    Set<Id> accId = new Set<Id>();
    
    if(Trigger.isInsert)
    {
        for(Contact con : Trigger.new)
        {
            accId.add(con.AccountId);
        }
    }
    
    if(Trigger.isDelete)
    {
        for(Contact con : Trigger.old)
        {
            accId.add(con.AccountId);
        }
    }
    //query 
    List<Account> accList = [Select Id,Number_Of_Contacts__c,(Select id from contacts) from Account where Id IN : accId];
    
    for(Account acc :accList)
    {
        acc.Number_Of_Contacts__c    = acc.contacts.size();
    }
    update accList;
}*/
  • June 09, 2021
  • Like
  • 0
************************trigger***************************
trigger TaskandemailusingTrigger on Account (after insert) {
    List<Task> tasklist= new List<task>();
    Set<User> ownerID = new Set<User>();
 
 user u=[select Name, Email from User where id=:userinfo.getUserId()];
  
    for (Account acc:trigger.new){
        if(acc.type=='Prospect'){
            task t=new task();
            t.whatid=acc.id;
            t.Priority='normal';
            t.OwnerId=u.Id;
            t.Status='not started';
            t.subject='Account task created'+acc.Name;
        
            tasklist.add(t);
        
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
      String[] toAddresses = new String[] {u.Email};
        mail.setToAddresses(toAddresses); 
       mail.setSubject('your task has been created'); 
            mail.setHtmlBody('this is Acoount task mail');
        Messaging.Email[] emails=new Messaging.Email[]{mail};
        Messaging.sendEmail(emails);
       }
    }
        
        insert tasklist;
        
        
        
    }
  • June 09, 2021
  • Like
  • 0
*************************controller***********************
public with sharing class AccountDetails{
    
        public list<Account> accounts{get;set;}
    
        public String accountId{get;set;}
    
        public list<contact> contacts{get;set;}
    
        public AccountDetails(){
            accounts = [select Id,Name,Number_Of_Contacts__c from Account limit 100];
        }
       
        public void getContactDetails(){
            contacts = [select Id,Name from Contact where AccountId =:accountId];
        }
    
}
 
  • June 08, 2021
  • Like
  • 0
*********************trigger is*****************************
/*
 We need to populate number of Contact Records on Account 
 Object (Insert,Delete) all condition should be consider.
  
 */
 
trigger NoOfcontacts on Contact (after insert, after delete) {
    Set<Id> accId = new Set<Id>();
    
    if(Trigger.isInsert)
    {
        for(Contact con : Trigger.new)
        {
            accId.add(con.AccountId);
        }
    }
    
    if(Trigger.isDelete)
    {
        for(Contact con : Trigger.old)
        {
            accId.add(con.AccountId);
        }
    }
    //query 
    List<Account> accList = [Select Id,Number_Of_Contacts__c,(Select id from contacts) from Account where Id IN : accId];
    
    for(Account acc :accList)
    {
        acc.Number_Of_Contacts__c    = acc.contacts.size();
    }
    update accList;
}
  • June 08, 2021
  • Like
  • 0
Facing problem about Google map:please provide required solution about it
User-added image




************************vf page*********************
<apex:page standardController="Account">

<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAbfPnDaL24nk10UVODur46RQ4hZBRKujLa20gdgk6BGq02b_7dRSUc-gU9S7Sru9i0Z4lD1pGbwanwg" type="text/javascript"></script>

<script type="text/javascript">

var map = null;
var geocoder = null;

var address = "{!Account.BillingStreet}, {!Account.BillingPostalCode} {!Account.BillingCity}, {!Account.BillingState}, {!Account.BillingCountry}";

function initialize() {
if(GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("MyMap"));
map.addControl(new GMapTypeControl());
map.addControl(new GLargeMapControl3D());

geocoder = new GClientGeocoder();
geocoder.getLatLng(
address,
function(point) {
if (!point) {
document.getElementById("MyMap").innerHTML = address + " not found";
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.bindInfoWindowHtml("Account Name : <b><i> {!Account.Name} </i></b>
Address : "+address);
}
}
);
}
}
</script>


<div id="MyMap" style="width:100%;height:300px"></div>
<script>
initialize() ;
</script>

</apex:page>
  • June 04, 2021
  • Like
  • 0
facing Problem in Saving record.
but img is saved.
User-added image
User-added image


*************************controller****************************
public class ImagInsertionIntoRichText {
public String naam{get;set;}
public ID folderid{get;set;}
public Blob file{get;set;}
public candidate1__c pos{set;get;}
private ApexPages.StandardController controller;
public ImagInsertionIntoRichText(ApexPages.StandardController controller) {
this.pos = (candidate1__c)controller.getRecord();
//pos=[select Candidiate_Experience1__c,contact_Number__c,Current_Company__c,current_CTC__c,E_Mail_Id__c,Expected_CTC__c,Current_City__c from candidate1__c where id=;] ;
}
public void insrt()
{
Document d= new Document();
d.name = naam;
d.body=file; // body field in document object which holds the file.
d.folderid='0052v00000ZFCqx'; //folderid where the document will be stored insert d;
insert d;
candidate1__c cs = new candidate1__c();
cs.Image__c = '<img src="/servlet/servlet.FileDownload?file='+d.id+'" width="500" height="281"></img>'; //FirstExample is namespace & Comments__c is Rich Text Area field

insert cs;
}
}
***********************************vf page****************************
<apex:page standardController="candidate1__c" extensions="ImagInsertionIntoRichText">
<apex:form>
<apex:pageBlock>
<apex:pageBlockSection>

<apex:inputField value="{!candidate1__c.Name}" />
<apex:inputField value="{!candidate1__c.Candidiate_Experience1__c}" />
<apex:inputField value="{!candidate1__c.contact_Number__c}" />
<apex:inputField value="{!candidate1__c.Current_City__c}" />
<apex:inputField value="{!candidate1__c.Current_Company__c}" />
<apex:inputField value="{!candidate1__c.current_CTC__c}" />
<apex:inputField value="{!candidate1__c.E_Mail_Id__c}" />
<apex:inputField value="{!candidate1__c.Expected_CTC__c}" />

<apex:outputLabel value="Document Name"></apex:outputLabel>
<apex:inputText id="name" value="{!naam}"/>
<apex:outputLabel value="Upload Document"></apex:outputLabel>
<apex:inputfile value="{!file}"></apex:inputfile>
<apex:commandButton value="save" action="{!insrt}" id="save"/>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
  • June 04, 2021
  • Like
  • 0
When click on send mail button:
User-added image*************vf page******************
<apex:page Controller="wrapperClassController">
    <apex:form>
    <head>
       <apex:includescript value="https://code.jquery.com/jquery-1.11.1.min.js" / >
       <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.18/r-2.2.2/rg-1.0.3/sl-1.2.6/datatables.min.css"/>
       <script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.18/r-2.2.2/rg-1.0.3/sl-1.2.6/datatables.min.js"></script>
      <link type="text/css" href="//gyrocode.github.io/jquery-datatables-checkboxes/1.2.11/css/dataTables.checkboxes.css" rel="stylesheet" />
      <script type="text/javascript" src="//gyrocode.github.io/jquery-datatables-checkboxes/1.2.11/js/dataTables.checkboxes.min.js"></script>  
        <script>
          j$ = jQuery.noConflict();
         j$(document).ready(function () {
         var conTable = j$('[id$="contacttable"]').DataTable({
                   "pageLength": 50,
                   'columnDefs': [{
                   'targets': 0,
                        'checkboxes': {
                              'selectRow': true
                   },
                        "orderable": false 
                    }
                   ],

               'select': {
               'style': 'multi'
                     }
                  });

            });

        </script>

    </head>
       <apex:pageBlock>
        <apex:pageBlockButtons location="top">
               <apex:outputPanel layout="none" id="buttonsPanel">
                  <apex:commandButton value="send Mail" action="{!sendEmails}"> 
                </apex:commandButton> 
                <apex:commandButton value="Reset" action="{!reset}" immediate="true"/>
               </apex:outputPanel>      
            </apex:pageBlockButtons>
    <body>
        <table id="contacttable" class="display">
            <thead>
                <tr>
                    <th><apex:inputCheckbox/></th>
                    <th>Email</th>
                    <th>Name</th>
                    <th>Phone</th>
                </tr>
            </thead>
            <tbody>
                <apex:repeat value="{!cListWrapper}" var="c">
                    <tr>
                    <td><apex:inputCheckbox value="{!c.selected}" id="inputId"/></td>
                        <td>{!c.con.Email}</td>
                        <td>{!c.con.Name}</td>
                        <td>{!c.con.Phone}</td>
                    </tr>
                </apex:repeat>
            </tbody>
        </table>
     </body>
    </apex:pageBlock>        
   </apex:form>
 </apex:page>
***************************controller**********************
public class wrapperClassController {
       private String recordId;

    public Boolean selected {get; set;}
    public List<Contact> contactList {get;set;}
    public List<cWrapper> cListWrapper {get;set;}

    public wrapperClassController(){
        contactList = [SELECT Id, Name, Phone,Email FROM Contact WHERE AccountId=:recordId limit 1000];
        cListWrapper = new list<cWrapper>();

            for(Contact c: contactList) {
                cListWrapper.add(new cWrapper(c));
            }
    }    
    public class cWrapper {

        public Contact  con {get; set;}
        public Boolean selected {get; set;}


        public cWrapper(Contact  c) {
            con = c;
            selected = false;
        }
    }

    public PageReference reset() {
        PageReference pg = new PageReference(System.currentPageReference().getURL());
        pg.setRedirect(true);
        return pg;
    }

  public PageReference sendEmails(){
         List<Contact> selectedContacts = new List<Contact>();
         //System.debug('==>Inside sendEmail() '+ wrapperConsList);
        for(cWrapper c: cListWrapper) {
            if(c.Selected == true) {
                selectedContacts.add(c.con);

            }
        }
      // System.debug('toaddresses==>'+selectedContacts);
        String []toAddresses = new List<String>();
      //String[] toAddresses = new String[] {};
        
        for(Contact c : selectedContacts) {
            
            toAddresses.add(c.Email);
           
        }
       // System.debug('toaddresses==>'+toAddresses);
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(toAddresses);
        mail.setSubject('VF page created' );
        mail.setHtmlBody('This SF message!!!!!!   Thank you');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
        //update selectedContacts;
        return null;
    }  

}
 
  • June 03, 2021
  • Like
  • 1
public class VFControllerPosition {
    public Position__c po;
    
    public VFControllerPosition(ApexPages.StandardController controller) 
    {
        this.po =(Position__c)controller.getRecord();
    }
    
    public PageReference redirect1() 
    {
        PageReference p =new PageReference('/apex/JobportalTabpage2');
        return p; 
    }
    public PageReference redirect2()
    {
        insert po;
        PageReference p=new PageReference('/apex/JobportalTabpage3?id='+po.id);
        p.setredirect(true);
        return p;
        
    }
    public PageReference redirect3() 
    {
        PageReference p =new PageReference('/apex/JobportalTabpage4');
        p.setredirect(true);
        return p; 
        
    }
    public PageReference redirect4()
    {
        
        PageReference pr = new PageReference('/apex/JobportalTabpage5'+Apexpages.currentPage().getParameters().get('id'));
       
        pr.setredirect(true);
        return pr; 
        
        
        
    }
    
    
    
    
}
  • May 28, 2021
  • Like
  • 0
1.created custom button on Account details page "show contact"-that shows related contact of that account
User-added image
2.after click on show contact button ,u see the related contacts:

3:when select checkbox of that contact -send mail
(mass mail method)
User-added image
  • May 28, 2021
  • Like
  • 0
1.created custom button on details page of account account "show" requirement is:
when click on this button show rcontacts  related to account in table format.
  • May 27, 2021
  • Like
  • 0
public class VFControllerPosition {
    public Position__c po;
    
    public VFControllerPosition(ApexPages.StandardController controller) 
    {
        this.po =(Position__c)controller.getRecord();
    }
    
    public PageReference redirect1() 
    {
        PageReference p =new PageReference('/apex/JobportalTabpage2');
        return p; 
    }
    public PageReference redirect2()
    {
        insert po;
        PageReference p=new PageReference('/apex/JobportalTabpage3?id='+po.id);
        p.setredirect(true);
        return p;
        
    }
    public PageReference redirect3() 
    {
        PageReference p =new PageReference('/apex/JobportalTabpage4');
        p.setredirect(true);
        return p; 
        
    }
    public PageReference redirect4()
    {
        
        PageReference pr = new PageReference('/apex/JobportalTabpage5'+Apexpages.currentPage().getParameters().get('id'));
        
        pr.setredirect(true);
        return pr; 
        
        
        
    }
    
    
    
    
}
  • May 26, 2021
  • Like
  • 0
/*
 * Write a batch class to send an email to Opportunity owner. 
 * On 1st of each month send an email to Opportunity owner if close date is in this month.
 */
public class Sendmailcopy implements Database.Batchable <sobject> { 
     public Database.QueryLocator start(DataBase.BatchableContext BC){
        return Database.getQueryLocator([select id, Name, OwnerId,Owner.Email,CloseDate from Opportunity where CloseDate=THIS_MONTH]);
    }
      List<String> emailList=new List<String>();
      
    public void execute(Database.BatchableContext BC,List<Opportunity> opptyList){
        
        
        for(Opportunity opp:opptyList)
        {
            emailList.add(opp.Owner.Email);
        }
        sendmail();
    }
    public void sendmail()
    { 
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(emailList);
        email.setSubject(' opportunity Close Date!!!!!');
        email.setPlainTextBody('Close date of this opportunity is in this month');
        
        Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
    }
   public void finish(Database.BatchableContext BC){
    }
}

/*************schedule*************************
 global class sendmail implements Schedulable {
    global void execute(SchedulableContext ctx) {
        Sendmailcopy um=new Sendmailcopy();
        Database.executeBatch(um);
    }
}
*/
  • May 24, 2021
  • Like
  • 0
When click on send mail button:
User-added image*************vf page******************
<apex:page Controller="wrapperClassController">
    <apex:form>
    <head>
       <apex:includescript value="https://code.jquery.com/jquery-1.11.1.min.js" / >
       <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.18/r-2.2.2/rg-1.0.3/sl-1.2.6/datatables.min.css"/>
       <script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.18/r-2.2.2/rg-1.0.3/sl-1.2.6/datatables.min.js"></script>
      <link type="text/css" href="//gyrocode.github.io/jquery-datatables-checkboxes/1.2.11/css/dataTables.checkboxes.css" rel="stylesheet" />
      <script type="text/javascript" src="//gyrocode.github.io/jquery-datatables-checkboxes/1.2.11/js/dataTables.checkboxes.min.js"></script>  
        <script>
          j$ = jQuery.noConflict();
         j$(document).ready(function () {
         var conTable = j$('[id$="contacttable"]').DataTable({
                   "pageLength": 50,
                   'columnDefs': [{
                   'targets': 0,
                        'checkboxes': {
                              'selectRow': true
                   },
                        "orderable": false 
                    }
                   ],

               'select': {
               'style': 'multi'
                     }
                  });

            });

        </script>

    </head>
       <apex:pageBlock>
        <apex:pageBlockButtons location="top">
               <apex:outputPanel layout="none" id="buttonsPanel">
                  <apex:commandButton value="send Mail" action="{!sendEmails}"> 
                </apex:commandButton> 
                <apex:commandButton value="Reset" action="{!reset}" immediate="true"/>
               </apex:outputPanel>      
            </apex:pageBlockButtons>
    <body>
        <table id="contacttable" class="display">
            <thead>
                <tr>
                    <th><apex:inputCheckbox/></th>
                    <th>Email</th>
                    <th>Name</th>
                    <th>Phone</th>
                </tr>
            </thead>
            <tbody>
                <apex:repeat value="{!cListWrapper}" var="c">
                    <tr>
                    <td><apex:inputCheckbox value="{!c.selected}" id="inputId"/></td>
                        <td>{!c.con.Email}</td>
                        <td>{!c.con.Name}</td>
                        <td>{!c.con.Phone}</td>
                    </tr>
                </apex:repeat>
            </tbody>
        </table>
     </body>
    </apex:pageBlock>        
   </apex:form>
 </apex:page>
***************************controller**********************
public class wrapperClassController {
       private String recordId;

    public Boolean selected {get; set;}
    public List<Contact> contactList {get;set;}
    public List<cWrapper> cListWrapper {get;set;}

    public wrapperClassController(){
        contactList = [SELECT Id, Name, Phone,Email FROM Contact WHERE AccountId=:recordId limit 1000];
        cListWrapper = new list<cWrapper>();

            for(Contact c: contactList) {
                cListWrapper.add(new cWrapper(c));
            }
    }    
    public class cWrapper {

        public Contact  con {get; set;}
        public Boolean selected {get; set;}


        public cWrapper(Contact  c) {
            con = c;
            selected = false;
        }
    }

    public PageReference reset() {
        PageReference pg = new PageReference(System.currentPageReference().getURL());
        pg.setRedirect(true);
        return pg;
    }

  public PageReference sendEmails(){
         List<Contact> selectedContacts = new List<Contact>();
         //System.debug('==>Inside sendEmail() '+ wrapperConsList);
        for(cWrapper c: cListWrapper) {
            if(c.Selected == true) {
                selectedContacts.add(c.con);

            }
        }
      // System.debug('toaddresses==>'+selectedContacts);
        String []toAddresses = new List<String>();
      //String[] toAddresses = new String[] {};
        
        for(Contact c : selectedContacts) {
            
            toAddresses.add(c.Email);
           
        }
       // System.debug('toaddresses==>'+toAddresses);
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(toAddresses);
        mail.setSubject('VF page created' );
        mail.setHtmlBody('This SF message!!!!!!   Thank you');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
        //update selectedContacts;
        return null;
    }  

}
 
  • June 03, 2021
  • Like
  • 1
Create 3 objects Airplanes, Schedules, and Flights. Airplane object has 2 fields Name of airplane, number of seats. Schedules object has 4 fields, start date, End date, Post Date (formula field Start Date minus 30- days) and lookup to Airplane object. An Airplane can have multiple schedules. Flight object has lookup to schedules as well as Airplane and 2 additional fields as Flight start date and flight end date.

Write a code that will run every day on Schedule and when the Post Date is less than or equal to today, create a record of flight object. 
  • February 02, 2022
  • Like
  • 0
*********************trigger is*****************************
/*
 We need to populate number of Contact Records on Account 
 Object (Insert,Delete) all condition should be consider.
  
 */
 
trigger NoOfcontacts on Contact (after insert, after delete) {
    Set<Id> accId = new Set<Id>();
    
    if(Trigger.isInsert)
    {
        for(Contact con : Trigger.new)
        {
            accId.add(con.AccountId);
        }
    }
    
    if(Trigger.isDelete)
    {
        for(Contact con : Trigger.old)
        {
            accId.add(con.AccountId);
        }
    }
    //query 
    List<Account> accList = [Select Id,Number_Of_Contacts__c,(Select id from contacts) from Account where Id IN : accId];
    
    for(Account acc :accList)
    {
        acc.Number_Of_Contacts__c    = acc.contacts.size();
    }
    update accList;
}
  • June 08, 2021
  • Like
  • 0
Facing problem about Google map:please provide required solution about it
User-added image




************************vf page*********************
<apex:page standardController="Account">

<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAbfPnDaL24nk10UVODur46RQ4hZBRKujLa20gdgk6BGq02b_7dRSUc-gU9S7Sru9i0Z4lD1pGbwanwg" type="text/javascript"></script>

<script type="text/javascript">

var map = null;
var geocoder = null;

var address = "{!Account.BillingStreet}, {!Account.BillingPostalCode} {!Account.BillingCity}, {!Account.BillingState}, {!Account.BillingCountry}";

function initialize() {
if(GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("MyMap"));
map.addControl(new GMapTypeControl());
map.addControl(new GLargeMapControl3D());

geocoder = new GClientGeocoder();
geocoder.getLatLng(
address,
function(point) {
if (!point) {
document.getElementById("MyMap").innerHTML = address + " not found";
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.bindInfoWindowHtml("Account Name : <b><i> {!Account.Name} </i></b>
Address : "+address);
}
}
);
}
}
</script>


<div id="MyMap" style="width:100%;height:300px"></div>
<script>
initialize() ;
</script>

</apex:page>
  • June 04, 2021
  • Like
  • 0
public class VFControllerPosition {
    public Position__c po;
    
    public VFControllerPosition(ApexPages.StandardController controller) 
    {
        this.po =(Position__c)controller.getRecord();
    }
    
    public PageReference redirect1() 
    {
        PageReference p =new PageReference('/apex/JobportalTabpage2');
        return p; 
    }
    public PageReference redirect2()
    {
        insert po;
        PageReference p=new PageReference('/apex/JobportalTabpage3?id='+po.id);
        p.setredirect(true);
        return p;
        
    }
    public PageReference redirect3() 
    {
        PageReference p =new PageReference('/apex/JobportalTabpage4');
        p.setredirect(true);
        return p; 
        
    }
    public PageReference redirect4()
    {
        
        PageReference pr = new PageReference('/apex/JobportalTabpage5'+Apexpages.currentPage().getParameters().get('id'));
        
        pr.setredirect(true);
        return pr; 
        
        
        
    }
    
    
    
    
}
  • May 26, 2021
  • Like
  • 0