• Archana Pawar 30
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 1
    Replies
Hi Team, 
I have a similar problem, pdf is getting saved twice in attachment section

This is my First Page- 9calling 'SaveAttach' method in first page
<apex:page standardController="Proforma_Invoice__c" extensions="TemplateController" action="{!saveAttach}" renderAs="pdf">

This is my second page- <apex:page standardController="Proforma_Invoice__c" extensions="TemplateController" renderAs="pdf">

and this is my controller class-  Public void saveAttach() {
        try {
            System.debug('Inside saveAttach');
            
            // Check if the attachment already exists
        if (hasAttachment()) {
            System.debug('Attachment already exists. Skipping saveAttach.');
            return;
        }
            PageReference pdfPage = Page.Proforma_InvoiceV2;
            pdfPage.getParameters().put('id',profInv.id);
            Blob pdfBlob = pdfPage.getContent();
            Attachment a = new Attachment(parentId = profInv.id, name=profInv.name + '-ProformaInvoice.pdf', body = pdfBlob);
            insert a;
        } catch (Exception e) {
            system.debug('an error occured: '+e.getMessage());
        }
    }
    private Boolean hasAttachment() {
    // Query attachments with the same parent ID
    List<Attachment> attachments = [SELECT Id FROM Attachment WHERE ParentId = :profInv.id LIMIT 1];
    return !attachments.isEmpty();
}

 
Hi Team,
I want to use Live chat function of salesfore? can you please help me with the pricing details, whether this functionality is free of cost or chargeble?

Thanks in advance..
Hi Team,

Can you please help me out with below detail.
i want to use ClicktoCreate feature of salesforce Maps and currently working on consumer goods cloud.
But, while creating records for using Click2Create 'Retail Store' object is not showing visible to select.

Please help.
Thank you in advance.
Could you please tell me how do i get Record Ids per batch seperately?
For example i have written batch class on Account (xyz logic),i want to show record ids like-
Batch1- This record ids has been updated
Batch2- This record ids has been updated
and so on
Requirement- Create a field in Account -NumOfContact__c (This field should be a picklist values-1,2,3,4,5)
Whenever i selected '1' then 1 contact should be added automatically in related list.
further, if i selected '2' then again only 1 contact should be created (because we have already  1 contact) .
That means this picklist field value (NumOfContact__c) should be same as the no.of contacts in the related list.

I have written below case but same is not working please help me out


trigger TESTINGCONTACTS on Account (before update) {
    List<Contact> contactToInsert = new List<Contact>();
    List<Contact> contactToDelete = new List<Contact>();
    
    if (trigger.IsBefore && trigger.Isupdate){
        List<Account> accRecs = [select id, NumOfContacts__c,(SELECT Id FROM contacts) FROM Account WHERE id IN: trigger.newmap.keyset()];
        
        for (Account acc: accRecs){
            if(acc.Contacts.size()>0){
                Integer contactRecsSize = acc.Contacts.size();
                Integer AccNumFieldVal = Integer.valueof(acc.NumOfContacts__c);
            if (AccNumFieldVal > contactRecsSize){
                Integer  totalConsToInsert = AccNumFieldVal - contactRecsSize;
                for (Integer i=0;i<=totalConsToInsert;i++){
                    contact con = new contact();
                    con.lastName= 'conRec'+i;
                    contactToInsert.add(con);
                }
                    
                }else{
                    Integer totalConsToDelete = contactRecsSize - AccNumFieldVal;
                    Integer tecCount = 0;
                    for(contact con:acc.contacts){
                        if(totalConsToDelete != tecCount){
                         contactToDelete.add(con);   
                            tecCount++;
                        }
                    }
                 
                }
             
            }else{
                for(integer i=0; i <= Integer.valueof(acc.NumOfContacts__c);i++){
                    contact con = new contact();
                    con.lastName = 'conRec'+i;
                    contactToInsert.add(con);
                        
                }
            }
     
        }
        if(contactToInsert.size() > 0){
            insert contactToInsert;
        }
           if(contactToDelete.size() > 0){
            delete contactToDelete;
        }
    }
}
Could you please tell me how do i get Record Ids per batch seperately?
For example i have written batch class on Account (xyz logic),i want to show record ids like-
Batch1- This record ids has been updated
Batch2- This record ids has been updated
and so on