• H 007
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 9
    Replies
Hi, I need to setup a integration from Sitecore to Salesforce. So anyone please help me to send data from Sitecore to Salesforce..
  • September 22, 2022
  • Like
  • 1
Hi, right now I am working with fieldset in salesforce, I just developed a LWC component for show filedset set with progress bar, but now I am trying to add inline editing functionally but progress bar is not working can anyone plese help me.
import { LightningElement, api, wire, track} from 'lwc';
// import { refreshApex } from '@salesforce/apex';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import getFieldSetMetadata from '@salesforce/apex/FieldsetController.getFieldSetMetadata';

export default class Fieldset extends LightningElement {

    @api showTitle;
    @api strTitle;
    @api iconName;
    @api showProgress;
    @api columnsLarge;
   
    @api fieldSetName;
    @api isEditable;
    @api alwaysEditing;
    @api saveMessageTitle;
    @api saveMessage;
    @api recordId;
    @api recordTypeId;

    @track sObjectName;
    @track recordFields = [];
    @track metadataError;

    @track isLoading = true;
    @track isEditing = false;
    @track hasChanged = false;
    @track isSaving = false;
    @track layoutSizeLarge;
   
    @track fieldCount;
    @track count;
    @track hasRen=false;
    @track hasLoad=false;
    @api progress;
    
    showEditField=false;
    arrayOfFields=[];
    acc;

   
     handleChange()
    {
        this.count=0;
        var c=0;
        // const formValue=this.template.querySelectorAll('lightning-record-form')
        // console.log('form values = '+JSON.stringify(formValue))
        // const demoInput = this.template.querySelector('lightning-input[data-anyName=anyValue]').value;
        // console.log('demoInput '+ demoInput);

        const inputFields = this.template.querySelectorAll(
            'lightning-input-field'
        ); 
        const outputFields = this.template.querySelectorAll(
            'lightning-output-field'
        );
            console.log('input fields -> '+JSON.stringify(inputFields))
            console.log('output fields -> '+outputFields)
    //    console.log(JSON.stringify(inputFields.length));
    //     console.log(JSON.stringify(outputFields.length));
    //   console.log('hello'+JSON.stringify(outputFields));
      //  console.log('hello1'+JSON.stringify(inputFields));
    
        if (inputFields) 
        {   
            inputFields.forEach(field => {
                console.log(field.fieldName +'-> ' +field.value);
                // console.log();

                if(field.value!=='' && field.value!==null && field.value!=undefined && field.value!=false) 
                {
                    this.count=this.count+1;

                }
                
            });
            // if (event.target.checked){this.count=count+1}
        } console.log('count of all input fields is'+ this.count);
         console.log('fieldCount'+this.fieldCount );

        if (outputFields) 
        {
            
           // console.log('hi'+JSON.parse(JSON.stringify(outputFields[0].outerText)));
            outputFields.forEach(field => {
                var fld=field.outerText.split('\n')[1];
                

                // console.log('dc  '+field.outerText.split('\n'));
                console.log('field name '+ JSON.stringify(field.fieldName));
                console.log('field value '+fld);
                if(fld!==undefined && fld!=='' && fld!==null)
                {

                    c=c+1;
                    this.count=this.count+1;
          
                }
                
            });
        }
        // console.log('coount '+this.count);
    //    console.log('output field count'+c);

        this.progress=parseInt((this.count*100)/ this.fieldCount);
       
    }
    
    @wire(getFieldSetMetadata, {
        recordId: '$recordId',
        fieldSetName: '$fieldSetName'
    })
    wiredFieldSetMetadata(value) {
        this.acc=value;
        const { data, error } = value;
        
        this.isLoading = true;
        if (data) {
                this.arrayOfFields=new Array();
           // console.log(JSON.stringify(data.fieldsMetadata));
           // console.log(data.fieldsMetadata.length);
            this.fieldCount=data.fieldsMetadata.length;
            // Get the FieldSet Name if we have no custom title
            if (!this.strTitle) this.strTitle = data.fieldSetLabel;
            // Get the Record Type Id
            this.recordTypeId = data.recordTypeId;
            // Get the SObject Name
            this.sObjectName = data.sObjectName;
            // If we have record fields, Remove them all
            if (!!this.recordFields.length)
                while (this.recordFields.length > 0) this.recordFields.pop();
            // Get the fields metadata and populate fields
            data.fieldsMetadata.forEach((fd) => {
                // Get valid JSON
                const fieldProperties = JSON.parse(fd);
                const {
                    fieldSetProperties,
                    fieldDescribeProperties
                } = fieldProperties;
                // Add the field
                
                this.arrayOfFields.push(fieldDescribeProperties.name)
                
                this.recordFields.push({
                    name: fieldDescribeProperties.name,
                    isRequired: fieldSetProperties.isRequired || fieldSetProperties.dbRequired,
                    isUpdateable: !!fieldDescribeProperties.updateable,
                    editable: this.isEditing && !!fieldDescribeProperties.updateable
                });
            }); 
            console.log('array of fields ',this.arrayOfFields);
            // Clear any errors
            this.metadataError = undefined;
            this.handleChange();
        } else if (error) {
            this.metadataError = 'Unknown error';
            if (Array.isArray(error.body)) {
                this.metadataError = error.body.map(e => e.message).join(', ');
            } else if (typeof error.body.message === 'string') {
                this.metadataError = error.body.message;
            }
            console.error('getMetadata error', this.metadataError);
        }
        if (this.recordFields.length || this.metadataError) this.isLoading = false;
      //  this.handleChange();
    //   if(this.refreshcnt==0)
    //   {
    //     refreshApex(this.acc);
    //     this.refreshcnt++;
    
    //   }
    this.handleChange();
    }

   
    // Get the card Title if we should show it
    get cardTitle() {
        return this.showTitle ? this.strTitle : null;
    }

    // Show spinner error propertys
    get showSpinner() {
        return this.isLoading || this.isSaving;
    }

    // Show the record form
    get showForm() {
        return !this.isLoading && !!this.sObjectName && !this.metadataError;
    }

    // Check if we can edit
    get editLabel() {
        return this.isEditing ? 'Cancel' : 'Edit';
    }

    // Check if we can edit
    get canEdit() {
        return this.isEditable && !this.alwaysEditing && !!this.recordFields.length;
    }

    // Check if we can save, we need fields
    get canSave() {
        return (this.canEdit || this.alwaysEditing) && this.isEditing && this.hasChanged && !!this.recordFields.length;
    }

    // Show a UI Message
    showToastEvent(title, message, variant) {
        const event = new ShowToastEvent({
            title,
            message,
            variant
        });
        this.dispatchEvent(event);
    }


    // Set the has changed to true
    setHasChanged() {
        this.handleChange();
        this.hasChanged = true;
    }

    // Handle the form Submit callback
    handleFormSubmit() {
        // Show spinner
        this.isSaving = true;
    };

    // Handle the form Success callback
    handleFormSuccess() {
        // Hide spinner
        this.isSaving = false;
        // No more changes to save
        this.hasChanged = false;
        // Show success message
        this.showToastEvent(this.saveMessageTitle, this.saveMessage, 'success');
    };

    // Handle the form Error callback
    handleFormError() {
        // Hide spinner
        this.isSaving = false;
    };
}
  • August 22, 2022
  • Like
  • 0
public class OpportunityPdfController {
		
	
    
    @future(callout=true)
      
    public static void pdfGenration(Map<Id, Id> oppIdWithAccId){  
        Set<Id> OppIds=oppIdWithAccId.keySet();
        System.debug('OPPIDS'+ OppIds);

        Map<Id, ContentVersion> contentVersionMap = createContentVersion(OppIds, oppIdWithAccId);
        createContentDocumentLink(contentVersionMap);       
        
    }

    private static Map<Id, ContentVersion> createContentVersion(Set<Id> OppIds, Map<Id, Id> oppIdWithAccId){

        System.debug('OPPIDS2'+ OppIds);
        Map<Id, ContentVersion> contentVersionMap = new Map<Id, ContentVersion>(); 
		Blob body;        
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        List<Messaging.EmailFileAttachment> attachList = new List<Messaging.EmailFileAttachment>();
        List<String> sendTo= new List<String>();
        
		List<Contact>  conList=[SELECT Id, AccountId, Email FROM Contact WHERE AccountId IN: oppIdWithAccId.values() AND Email!=Null];
       
        system.debug('conList'+conList );
        
       Map<Id, String> oppIdWithEmail= new Map<Id, String>();  
         
        for(Id OppId: OppIds)
        {		
            PageReference pdf = new PageReference('/apex/InvoicePDF');
            pdf.getParameters().put('Id',OppId);     
            
            ContentVersion cv=new ContentVersion();            
            try{   
                
                body=pdf.getContentAsPDF();
                System.debug('body : ' + body);
                
            }
            catch (Exception e) {
                
                body = Blob.valueOf('Text');
                System.debug(e.getMessage());
            }                     
            cv.PathOnClient= 'Invoice'+'.pdf';            	
            cv.Title= 'Invoice'+' '+ Date.today();
            cv.IsMajorVersion = true;  
            cv.VersionData=body;  
            
            contentVersionMap.put(OppId, cv);    
          
        } 
        if(!contentVersionMap.Values().isEmpty()){      
        
            insert contentVersionMap.Values(); 
            for(Id oid:  contentVersionMap.keySet()){
                
                Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment();
                attach.setContentType('.pdf/txt');
                attach.setFileName('Invoice.pdf');
                attach.setInline(false);
                attach.Body = contentVersionMap.get(oid).VersionData; 
                attachList.add(attach);
                
            }
            For(Contact mailList: conList){               
          
                
            Messaging.SingleEmailMessage  mail= new Messaging.SingleEmailMessage();
            
            sendTo.add(mailList.Email);
                
            system.debug('EmailList'+ sendTo);
            mail.setToAddresses(sendTo);
            mail.setSubject('Product Invoice');
            mail.setHtmlBody('');
       		mail.setFileAttachments(attachList);            
            mails.add(mail);         
            
        }
          Messaging.sendEmail(mails);            
      
        }return contentVersionMap;      
          
    }

    private static void createContentDocumentLink(Map<Id, ContentVersion> idOppContentVersionMap){

        Map<Id, Id> idConDocMap = new Map<Id, Id>();
        List<ContentDocumentLink> ContentDocumentLinkList = new List<ContentDocumentLink>();

        for(ContentVersion cv : [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:idOppContentVersionMap.Values()])
        {
            idConDocMap.put(cv.Id, cv.ContentDocumentId);
        }

        if(idConDocMap.isEmpty()) return;

        for(Id OppId : idOppContentVersionMap.keySet()){

            ContentVersion contentVersion = idOppContentVersionMap.get(OppId);

            ContentDocumentLink cdl = New ContentDocumentLink();
            cdl.LinkedEntityId = OppId;           
            cdl.ContentDocumentId = idConDocMap.get(contentVersion.Id);           
            cdl.shareType = 'V';
            
            ContentDocumentLinkList.add(cdl);

        }
		if(!ContentDocumentLinkList.isEmpty()){    
       		insert ContentDocumentLinkList;            
        } 
    }   

}

 
  • August 12, 2022
  • Like
  • 0
Trigger:
trigger PDFGenrate on Opportunity (after insert, after update) {
	 
   Set<Id> OppIds= new Set<Id>();
    
    for(Opportunity opp: trigger.new){        
        if(opp.StageName=='Closed Won'){            
         OppIds.add(Opp.Id);             
        } 
       }OpportunityPdfController.pdfGenration(OppIds);      
}

Trigger Handler: 
public class OpportunityPdfController {
    
    @future(callout=true)
    public static void pdfGenration(Set<Id> OppIds){
        List<Sobject> attachmentlist = new List<Sobject>();
        List<Sobject> ContentDocLink = new List<Sobject>();
        for(Id OppId: OppIds){

            Blob body;
            
                    PageReference pdf = new  PageReference('/apex/PrintPDF');
                    pdf.getParameters().put('Id',OppId);     
                  
                    ContentVersion cv=new ContentVersion();            
                    try{                
                        body=pdf.getContentAsPDF();
                    }catch (Exception e) {
                        body = Blob.valueOf('Text');
                        system.debug(e.getMessage());
                    }                     
                    cv.PathOnClient= 'Invoice'+'.pdf';            	
                    cv.Title= 'Invoice';
                    cv.IsMajorVersion = true;  
            		cv.VersionData=body;
                    attachmentlist.add(cv);     
            
        //   }     
     
     //  if(attachmentlist.size()>0){
            insert  attachmentlist;              
            
            
            Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cv.Id].ContentDocumentId;
            system.debug(conDocId);
            ContentDocumentLink cdl = New ContentDocumentLink();

            cdl.LinkedEntityId = OppId;
            
            cdl.ContentDocumentId = conDocId;
            
            cdl.shareType = 'V';
            
        ContentDocLink.add(cdl);
            insert ContentDocLink;
            
        }
        
    }
}

 
  • August 03, 2022
  • Like
  • 0
Hi Everyone I have one cusotm object "cus_project__c" and one custome filed which name is Product Family( General, Stationery and other  ) , so I want when order is actived then in cus_project __c record will be created when according to product family. For Ex: If in order we are added one product and which project family is General then project record will be created with the name of "General" and all greneral category record will be store in this project.
 
So can any one please help me for resolve this issue with the help of trigger.
I Just write the following code but the project record is not created. 
trigger CreateProject on Order (after insert, after update) {
    List<cus_project__c> prolist= new List<cus_project__c>();
    List<Id> productId = new List<Id>();
    List<Id> priceBookid = new List<Id>();
    Set<Id> orderId= new Set<Id>();
    Set<Id> orderRecId= new Set<Id>();
    
    List<Product2> productlist=[SELECT id, Family from Product2 where id IN : productId];// to get all products.
    for(Order ord: trigger.new)
    {
        if(ord.Activated__c == true && (trigger.oldMap==Null || trigger.oldMap.get(ord.id).Activated__c==false) ) 
        {  
            orderId.add(ord.id);            
           
        }      
        for(Product2 p2: productlist){
                if(p2.family=='other'){
                    if(!prName.contains('other')){
                        Cus_project__c pro1= new Cus_project__c();
                        pro1.Order__c= ord.id;
                        pro1.Name='other';
                        pro1.Start__c=system.today();
                        pro1.End__c=system.today()+80;
                        prolist.add(pro1);  
                    }                      
                }             
            } 
    } 	insert prolist;   
      list<OrderItem> orderIds =[select Product2Id, PricebookEntryId from OrderItem where OrderId in :orderId];// Find OrderProduct ids 
            for(integer i=0;i<orderIds.size();i++){ 
                productId.add(orderIds.get(i).Product2Id);  // Find productsIds
                priceBookid.add(orderIds.get(i).PricebookEntryId);  // Find PriceBooks Ids                      
            }          
         List<cus_project__c> orderRec= [SELECT ID, Name FROM cus_project__c WHERE Order__c In :orderId]; // To get all project of Order.
            List<String> prName= new List<String>();
            for(integer i=0;i<orderRec.size();i++){
                prName.add(orderRec.get(i).Name);                        
            } 
    
     
    
        }

 
  • July 09, 2022
  • Like
  • 0
public  with sharing class ProjectClass {    
     public List<Cus_Project__c> proj{get;set;}//show Order Data 
        Public Cus_Project__c pr{get;set;} 
     Public Cus_Project__c project{get;set;}
     Public Boolean isEditable {get;set;}       
        
     Public ProjectClass(){ 
          project=[Select Id, name,Order__c,Start__c, End__c,Project_Amount__c, Total_Cost__c,Status__c
                 from Cus_Project__c where id =:ApexPages.currentPage().getParameters().get('id')];         
        
         isEditable= false;     }   
    
     Public void getProject(){
        pr=[Select Id, name,Order__c,Start__c, End__c,Project_Amount__c, Total_Cost__c,Status__c
                 from Cus_Project__c where id =:ApexPages.currentPage().getParameters().get('id')];
     }    
   public PageReference Savepr(){
       
              update project;
            pageReference pnext = new PageReference('/apex/ProjectDetailPage?id='+pr.id);
            pnext.setRedirect(true);
            return pnext;                 
    }   
     public void recEdit(){
         isEditable= true;
         system.debug('Project Callaed');
    }
}

VF: 
<apex:page  controller="ProjectClass" action="{!getProject}" lightningStylesheets="true">
  <apex:form>             
      <script  type="text/javascript">
          function validate(){
             if(document.getElementById('{!$Component.form.pb1.ps1.Start__c}').value==''){
                if(document.getElementById('{!$Component.form.pb1.ps1.Status__c}').value=='In Progress'){
                        alert('Unable to update');
                }
            } else{                
                acc();               
            }       
        }
      </script>
       <apex:pageBlock rendered="true" >              
            <apex:pageBlockSection title=" Project Information" columns="2" >                
                <apex:outputField value="{!pr.Name}"/>
                <apex:outputField value="{!pr.Order__c}"/> 
                <apex:outputField value="{!pr.Start__c}"/>
                <apex:outputField value="{!pr.End__c}"/>
                <apex:outputField value="{!pr.Status__c}"/>
                <apex:outputField value="{!pr.Project_Amount__c}"/>
                <apex:outputField value="{!pr.Total_Cost__c}"/>             
            </apex:pageBlockSection>
       </apex:pageBlock>
  </apex:form>     
        <apex:form id='form'>   
              <apex:actionFunction action="{!savepr}" Name="acc"></apex:actionFunction>
    <apex:pageBlock rendered="true" id="pb1">           
            <apex:pageBlockSection title=" Project Information" columns="2" id="ps1">                
                <apex:inputField value="{!project.Name}"/>
                <apex:inputField value="{!project.Order__c}"/>
                <apex:inputField value="{!project.Start__c}" id="Start__c"/>
                <apex:inputField value="{!project.End__c}"/>
                <apex:inputField value="{!project.Status__c}" id="Status__c"/>
                <apex:inputField value="{!project.Project_Amount__c}"/>
                <apex:inputField value="{!project.Total_Cost__c}"/>             
            </apex:pageBlockSection>
         <apex:pageBlockButtons >
                <apex:commandButton value="SaveData" onclick="validate();"/>
            </apex:pageBlockButtons>
    </apex:pageBlock> 
  </apex:form>
   </apex:page>
  • May 30, 2022
  • Like
  • 0
Order Detail Page:
<apex:page standardController="Order" action="{!details}" extensions="OrderClass" lightningStylesheets="true">
    
  <apex:form >
     <script>
        function fun(){
            EditProject();
      }
    </script>
    <apex:pageBlock rendered="{!ShowpageDetailPage}">
            <apex:pageBlockSection title="Order Record Information" columns="2" >
                <apex:outputField value="{!Order.Name}"/>
                <apex:outputField value="{!Order.OrderNumber}"/>
                <apex:outputField value="{!Order.AccountId}"/>
                <apex:outputField value="{!Order.OpportunityId}"/>
                <apex:outputField value="{!Order.Type}"/>
                <apex:outputField value="{!Order.CurrencyIsoCode}"/>
                <apex:outputField value="{!Order.CompanyAuthorizedById}"/>
                <apex:outputField value="{!Order.CustomerAuthorizedDate}"/>
                <apex:outputField value="{!Order.ShipToContactId}"/>
                <apex:outputField value="{!Order.Project_Start_Date__c}"/>
                <apex:outputField value="{!Order.Project_End_Date__c}"/>
                <apex:outputField value="{!Order.Activated__c}"/>
                <apex:outputField value="{!Order.Invoice_Date__c}"/>
                <apex:outputField value="{!Order.TotalAmount}"/>
                <apex:outputField value="{!Order.Close_Date__c}"/>
                <apex:outputField value="{!Order.Description}"/>                  
            </apex:pageBlockSection>  
        <apex:pageBlockButtons >
                <apex:commandButton value="Edit"  action="{!ShowBlockMethod}"/>
            </apex:pageBlockButtons>                  
    </apex:pageBlock>
  </apex:form> 
    
    <apex:form >
    <apex:pageBlock rendered="{!ShowpageEditPage}">
            <apex:pageBlockSection title="Order Record Information" columns="2" >
                <apex:inputField value="{!Order.Name}"/>
                <apex:inputField value="{!Order.OrderNumber}"/>
                <apex:inputField value="{!Order.AccountId}"/>
                <apex:inputField value="{!Order.OpportunityId}"/>
                <apex:inputField value="{!Order.Type}"/>
                <apex:inputField value="{!Order.CurrencyIsoCode}"/>
                <apex:inputField value="{!Order.CompanyAuthorizedById}"/>
                <apex:inputField value="{!Order.CustomerAuthorizedDate}"/>
                <apex:inputField value="{!Order.ShipToContactId}"/>
                <apex:inputField value="{!Order.Project_Start_Date__c}"/>
                <apex:inputField value="{!Order.Project_End_Date__c}"/>
                <apex:inputField value="{!Order.Activated__c}"/>
                <apex:inputField value="{!Order.Invoice_Date__c}"/>
                <apex:inputField value="{!Order.TotalAmount}"/>
                <apex:inputField value="{!Order.Close_Date__c}"/>
                <apex:inputField value="{!Order.Description}"/>                  
            </apex:pageBlockSection>  
        <apex:pageBlockButtons >
                <apex:commandButton value="Save"  action="{!Save}"/>
            </apex:pageBlockButtons>                  
    </apex:pageBlock>
  </apex:form> 
     <apex:form >
    <apex:pageBlock >  
        <apex:actionFunction action="{!recEdit}" Name="EditProject" immediate="true"></apex:actionFunction>
        <apex:pageBlockTable title="Releted Record" value="{!releted}" var="r"> 
              <apex:column >
                <apex:outputLink value="/apex/ProjectDetailPage?id={!r.id}">Del | </apex:outputLink>            
                <apex:outputLink onclick="fun();" value="/apex/ProjectDetailPage?id={!r.id}" >Edit | </apex:outputLink>     
             </apex:column> 
            <apex:column >
                 <apex:outputLink value="/apex/ProjectDetailPage?id={!r.id}"> {!r.name}</apex:outputLink>
             </apex:column> 
             <apex:column value="{!r.Start__c}"/>
            <apex:column value="{!r.End__c}"/>
            <apex:column value="{!r.Status__c}"/>
            <apex:column value="{!r.Project_Amount__c}"/>
            <apex:column value="{!r.Total_Cost__c}"/>            
        </apex:pageBlockTable>               
    </apex:pageBlock>
       </apex:form>     
</apex:page>
Related Object VF page
<apex:page controller="ProjectClass" action="{!getProject}" lightningStylesheets="true">
  <apex:form >  
       <apex:pageBlock rendered="true" >              
            <apex:pageBlockSection title=" Project Information" columns="2" >                
                <apex:outputField value="{!pr.Name}"/>
                <apex:outputField value="{!pr.Order__c}"/>
                <apex:outputField value="{!pr.Start__c}"/>
                <apex:outputField value="{!pr.End__c}"/>
                <apex:outputField value="{!pr.Status__c}"/>
                <apex:outputField value="{!pr.Project_Amount__c}"/>
                <apex:outputField value="{!pr.Total_Cost__c}"/>             
            </apex:pageBlockSection>
       </apex:pageBlock>
  </apex:form>     
      <apex:form >  
    <apex:pageBlock rendered="isEditable">           
            <apex:pageBlockSection title=" Project Information" columns="2" >                
                <apex:inputField value="{!pr.Name}"/>
                <apex:inputField value="{!pr.Order__c}"/>
                <apex:inputField value="{!pr.Start__c}"/>
                <apex:inputField value="{!pr.End__c}"/>
                <apex:inputField value="{!pr.Status__c}"/>
                <apex:inputField value="{!pr.Project_Amount__c}"/>
                <apex:inputField value="{!pr.Total_Cost__c}"/>             
            </apex:pageBlockSection>
         <apex:pageBlockButtons >
                <apex:commandButton value="Save"  action="{!Save}"/>
            </apex:pageBlockButtons>
    </apex:pageBlock> 
  </apex:form>
   </apex:page>
public with sharing class OrderClass {
   public Order orderRecord { get; set; }
    public Boolean ShowpageEditPage {get; set;}
    public Boolean ShowpageDetailPage {get; set;}
    Public List<Cus_Project__c> releted{get;set;}
    public OrderClass (ApexPages.StandardController controller) {
        ShowpageEditPage=false;
        ShowpageDetailPage=true;    
     }     
      Public void ShowBlockMethod(){
       ShowpageEditPage =true;
      ShowpageDetailPage= false;
    }        
        Public void details(){                      // Use for Show Releted  Record  on Detailpage       
       
        releted=[Select Id, name, Order__c,Start__c, End__c,Project_Amount__c, Total_Cost__c,Status__c
                 from Cus_Project__c where Order__c =:ApexPages.currentPage().getParameters().get('id')];
    } 
}
public with sharing class ProjectClass {
    
     public List<Cus_Project__c> proj{get;set;}//show Order Data 
        Public Cus_Project__c pr{get;set;}
     Public Boolean isEditable {get;set;}
    
     Public ProjectClass(){
         isEditable= false;
     }   
    
     Public void getProject(){
        pr=[Select Id, name,Order__c,Start__c, End__c,Project_Amount__c, Total_Cost__c,Status__c
                 from Cus_Project__c where id =:ApexPages.currentPage().getParameters().get('id')];       
    }
     public PageReference Save(){
            update pr;
            PageReference pnext = new PageReference('/apex/ProjectDetailPage?id='+pr.id);
            pnext.setRedirect(true);
            return pnext;
    }    
    Public void recEdit(){
        isEditable= true;
    }
}
  • May 28, 2022
  • Like
  • 0
global class BatchOnContact implements Database.Batchable<sObject>, Database.Stateful{
    
    global Database.QueryLocator start(Database.BatchableContext bc){     
        
        return Database.getQueryLocator('select Id, name, StageName from opportunity where StageName=\'Closed Won\'');
        
    }
    global void execute(Database.BatchableContext bc, List<opportunity> Opplist){
        List<OpportunityLineItem> OList = new List<OpportunityLineItem>();
        List<Product2> prolist= [SELECT Id from Product2 Limit 10];
              For(opportunity opp:  Opplist){
            for(Integer i=0; i<10; i++){
               OpportunityLineItem op= new OpportunityLineItem(opportunityId=opp.id, Product2Id=prolist.get(i).id,Quantity =1, TotalPrice=1000);
                OList.add(op);                                                               
            }  opp.Pricebook2Id='0066F00000yUeDpQAK';            
        }update opplist;
        insert OList;      
    }
 global void finish(Database.BatchableContext bc){ }
}
  • May 25, 2022
  • Like
  • 0
public with sharing class CusOrderData {
    public List<Cus_Order__c> order{get;set;}//show Order Data 
   public Cus_Order__c orderdata{get;set;}
     public Object items{get;set;}
 
    public CusOrderData(){
        orderdata=new Cus_Order__c();
        order=[SELECT Name,Activated__c,Order_Start_Date__c,Order_End_Date__c,Invoice_Date__c,
               Project_Start_Date__c, Project_End_Date__c, Down_payment_amount__c FROM Cus_Order__c];// Show Order Data   
         items = [SELECT Id, name FROM Cus_Order__c where Id=:ApexPages.currentpage().getparameters().get('Id')];
        system.debug(items); 
    }   
   public PageReference Save(){
           upsert order;
               PageReference pnext = new PageReference('/apex/CusOrderData?id='+orderdata.id);
                pnext.setRedirect(true);
            return pnext;
    }
    public void Edit(){                    
    }
}

VF page:
<apex:page controller="CusOrderData" lightningStylesheets="true" tabStyle="Account">
    <apex:form >
        <apex:pageBlock title="Order Edit Page">
               
                <apex:pageBlockSection >                
                <apex:inputField value="{!orderdata.Name}" />
                <apex:inputField value="{!orderdata.Activated__c}" />    
                <apex:inputField value="{!orderdata.Invoice_Date__c}"/>
                <apex:inputField value="{!orderdata.Project_Start_Date__c}"/>
                <apex:inputField value="{!orderdata.Project_End_Date__c}"/>
                <apex:inputField value="{!orderdata.Order_Start_Date__c}"/>
                <apex:inputField value="{!orderdata.Order_End_Date__c}"/>
                <apex:inputField value="{!orderdata.Down_payment_amount__c}"/> 
                    </apex:pageBlockSection>
            
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!Save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
  • May 18, 2022
  • Like
  • 0
public class UpdateMinDateHandler {
    
    Public static Boolean firstcall=false; // Stop the Recursive Calling
    Public static void triggerCall(List<Cus_Project__c> newRecordList){
        Set<Id> OrderId= new Set<Id>();
    List<Cus_Order__c> orderlist= new List<Cus_Order__c>();
    for(Cus_Project__c proj: newRecordList){
        OrderId.add(proj.Cus_Order__c);
    }   
    List<AggregateResult> resultlist= [SELECT Cus_Order__c, Min(Start__c)mindate, Max(End__c)maxdate FROM Cus_Project__c 
                                      where Cus_Order__c IN: OrderId group by Cus_Order__c ];
    List<Cus_Order__c> Updatedata=new  List<Cus_Order__c>();
    system.debug(resultlist);
    for(AggregateResult result:resultlist )
    {
      Updatedata.add(new  Cus_Order__c(Id = (Id)result.get('Cus_Order__c'),
                                      Order_Start_Date__c=(date)result.get('mindate'),
                                      Order_End_Date__c=(date)result.get('maxdate')));
     }
    update Updatedata;
    }

}
  • May 17, 2022
  • Like
  • 0
Hi, I need to setup a integration from Sitecore to Salesforce. So anyone please help me to send data from Sitecore to Salesforce..
  • September 22, 2022
  • Like
  • 1
Trigger:
trigger PDFGenrate on Opportunity (after insert, after update) {
	 
   Set<Id> OppIds= new Set<Id>();
    
    for(Opportunity opp: trigger.new){        
        if(opp.StageName=='Closed Won'){            
         OppIds.add(Opp.Id);             
        } 
       }OpportunityPdfController.pdfGenration(OppIds);      
}

Trigger Handler: 
public class OpportunityPdfController {
    
    @future(callout=true)
    public static void pdfGenration(Set<Id> OppIds){
        List<Sobject> attachmentlist = new List<Sobject>();
        List<Sobject> ContentDocLink = new List<Sobject>();
        for(Id OppId: OppIds){

            Blob body;
            
                    PageReference pdf = new  PageReference('/apex/PrintPDF');
                    pdf.getParameters().put('Id',OppId);     
                  
                    ContentVersion cv=new ContentVersion();            
                    try{                
                        body=pdf.getContentAsPDF();
                    }catch (Exception e) {
                        body = Blob.valueOf('Text');
                        system.debug(e.getMessage());
                    }                     
                    cv.PathOnClient= 'Invoice'+'.pdf';            	
                    cv.Title= 'Invoice';
                    cv.IsMajorVersion = true;  
            		cv.VersionData=body;
                    attachmentlist.add(cv);     
            
        //   }     
     
     //  if(attachmentlist.size()>0){
            insert  attachmentlist;              
            
            
            Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cv.Id].ContentDocumentId;
            system.debug(conDocId);
            ContentDocumentLink cdl = New ContentDocumentLink();

            cdl.LinkedEntityId = OppId;
            
            cdl.ContentDocumentId = conDocId;
            
            cdl.shareType = 'V';
            
        ContentDocLink.add(cdl);
            insert ContentDocLink;
            
        }
        
    }
}

 
  • August 03, 2022
  • Like
  • 0
Hi Everyone I have one cusotm object "cus_project__c" and one custome filed which name is Product Family( General, Stationery and other  ) , so I want when order is actived then in cus_project __c record will be created when according to product family. For Ex: If in order we are added one product and which project family is General then project record will be created with the name of "General" and all greneral category record will be store in this project.
 
So can any one please help me for resolve this issue with the help of trigger.
I Just write the following code but the project record is not created. 
trigger CreateProject on Order (after insert, after update) {
    List<cus_project__c> prolist= new List<cus_project__c>();
    List<Id> productId = new List<Id>();
    List<Id> priceBookid = new List<Id>();
    Set<Id> orderId= new Set<Id>();
    Set<Id> orderRecId= new Set<Id>();
    
    List<Product2> productlist=[SELECT id, Family from Product2 where id IN : productId];// to get all products.
    for(Order ord: trigger.new)
    {
        if(ord.Activated__c == true && (trigger.oldMap==Null || trigger.oldMap.get(ord.id).Activated__c==false) ) 
        {  
            orderId.add(ord.id);            
           
        }      
        for(Product2 p2: productlist){
                if(p2.family=='other'){
                    if(!prName.contains('other')){
                        Cus_project__c pro1= new Cus_project__c();
                        pro1.Order__c= ord.id;
                        pro1.Name='other';
                        pro1.Start__c=system.today();
                        pro1.End__c=system.today()+80;
                        prolist.add(pro1);  
                    }                      
                }             
            } 
    } 	insert prolist;   
      list<OrderItem> orderIds =[select Product2Id, PricebookEntryId from OrderItem where OrderId in :orderId];// Find OrderProduct ids 
            for(integer i=0;i<orderIds.size();i++){ 
                productId.add(orderIds.get(i).Product2Id);  // Find productsIds
                priceBookid.add(orderIds.get(i).PricebookEntryId);  // Find PriceBooks Ids                      
            }          
         List<cus_project__c> orderRec= [SELECT ID, Name FROM cus_project__c WHERE Order__c In :orderId]; // To get all project of Order.
            List<String> prName= new List<String>();
            for(integer i=0;i<orderRec.size();i++){
                prName.add(orderRec.get(i).Name);                        
            } 
    
     
    
        }

 
  • July 09, 2022
  • Like
  • 0
global class BatchOnContact implements Database.Batchable<sObject>, Database.Stateful{
    
    global Database.QueryLocator start(Database.BatchableContext bc){     
        
        return Database.getQueryLocator('select Id, name, StageName from opportunity where StageName=\'Closed Won\'');
        
    }
    global void execute(Database.BatchableContext bc, List<opportunity> Opplist){
        List<OpportunityLineItem> OList = new List<OpportunityLineItem>();
        List<Product2> prolist= [SELECT Id from Product2 Limit 10];
              For(opportunity opp:  Opplist){
            for(Integer i=0; i<10; i++){
               OpportunityLineItem op= new OpportunityLineItem(opportunityId=opp.id, Product2Id=prolist.get(i).id,Quantity =1, TotalPrice=1000);
                OList.add(op);                                                               
            }  opp.Pricebook2Id='0066F00000yUeDpQAK';            
        }update opplist;
        insert OList;      
    }
 global void finish(Database.BatchableContext bc){ }
}
  • May 25, 2022
  • Like
  • 0
public class UpdateMinDateHandler {
    
    Public static Boolean firstcall=false; // Stop the Recursive Calling
    Public static void triggerCall(List<Cus_Project__c> newRecordList){
        Set<Id> OrderId= new Set<Id>();
    List<Cus_Order__c> orderlist= new List<Cus_Order__c>();
    for(Cus_Project__c proj: newRecordList){
        OrderId.add(proj.Cus_Order__c);
    }   
    List<AggregateResult> resultlist= [SELECT Cus_Order__c, Min(Start__c)mindate, Max(End__c)maxdate FROM Cus_Project__c 
                                      where Cus_Order__c IN: OrderId group by Cus_Order__c ];
    List<Cus_Order__c> Updatedata=new  List<Cus_Order__c>();
    system.debug(resultlist);
    for(AggregateResult result:resultlist )
    {
      Updatedata.add(new  Cus_Order__c(Id = (Id)result.get('Cus_Order__c'),
                                      Order_Start_Date__c=(date)result.get('mindate'),
                                      Order_End_Date__c=(date)result.get('maxdate')));
     }
    update Updatedata;
    }

}
  • May 17, 2022
  • Like
  • 0