• pokalakari naga
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 5
    Replies
Hi all,

I want to retrieve the contacts related notes using rest api. I was new to api calls.
Can anyone help me over here.

Thanks in advance.

Regards,
naga.
Hi all,

I was trying to create the custom CLONE button which clone the child object records also. For this I have used a custom vfpage and custom controller.
I want to show the child object fileds with in the same page in the edit mode. so that we can edit the values of the child record before cloneing the record.
 
<apex:page controller="ClonePlusController" action="{!initialiseObjectsForCloning}">
  
  <apex:sectionHeader title="Clone Plus: {!objectName}"/>

  <apex:form id="theform" >
   
    Please select the child objects you would like to clone.<br/><br/>
  
    <apex:repeat value="{!objectChildren}" var="child">
      <apex:PageBlock title="{!child.pluralLabel}"> 
        <apex:pageBlockTable value="{!child.objectRows}" 
                             var="objectRow">
          <apex:column headerValue="Clone" width="10%">
            <apex:inputCheckbox value="{!objectRow.selected}"/>
          </apex:column>
          <apex:column headerValue="Name" value="{!objectRow.name}" 
                                          width="90%"/>
        </apex:pageBlockTable>
      </apex:PageBlock>
    </apex:repeat>
    
    <apex:PageBlock >
      <apex:commandButton action="{!doClone}" value="Clone"/>
    </apex:PageBlock>
  </apex:form>  

</apex:page>
Custom controller
/**
* @description Helper class to clone parent and its children sObjects
*/
global without sharing class EnhancedCloneHelper {
       
    /**
    * @description Clone parent and its children
    * @param id of the parent sObject
    * @return String Serialized result
    */
    webservice static String clone (String sObjectId) {
        
        List<Sections__c> parentSObjects;
        Sections__c parent;
        CloneModel cloneModelResult = new CloneModel();
        
        // Parent query
        String query = String.format(
            'SELECT {0} FROM {1} WHERE Id = \'\'{2}\'\'',
            new String[] {
                String.join(
                    new List<String>(
                        Sections__c.SObjectType.getDescribe().fields.getMap().keySet()
                    ),
                    ','
                ),
                String.valueOf(Sections__c.SObjectType),
                sObjectId
           }
        );

        try {
            
            // Query and gets results
            parentSObjects = Database.query(query);         
            
            // Clone the original object. Here you can change anything without affecting the original sObject
            parent = parentSObjects[0].clone(false, true, false, false);
            //parent.Name = parent.Name + 'CLONED';

            Database.insert(parent);
       
        } catch (DmlException error) {
            cloneModelResult.message = 'An error occurred while cloning the object.' + error.getMessage();
            return JSON.serialize(cloneModelResult);        
        }
        
        // Children query  
        query = String.format(
            'SELECT {0} FROM {1} WHERE Sections__c = \'\'{2}\'\'',
            new String[] {
                String.join(
                    new List<String>(
                        Project_List__c.SObjectType.getDescribe().fields.getMap().keySet()
                    ),
                    ','
                ),
                String.valueOf(Project_List__c.SObjectType),
                sObjectId
           }
        );
        
        List<Project_List__c> children = new List<Project_List__c>();
        
        try {
            
            // Query and clone the children. Here you can change anything without affecting the original sObject
            for (Project_List__c child:(List<Project_List__c>)Database.query(query)) {
                children.add(child.clone(false,true,false,false));
            }
            
            // If there isn't any children ends the process and return success
            if (children.isEmpty()) {
                cloneModelResult.isSuccess = true;
                cloneModelResult.message = 'Object successfully cloned!';                
                cloneModelResult.url = getUrlRedirect(parent.Id);
                return JSON.serialize(cloneModelResult);
            }
            
            // Set the parent's Id
            for (Project_List__c child : children) {
                child.Additional_Items__c = parent.Id;
            }
        
            Database.insert(children);
    
            
        }  catch(DMLException error) {
            cloneModelResult.message = 'An error occurred while cloning the object.' + error.getMessage();
            return JSON.serialize(cloneModelResult); 
        }
        
        // Return success at the end of the process
        cloneModelResult.isSuccess = true;
        cloneModelResult.message = 'Object and its children successfully cloned!';
        cloneModelResult.url = getUrlRedirect(parent.Id);
        
        return JSON.serialize(cloneModelResult);

    }

    private static String getUrlRedirect(String sObjectId){
        PageReference page = new PageReference('/'+ sObjectId);
        return page.getUrl();
    }
    
    global class CloneModel {
        Boolean isSuccess;
        String message;
        String url;
    }
}
can anyone help me over here.

Thanks in advance.

regard,
naga

 
Hi all,

Can we clone the record along with the related list records. Can we achive this with the custom clone button or we need to create custom clone button.
If we need to create a custom clone button can anyone please help me over here.

Thanks in advacne,

Regards,
naga.
Hi all,

I want to clear the lookup field value when std.CLONE button is cliciked. I have tried with syntax below
https://cs5.salesforce.com/XXXXX0000000XXXX/e?clone=1&retURL=%XXXXXX000000XXXt&00N3A00000Cg7BD_lkid=&01I3A000002nfCG=

But the lookup value is not getting cleared. Can anyone help me overe here.

Thanks in advace.
Regarding,
naga.
Hi all,

I have two custom objects with lookup firlter relationship when i cloone the Custom object A then the related list records also need to be clone. How can we achive this. 
Can anyone help me overhere.

Thanks in advance.

Regards,
naga.
Hi all,

I have a requirement to show/hide the fields in the standar account edit page when a checkbox is checked and unchecked. Can we achive this without overriding the edit button the custom vfpage.
Can anyone suggest me over here.

Thanks in advance.

Regards,
naga.
Hi all,

I want to create custom logi page form the Force.com sites using custom controller and vfpage. Can we achive this in salesforce ..?
I'm not asking for the Portals or communities I only want to crate a custom login page and authenticate them and then redirect the user to other vfpages.

Can anyone help me over this.

Thanks in advance.

Regards,
naga.
Hi all,

I'm facing the issue with SOQL query in the example which has given in the vfpage deveploer guide. Can anyone help me over here.Below is the controller class which i have used. And the error I'm facing is
SObject row was retrieved via SOQL without querying the requested field: Account.AnnualRevenue
public class DynamicCustomizableListHandler {

    // Resources we need to hold on to across requests
    private ApexPages.StandardSetController controller;
    private PageReference savePage;

    // This is the state for the list "app"
    private Set<String> unSelectedNames = new Set<String>();
    private Set<String> selectedNames = new Set<String>();
    private Set<String> inaccessibleNames = new Set<String>();

    public DynamicCustomizableListHandler(ApexPages.StandardSetController controller) {
        this.controller = controller;
        loadFieldsWithVisibility();
    }

    // Initial load of the fields lists
    private void loadFieldsWithVisibility() {
        Map<String, Schema.SobjectField> fields = 
            Schema.SobjectType.Account.fields.getMap();
        for (String s : fields.keySet()) {
            if (s != 'Name') {  // name is always displayed 
                unSelectedNames.add(s);
            }
            if (!fields.get(s).getDescribe().isAccessible()) {
                inaccessibleNames.add(s);
            }
        }
    }

    // The fields to show in the list
    // This is what we generate the dynamic references from
    public List<String> getDisplayFields() { 
        List<String> displayFields = new List<String>(selectedNames);
        displayFields.sort();
        return displayFields;
    }
    
    // Nav: go to customize screen
    public PageReference customize() {
        savePage = ApexPages.currentPage();
        return Page.CustomizeDynamicList;
    }

    // Nav: return to list view
    public PageReference show() {
        // This forces a re-query with the new fields list
        controller.reset();
        controller.addFields(getDisplayFields());
        return savePage; 
    }

    // Create the select options for the two select lists on the page
    public List<SelectOption> getSelectedOptions() { 
        return selectOptionsFromSet(selectedNames);
    }
    public List<SelectOption> getUnSelectedOptions() { 
        return selectOptionsFromSet(unSelectedNames);
    }
    
    private List<SelectOption> selectOptionsFromSet(Set<String> opts) {
        List<String> optionsList = new List<String>(opts);
        optionsList.sort();
        List<SelectOption> options = new List<SelectOption>();
        for (String s : optionsList) {
            options.add(new 
                SelectOption(s, decorateName(s), inaccessibleNames.contains(s)));
        }
        return options;
    }

    private String decorateName(String s) {
        return inaccessibleNames.contains(s) ? '*' + s : s;
    }

    // These properties receive the customization form postback data
    // Each time the [<<] or [>>] button is clicked, these get the contents
    // of the respective selection lists from the form
    public transient List<String> selected   { get; set; }
    public transient List<String> unselected { get; set; }

    // Handle the actual button clicks. Page gets updated via a
    // rerender on the form
    public void doAdd() {
        moveFields(selected, selectedNames, unSelectedNames);
    }
    public void doRemove() {
        moveFields(unselected, unSelectedNames, selectedNames);
    }
    
    private void moveFields(List<String> items, 
            Set<String> moveTo, Set<String> removeFrom) {
        for (String s: items) {
            if( ! inaccessibleNames.contains(s)) {
                moveTo.add(s);
                removeFrom.remove(s);
            }
        }
    }
}


Thanks in advance.
Regards,
naga.
 
Hi all,

Can anyone help me to know why we use visualforce pages instard of standard page. We can customiize the standard pages but why do we use visual force page in salesforce.

Thanks in advance,

regards,
naga
Hi everyone,

Can anyone help me to write a trigger to create an Contact when an Account is created and send an email notification to the contact. In Account object I have created a custom field for email ID and create a contact.

Thanks in advance.

Regards,
naga.
Hi all,

Can anyone help me to know why we use visualforce pages instard of standard page. We can customiize the standard pages but why do we use visual force page in salesforce.

Thanks in advance,

regards,
naga
Hi All,

I am getting view state error in production environment. it is working in UAT environment. PLease help me to resolve this issue.

"Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 214.36KB"

VF page :
<apex:page sidebar="false" docType="html-5.0" controller="BulkUpload" showHeader="false" >
      
   <apex:form id="form" >

     <apex:sectionHeader title="Upload Carbon Data From CSV File"/>
     
      <apex:pagemessages />
      <apex:pageBlock >
             <!--  Component to allow user to upload file from local machine -->
             
             <center>
             <font color="Blue"> <b>Note: Please <a href="https://drive.google.com/open?id=1BbECRGfkO1oQ5dOTyt0hbmlc9beMnfql5zpZZs" target="_blank"> Click here </a> to follow the instructions for bulkupload csv file. </b> </font> <br/>
             <font color="Blue"> <b>Note: Please use the standard template to upload nova cases. <a href="https://drive.google.com/open?id=0B22fW7Nh4N5BQNTZXM" target="_blank"> Click here </a> to download the template. </b> </font> <br/>
             <font color="Blue"> <b>Note: Please use the standard template to para cases. <a href="https://drive.google.com/open?id=0B22fWk1wS1Jsbms" target="_blank"> Click here </a> to download the template. </b> </font>
             <br/><br/>
             
              <apex:inputFile value="{!contentFile}" filename="{!nameFile}" />
              <font color="Blue"> 
              <apex:commandButton action="{!ReadFile}" value="Upload File" id="theButton" style="width:70px;background:green;font-weight:bold" /></font>
              
             <!-- <br/> <br/> <font color="Blue"> <b>Note: Please use the standard template to upload cases. <a href="https://drive.google.com/file/d/0B5FQvDdE4z0PdFllT1g0aGNBN1k/view?usp=sharing" target="_blank"> Click here </a> to download the template. </b> </font>-->
             </center> 
             
             <br/>
             <div align="center" draggable="false" > 
      <apex:commandButton action="{!cancelPage}" value="Return to HomePage" styleClass="buttonStyle" style="background:green;font-weight:bold"/></div>
                            
          
      </apex:pageBlock>       
   </apex:form>   
</apex:page>

Controller :
public class GAD_CarbonBulkUpload
{
    transient public string nameFile{get;set;}
   transient public Blob contentFile{get;set;}
   transient String[] filelines = new String[]{};
    List<Case> casestoupload;
   // List<String> casestoupload= new List<String>();
    CarbonUtility carbon = new CarbonUtility ();
   transient public static Id carbonRecordtypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Carbon').getRecordTypeId(); 
    public static Map<String, Carbon_Bulk_Vendor__c> Queuemap= Carbon_Bulk_Vendor__c.getAll();
    /***This function reads the CSV file and inserts records into the case object. ***/
    public Pagereference ReadFile()
    {
        try{
                //Convert the uploaded file which is in BLOB format into a string
                nameFile =blobToString( contentFile,'ISO-8859-1');
                
                //Now sepatate every row of the excel file
                filelines = nameFile.split('\n');
                
                //Iterate through every line and create a Account record for each row
                casestoupload = new List<Case>();
                for (Integer i=1;i<filelines.size();i++)
                {
                   transient String[] inputvalues = new String[]{};
                    inputvalues = filelines[i].split(',');
                    
                    Case a= new Case(Status ='New', Origin = 'Web', recordtypeid = carbonRecordtypeId, isparent__c = true, Subject= 'Carbon Implementation', Business_Line__c = 'Carbon Implementation', GAD_Implementation_Type__c = 'Carbon Implementation', Effort_Hours__c=5 );
                    a.Customer_Id__c = inputvalues[0];
                    a.Features__c= inputvalues[2];       
                    a.Language__c = inputvalues[1];
                    a.GAD_Vendor_Name__c = inputvalues[3];
                    if(a.GAD_Vendor_Name__c!= 'BoostMedia' && a.GAD_Vendor_Name__c!='Welocalize' && a.GAD_Vendor_Name__c!='Cognizant'){
                    system.debug('enter into if loop'+ a.GAD_Vendor_Name__c);
                    carbon.setCaseAssignment(a);
                    }
                   
                    if(Queuemap !=null && Queuemap.containsKey(a.GAD_Vendor_Name__c)){
                       a.ownerid = Queuemap.get(a.GAD_Vendor_Name__c).Queue_id__c;
                    }
                    a.Name__c = inputvalues[4];
                    a.Email__c= inputvalues[5];
                    a.Team__c= inputvalues[6];
                    a.Manager__c= inputvalues[7];
                    a.Manager_Email__c= inputvalues[8];
                    a.Location__c= inputvalues[9];
                    a.LDAP__c= inputvalues[10];
                    a.Agency__c = inputvalues[11];
                    a.Name1__c= inputvalues[12];
                    a.AgeEmail__c= inputvalues[13];
                                       
                    casestoupload.add(a);
                    
                }
         }
         catch(Exception e){
                 ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured reading the CSV file'+e.getMessage());
                ApexPages.addMessage(errormsg);
         }  
         
        /* for(Case c1:casestoupload){
            casestoupload.addall(carbon.setCaseAssignment(c1));
            } */    
        //Finally, insert the collected records
        try{
            insert casestoupload;
            if(casestoupload.size()>0)
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.confirm,'Upload has been successful and cases has been created successfully'));
                        
        }
        catch (Exception e)
        {
            ApexPages.Message errormsg = new ApexPages.Message(ApexPages.severity.ERROR,'An error has occured inserting the records'+e.getMessage());
            ApexPages.addMessage(errormsg);
        }    
        return null;
    }
   
   /**** This function sends back to the visualforce page the list of account records that were inserted ****/ 
   /*public List<Case> getuploadedAccounts()
    {
        if (casestoupload!= NULL)
            if (casestoupload.size() > 0)
            
                return casestoupload;
            else
                return null;                    
        else
            return null;
    } */ 
        /**
         This function convers the input CSV file in BLOB format into a string
        @param input    Blob data representing correct string in @inCharset encoding
        @param inCharset    encoding of the Blob data (for example 'ISO 8859-1')
     */
    public static String blobToString(Blob input, String inCharset){
        String hex = EncodingUtil.convertToHex(input);
        System.assertEquals(0, hex.length() & 1);
        final Integer bytesCount = hex.length() >> 1;
        String[] bytes = new String[bytesCount];
        for(Integer i = 0; i < bytesCount; ++i)
            bytes[i] =  hex.mid(i << 1, 2);
        return EncodingUtil.urlDecode('%' + String.join(bytes, '%'), inCharset);
    }  
     public pagereference cancelPage(){
        Pagereference pageRef = new Pagereference('/apex/HomePage');
        return pageRef;
    }       
}
 
Hi all,

I'm facing the issue with SOQL query in the example which has given in the vfpage deveploer guide. Can anyone help me over here.Below is the controller class which i have used. And the error I'm facing is
SObject row was retrieved via SOQL without querying the requested field: Account.AnnualRevenue
public class DynamicCustomizableListHandler {

    // Resources we need to hold on to across requests
    private ApexPages.StandardSetController controller;
    private PageReference savePage;

    // This is the state for the list "app"
    private Set<String> unSelectedNames = new Set<String>();
    private Set<String> selectedNames = new Set<String>();
    private Set<String> inaccessibleNames = new Set<String>();

    public DynamicCustomizableListHandler(ApexPages.StandardSetController controller) {
        this.controller = controller;
        loadFieldsWithVisibility();
    }

    // Initial load of the fields lists
    private void loadFieldsWithVisibility() {
        Map<String, Schema.SobjectField> fields = 
            Schema.SobjectType.Account.fields.getMap();
        for (String s : fields.keySet()) {
            if (s != 'Name') {  // name is always displayed 
                unSelectedNames.add(s);
            }
            if (!fields.get(s).getDescribe().isAccessible()) {
                inaccessibleNames.add(s);
            }
        }
    }

    // The fields to show in the list
    // This is what we generate the dynamic references from
    public List<String> getDisplayFields() { 
        List<String> displayFields = new List<String>(selectedNames);
        displayFields.sort();
        return displayFields;
    }
    
    // Nav: go to customize screen
    public PageReference customize() {
        savePage = ApexPages.currentPage();
        return Page.CustomizeDynamicList;
    }

    // Nav: return to list view
    public PageReference show() {
        // This forces a re-query with the new fields list
        controller.reset();
        controller.addFields(getDisplayFields());
        return savePage; 
    }

    // Create the select options for the two select lists on the page
    public List<SelectOption> getSelectedOptions() { 
        return selectOptionsFromSet(selectedNames);
    }
    public List<SelectOption> getUnSelectedOptions() { 
        return selectOptionsFromSet(unSelectedNames);
    }
    
    private List<SelectOption> selectOptionsFromSet(Set<String> opts) {
        List<String> optionsList = new List<String>(opts);
        optionsList.sort();
        List<SelectOption> options = new List<SelectOption>();
        for (String s : optionsList) {
            options.add(new 
                SelectOption(s, decorateName(s), inaccessibleNames.contains(s)));
        }
        return options;
    }

    private String decorateName(String s) {
        return inaccessibleNames.contains(s) ? '*' + s : s;
    }

    // These properties receive the customization form postback data
    // Each time the [<<] or [>>] button is clicked, these get the contents
    // of the respective selection lists from the form
    public transient List<String> selected   { get; set; }
    public transient List<String> unselected { get; set; }

    // Handle the actual button clicks. Page gets updated via a
    // rerender on the form
    public void doAdd() {
        moveFields(selected, selectedNames, unSelectedNames);
    }
    public void doRemove() {
        moveFields(unselected, unSelectedNames, selectedNames);
    }
    
    private void moveFields(List<String> items, 
            Set<String> moveTo, Set<String> removeFrom) {
        for (String s: items) {
            if( ! inaccessibleNames.contains(s)) {
                moveTo.add(s);
                removeFrom.remove(s);
            }
        }
    }
}


Thanks in advance.
Regards,
naga.
 
Hi everyone,

Can anyone help me to write a trigger to create an Contact when an Account is created and send an email notification to the contact. In Account object I have created a custom field for email ID and create a contact.

Thanks in advance.

Regards,
naga.