• Sahil Shitole
  • NEWBIE
  • 80 Points
  • Member since 2019

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 19
    Replies
I have a VF page that is basically created to generate a PDF document .
How do i add page breaks in this. 
The code is generating PDF and how ever i need a page break (need some content to be displayed in a fresh page).
How to do this.
Please suggest.
Getting this as Output.<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="recordList" type="List"/>
    <aura:attribute name="iden" type="String"/>    
      <aura:iteration items="{!v.recordList}" var="con">
       <div class="c-container">
        <lightning:layout horizontalAlign="spread" multipleRows="true">
             <lightning:layoutItem size="4" padding="around-small">
                 <div class="custom-box">
                 <lightning:card title="{!con.Beer_Name__c}"  iconName="custom:custom56" >
              Alcohol % : {!con.Alcohol__c}&nbsp;
                  Price : {!con.Price__c}
            <div class="slds-col slds-size_4-of-8">
                <img src="{!$Resource.BeerImage}"/>
            </div>   
              <aura:set attribute="actions">
                <lightning:button name="{!con.Id}"  label="View Details" onclick="{!c.detailspage}" variant="brand"/>
            </aura:set>
             </lightning:card>             
            </div>
            
            </lightning:layoutItem>
           </lightning:layout>

            </div>     
           </aura:iteration>      
    <div>
        <c:BeerDetails beerId="{!v.iden}"/>
    </div> 
</aura:component>

I need This as my output.
Hi ,
I have created one Apex class and its VF page.
I have 2 fields in VF page, CITY and Phone.
Target: To update the Phone of the Account whose City is given City with the given phone number.

I have created everything and update is working perfectly.
But I wanted to add a message if the update is failed. and also if the update is success.

Here is my code:
Apex Class:
public class D2 {
    public String city{get;set;}
    public String phn{get;set;}
    public boolean show{get;set;}
    public D2(){
       
    }
    public void updatePhoneNum(){
        List<account> ac = new List<account>();
        List<account> ac1 = new List<account>();
        ac =[Select name, phone, Status__c, Gender__c, BillingCity from Account where BillingCity =:city];        
        for(Account a : ac){
               a.phone =phn;
            a.Status__c = 'In Progress';
            a.Gender__c = 'Male';       
        }
        update ac1; 
    }
}

Vf Page:

<apex:page controller="D2" >
    <apex:form>
        <apex:pageBlock title=" To Update the phone number of Accounts whose City is provided">
            <apex:pageMessages />
            <apex:pageBlockSection title="Provide the details" columns="1">
                <div align = "center">
                <apex:inputText  label="City" value ="{!city}" />
                <apex:inputText  label="Phone Number" value ="{!phn}" />
                    </div>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection >
                <div align = "center">
                <apex:commandButton  style ="float:centre" value ="Update" action ="{!updatePhoneNum}"/>
                </div>
            </apex:pageBlockSection>
                
        </apex:pageBlock>
    </apex:form>
</apex:page>

Please assist
Hi All,
Below are my Controller and my Test Class. Please help me test class for code coverage 75%.
 
public class ContactDuplicationCon {
    
    private final Contact contact;
    public string accId {get; set;}
    public string accname {get; set;}
    public boolean acclookup {get; set;}
    public boolean accstring {get; set;}
    
    public Datetime activityLastDate;
    public List<ActivityHistory> activityList = new List<ActivityHistory>();
    public List<ActivityHistory> activityListcontact = new List<ActivityHistory>();
    public ContactDuplicationCon(ApexPages.StandardController controller) {
        
        // Define the values for the contact you’re processing based on its ID
        Id id = ApexPages.currentPage().getParameters().get('id');
        accId = ApexPages.currentPage().getParameters().get('accId');        
        //system.debug('accid====='+accId);
        acclookup = true;
        accstring = false;   
        if(accId != NULL){
           Account ac = [select id,name from Account where id =: accId];
            accname = ac.name;
            acclookup = false;
            accstring = true;
        }
        
        this.contact = (id == null) ? new Contact() :
        [SELECT Id, FirstName, LastName, Email, Phone, AccountId ,Sub_Division__c,Account.Sub_Division_Name__c,Address__c,Title,Active__c,Target_Audience__c,MailingStreet,
         MailingCity,MailingState,MailingPostalCode,MailingCountry,    Fax,LeadSource,AssistantName,Department FROM Contact WHERE Id = :id];
             
             }
    // Return contact and its values to the Visualforce page for display
    public Contact getContact() {
        return this.contact;    
    }
    
    public PageReference contactsave() {
        if(accId != Null){
        Contact.AccountId = accId;
        }
        Account acc = [select id,name,Sub_Division_Name__c from account where id =: contact.AccountId];
        List<Contact> cc = new List<Contact>();
        system.debug('account===='+contact.AccountId);
            cc = [Select id,lastname,firstname,email,Sub_Division__c,Account.Sub_Division_Name__c,
                  (Select id,Status,OwnerId,CreatedDate,EndDateTime,LastModifiedDate,WhoId,Priority,Subject From ActivityHistories ORDER BY LastModifiedDate ASC Limit 1)
                  from contact where email =: contact.email AND Sub_Division__c =: acc.Sub_Division_Name__c ];
        
        List<Lead> ld = [Select id,name,email,Sub_Division_Name__c,
                         (Select id,Status,OwnerId,CreatedDate,EndDateTime,LastModifiedDate,WhoId,Priority,Subject From ActivityHistories ORDER BY LastModifiedDate ASC Limit 1)
                         from Lead where email =: contact.email AND Sub_Division_Name__c =: acc.Sub_Division_Name__c];
        //system.debug('subdivision====='+acc.Sub_Division_Name__c);
        //System.debug('Contact List Size =====>'+cc.size());        
        //System.debug('Lead List Size =====>'+ld.size());
        
        //System.debug('email==='+contact.email);
        
        if(cc.size() >= 1){
            for(Contact contacts : cc){
                //System.debug('Inside ContactActivity Loop');
                for(ActivityHistory activityhiscon : contacts.ActivityHistories){
                    activityListcontact.add(activityhiscon);
                }
                System.debug('Contact Activity Size ======>'+activityListcontact.size());
                if(activityListcontact.size() <= 0){
                    //System.debug('Contact Inside Activity List');                    
                    insert contact;
                    PageReference ContactDuplication = new PageReference('/' + Contact.Id);
                    ContactDuplication.setRedirect(true);
                    return ContactDuplication;
                }else{
                    for(ActivityHistory activityhiscon : contacts.ActivityHistories){
                        //System.debug('contact ActivityHistory LastModifiedDate ====> '+activityhiscon.LastModifiedDate);
                        activityLastDate = activityhiscon.LastModifiedDate + 30;
                        //System.debug('Contact activityLastDate  ====> '+activityLastDate);
                        if(activityLastDate > System.now()){
                            User u = [select id,Name,username,email from User where id =: userInfo.getUserId()];
                            Messaging.SingleEmailMessage mail= new Messaging.SingleEmailMessage();
                            string [] toAdd = new string[]{'xyz@gmail.com'};
                                mail.setToAddresses(toAdd);
                            mail.setSubject('Contact Duplication');                            
                            mail.setPlainTextBody('Dear Admin'+
                                                  '\n\nBelow User trying to create duplicate email '+contact.email+
                                                  '\n\nName:' + u.Name+
                                                  '\nUserName : '+ u.Username +                                      
                                                  '\n\nThank You.'+
                                                  '\n\n TEAM.');
                            Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {mail};
                                Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
                            if (results[0].success) {
                                System.debug('The email was sent successfully.');
                            } else {
                                System.debug('The email failed to send: '
                                             + results[0].errors[0].message);
                            }
                        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Email already exist with same subdivision in Contact'));                        }                              
                    }                                              
                }
            }
        }
        else if(ld.size() >= 1){
            System.debug('Inside Lead Loop');
            for(Lead leads : ld){
                //System.debug('Inside LeadActivity Loop');
                for(ActivityHistory activityhis : leads.ActivityHistories){
                    activityList.add(activityhis);
                }
                //System.debug('Activity Size ======>'+activityList.size());
                if(activityList.size() <= 0){
                    System.debug('Lead Inside Activity List');
                    insert contact;
                    PageReference ContactDuplication = new PageReference('/' + Contact.Id);
                    ContactDuplication.setRedirect(true);
                    return ContactDuplication;
                }else{
                    for(ActivityHistory activityhis : leads.ActivityHistories){
                        //System.debug('Lead ActivityHistory LastModifiedDate ====> '+activityhis.LastModifiedDate);
                        activityLastDate = activityhis.LastModifiedDate + 30;
                        //System.debug('Lead activityLastDate  ====> '+activityLastDate);
                        if(activityLastDate > System.now()){
                            User u = [select id,Name,username,email from User where id =: userInfo.getUserId()];
                            Messaging.SingleEmailMessage mail= new Messaging.SingleEmailMessage();
                            string [] toAdd = new string[]{'xyz@gmail.com'};
                                mail.setToAddresses(toAdd);
                            mail.setSubject('Lead Duplication');                            
                            mail.setPlainTextBody('Dear Admin'+
                                                  '\n\nBelow User trying to create duplicate email '+contact.email+
                                                  '\n\nName:' + u.Name+
                                                  '\nUserName : '+ u.Username +                                      
                                                  '\n\nThank You.'+
                                                  '\n\nTEAM.');
                            Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {mail};
                                Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
                            if (results[0].success) {
                                System.debug('The email was sent successfully.');
                            } else {
                                System.debug('The email failed to send: '
                                             + results[0].errors[0].message);
                            }
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Email already exist with same subdivision in Lead'));                            
                        }                              
                    }                                              
                }
            }
        }
        
        else{
            insert contact;
            PageReference ContactDuplication = new PageReference('/' + Contact.Id);
            ContactDuplication.setRedirect(true);
            return ContactDuplication;
        }        
        return null;
    }
    
    public PageReference Cancel(){        
        PageReference pageRef = new PageReference('/lightning/o/Contact/list?filterName=Recent');
        pageRef.setRedirect(true);
        return pageRef;          
    }
}

-----------------------------------

@isTest
public class ContactDuplicationConTest {
    static testMethod void testMethod1(){
        lead ld = new lead ();
        ld.LastName = 'Test';
        ld.email = 'testlead@gmail.com';
        ld.Company = 'testcomp';
        ld.Status = 'Followup';
        ld.LeadSource = '360 camp';
        ld.Division_Name__c = 'test division';
        ld.Sub_Division_Name__c = 'test subdivision';        
        insert ld;
        
        Account a = new Account();
        a.Name = 'testaccount';
        a.Sub_Division_Name__c = 'Global division';
        insert a;
        
        contact con = new contact();
        con.LastName = 'testcon';
        con.AccountId = a.id;
        con.Email= 'test@gmail.com';
        insert con;
        
        Event e = new Event();
        e.WhoId=ld.id;
        e.StartDateTime=system.today();
        e.EndDateTime=system.today()+5;
        insert e;
        
        Task taskCreate = new Task();
        taskCreate.WhoId = ld.Id;
        taskCreate.Status = 'Completed';
        taskCreate.Priority = 'Normal';
        taskCreate.Subject = 'Dummy subject';
        taskCreate.ActivityDate = system.today();
        insert taskCreate;
        
        apexPages.Currentpage().getParameters().put('Id',con.id);
        Apexpages.StandardController sc = new Apexpages.StandardController(con);
        ContactDuplicationCon ext = new ContactDuplicationCon(sc);
        
        ext.cancel();
        ext.contactsave();
        ext.getContact();
    }
    
    static testMethod void testMethod2(){
        
        lead ld = new lead ();
        ld.LastName = 'Test123';
        ld.Email = 'test1232345575676579@gmail.com';
        ld.Company = 'testcomp123';
        ld.Status = 'Followup';
        ld.LeadSource = '360 camp';
        ld.Division_Name__c = 'test division';
        ld.Sub_Division_Name__c = 'test subdivision';
        insert ld;
        
        Event e = new Event();
        e.WhoId=ld.id;
        e.StartDateTime=system.today();
        e.EndDateTime=system.today()+5;
        insert e;
        
        Task taskCreate = new Task();
        taskCreate.WhoId = ld.Id;
        taskCreate.Status = 'Completed';
        taskCreate.Priority = 'Normal';
        taskCreate.Subject = 'Dummy subject';
        taskCreate.ActivityDate = system.today();
        insert taskCreate;
        
        Account a = new Account();
        a.Name = 'testaccount';
        a.Sub_Division_Name__c = 'Global division';
        insert a;        
        
        contact con1 = new contact();
        con1.LastName = 'testcon1';
        con1.AccountId = a.id;
        con1.Email = 'testcon1@gmail.com';        
        insert con1;
        
        apexPages.Currentpage().getParameters().put('Id',con1.id);
        Apexpages.StandardController sc = new Apexpages.StandardController(con1);
        ContactDuplicationCon ext = new ContactDuplicationCon(sc);
        
        ext.cancel();
        ext.contactsave();
        ext.getContact();
        
    }
}

 

Hello all,

I've been trying for awhile to create a list button that will allow the creation of multiple child records of the same parent record on one Visualforce page (rather than clicking save and new over and over). I need to pass the parent ID and assign a record type, and I'd prefer that happen without the user having to do anything other than click the button on the related list. My visualforce page works in that if I preview it, I can see each field in a column, and the "add" link is working to add new rows. However, the parent ID isn't getting passed, I can't figure out how to assign the record type ID, and the "x" link to delete a row isn't working.

I've posted on the forum about this multiple times, but have not received many replies.

This would be a huge help for the organizations I work with, and I'd be willing to pay for a few hours of someone's time to help me get the code right. Any one interested in helping me out?

  • February 04, 2020
  • Like
  • 0
I have a VF page that is basically created to generate a PDF document .
How do i add page breaks in this. 
The code is generating PDF and how ever i need a page break (need some content to be displayed in a fresh page).
How to do this.
Please suggest.
 <apex:pageblock id="pb1">
            <apex:pageblockSection id="pbs1">
                <apex:inputCheckbox id="checkbox1" label="Check Me" onclick="getCheckBoxValue();"></apex:inputCheckbox>
                <apex:inputtext id="textbox1" label="Name" onchange="gettexBoxValue();"/>
            </apex:pageblockSection>
        </apex:pageblock>
    
    <script language="javascript">
        function getCheckBoxValue()
        {
        
           
           alert(document.getElementById('{!$Component.frm1.pb1.pbs1.checkbox1}').checked);  
        }
        
         function gettexBoxValue()
        {
          
           var a=document.getElementById('{!$Component.frm1.pb1.pbs1.textbox1}');
            alert(a);  
        }
       //if iam using this iam getting.  
        function CopySubject() {
      var CaseSub= $('[id$=textbox1]').val();
       alert(CaseSub); 
       }
    </script>
Getting this as Output.<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="recordList" type="List"/>
    <aura:attribute name="iden" type="String"/>    
      <aura:iteration items="{!v.recordList}" var="con">
       <div class="c-container">
        <lightning:layout horizontalAlign="spread" multipleRows="true">
             <lightning:layoutItem size="4" padding="around-small">
                 <div class="custom-box">
                 <lightning:card title="{!con.Beer_Name__c}"  iconName="custom:custom56" >
              Alcohol % : {!con.Alcohol__c}&nbsp;
                  Price : {!con.Price__c}
            <div class="slds-col slds-size_4-of-8">
                <img src="{!$Resource.BeerImage}"/>
            </div>   
              <aura:set attribute="actions">
                <lightning:button name="{!con.Id}"  label="View Details" onclick="{!c.detailspage}" variant="brand"/>
            </aura:set>
             </lightning:card>             
            </div>
            
            </lightning:layoutItem>
           </lightning:layout>

            </div>     
           </aura:iteration>      
    <div>
        <c:BeerDetails beerId="{!v.iden}"/>
    </div> 
</aura:component>

I need This as my output.
Hi ,
I have created one Apex class and its VF page.
I have 2 fields in VF page, CITY and Phone.
Target: To update the Phone of the Account whose City is given City with the given phone number.

I have created everything and update is working perfectly.
But I wanted to add a message if the update is failed. and also if the update is success.

Here is my code:
Apex Class:
public class D2 {
    public String city{get;set;}
    public String phn{get;set;}
    public boolean show{get;set;}
    public D2(){
       
    }
    public void updatePhoneNum(){
        List<account> ac = new List<account>();
        List<account> ac1 = new List<account>();
        ac =[Select name, phone, Status__c, Gender__c, BillingCity from Account where BillingCity =:city];        
        for(Account a : ac){
               a.phone =phn;
            a.Status__c = 'In Progress';
            a.Gender__c = 'Male';       
        }
        update ac1; 
    }
}

Vf Page:

<apex:page controller="D2" >
    <apex:form>
        <apex:pageBlock title=" To Update the phone number of Accounts whose City is provided">
            <apex:pageMessages />
            <apex:pageBlockSection title="Provide the details" columns="1">
                <div align = "center">
                <apex:inputText  label="City" value ="{!city}" />
                <apex:inputText  label="Phone Number" value ="{!phn}" />
                    </div>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection >
                <div align = "center">
                <apex:commandButton  style ="float:centre" value ="Update" action ="{!updatePhoneNum}"/>
                </div>
            </apex:pageBlockSection>
                
        </apex:pageBlock>
    </apex:form>
</apex:page>

Please assist