• Madhukar_Heptarc
  • NEWBIE
  • 83 Points
  • Member since 2018
  • Heptarc Solution Private Limited

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 0
    Questions
  • 39
    Replies
Hi, 

   In custom object Popup_Message__c there is a  custom field  Profile__c which stores comma seprated values now I need a extract a particular value using a soql 

example : In Profile__c is the value is stored as A,B,C

  I want to extract a find if Profile__c = C exit or not. Please suggest me how to extract. 

select Profile__c from Popup_Message__c where Profile__c = 'C' this is not returning 


Thanks 
SUD
  • May 02, 2019
  • Like
  • 0
How to insert value in Salutation, FirstName, Lastname, Account(LookUp) in contact object using Apex, help me with code
Hi All,

I am trying to create a new contact. Once the record is saved in Salesforce, an email need to be sent along with the unique id.

I have created a formula field for the Unique ID and associated record ID to this field.

Now, when I try to send an email with Unique ID, it shows null value.

<apex:page controller="SubmitNewContactController" docType="html-5.0">
   
    <apex:form>
        <apex:slds/>
    <apex:pageMessages></apex:pageMessages>
        <div class="slds-scope slds-box">
         <apex:outputPanel >
            <div class="slds-text-align_center slds-text-heading_medium"><p>Submit New Contact </p></div>
             <div class="slds-form-element">
                    <label class="slds-form-element__label"><abbr class="slds-required"></abbr> FirstName</label>
                <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!FirstName}" styleClass="slds-input" id="FirstName" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> LastName</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!LastName}" styleClass="slds-input" id="LastName" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> Phone</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!Phone}" styleClass="slds-input" id="Phone" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> Email</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!Email}" styleClass="slds-input" id="Email" />
                </div>
                 <label class="slds-form-element__label"><abbr class="slds-required"></abbr> Zipcode</label>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:input value="{!Zipcode}" styleClass="slds-input" id="Zipcode" />
                </div>
                 <div class=" slds-scope slds-form-element__control">
                    <apex:commandButton action="{!SubmitContact}" value="Submit"/> 
                </div>
            </div>
         </apex:outputPanel>   
        </div>
        
    
    </apex:form>
</apex:page>
public class SubmitNewContactController {
    public Contact c{get;set;}
    public String FirstName{get;set;}
    public String LastName{get;set;}
    public String phone{get;set;}
    public String Email{get;set;}
    public String Zipcode{get;set;}
    
    public SubmitNewContactController(){
        c = new Contact();
    }
    
    public PageReference SubmitContact(){
        c.FirstName = FirstName;
        c.LastName = LastName;
        c.phone = phone;
        c.Email = Email;
        c.MailingPostalCode = Zipcode;
        insert c;
        
        PageReference pr = new PageReference('/apex/ThankYouPage');
        Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
        String[] sendingTo = new String[]{c.Email};
        semail.setToAddresses(sendingTo);
        semail.setSubject('Registration is completed');
        semail.setPlainTextBody('Hi'+ c.name+'Thank you for registering.This is your UniqueID'+ c.Unique_ID__c);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
        pr.setRedirect(true);
        return pr;
        
        
        
    }
    

}

I am able to send the email but cannot capture the name and uniqueId in the email. It shows null in the email.
Can anyone please help me to fix the code?

Thanks,
Sirisha
 
Controller
public Class LogAcallController{
  private ApexPages.StandardController con;
    public class DataException extends Exception {} 
    public  Boolean isError = FALSE;
    public String whatId = ApexPages.CurrentPage().getParameters().get('what_Id');
    public String leadId = ApexPages.CurrentPage().getParameters().get('lead_id');
    public string WhoID=ApexPages.CurrentPage().getParameters().get('who_id');
    public Lead LeadData;
    public String retURL = ApexPages.CurrentPage().getParameters().get('id');
    public String parentId;
    public Task logACall {get;set;}
    public list<Task> TaskList{get;set;}
    public Task followUpTask {get;set;}
    
    public Boolean createFollowUpTask {get;set;}
    
    public LogAcallController(){
        
         String queryString = GeneralUtilityClass.getQueryString('Lead');
         queryString += ' From Lead WHERE Id =: leadId ';         
         LeadData= dataBase.query(queryString);
         
         
      if(WhoId !=null){
       parentId = LeadData.Id;
   
       }
       else{
        parentId = WhatID;
       }
       
       TaskList =new List<Task>();
  
        logACall = new Task();    
        logACall.WhoID=LeadData.id;
        logACALL.lEAD__C=LeadData.Id;
         logACall.Subject = 'Transferred';
         logACall.Task_Type__c = 'Inbound';  
        followUpTask = new Task(); 
        followUpTask.WhoID=LeadData.id;    
        createFollowUpTask = FALSE;

     
        
           Map<String, String> taskRecordTypeMap = new Map<String, String>();
            for(Schema.RecordTypeInfo r :Task.SObjectType.getDescribe().getRecordTypeInfos()){
            taskRecordTypeMap.put(r.getName(), r.getRecordTypeId());
            }
        
           Task  logACall = new Task();  
                logACall.whatId =whatId;                  
                logACall.RecordTypeId = taskRecordTypeMap.get('Call');
                logACall.WhoId = WhoId;
               }
               
        
    
    public PageReference save(){
    try{
    isError=false;
    
    validateData();
            if(isError == TRUE ){
          
               throw new DataException(ErrorMessages.REVIEW_ERROR_MESSAGE);
            } 
            }
             
        catch(exception e){
          
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
            return null;
        }
        
       try{
          Savepoint sp = Database.setSavepoint();   
                
          database.insert(logACall);  // insert logACall ;
         
          
        PageReference pr = new pageReference('/'+leadId);
        pr.setRedirect(true);        
       return pr;
  
        }
        catch(exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage()));
            return null;
        }
       
              
       
    }
    
    
    public PageReference cancel(){
       // PageReference pr = new pageReference(retURL);
        PageReference  pr = new pageReference ('/apex/LeadEditOverridePage?retURL=/'+leadId+'&id='+leadId);
     //  PageReference pr = new pageReference(retURL);
        pr.setRedirect(true);
        return pr;
    }
    
    
    public Boolean validateData() {
        isError =False;
        
           if(logACall.Attended_By__c==null) {
                logACall.Attended_By__c.addError('Please Enter Attended By Fields');
                isError = TRUE;
            }
             if(logACall.Call_Status__c!='Transferred') {
                logACall.Call_Status__c.addError('Please Enter Call Status as Transferred');
                isError = TRUE;
            }
             if(logACall.Call_Status__c=='Transferred' && (logACall.Transferred_To__c==null || logACall.Transferred_To__c=='' )) {
                logACall.Transferred_To__c.addError('Please Enter a value');
                isError = TRUE;
            }
        
              
        return isError;
    }
    
}

TEST CLASSS

@isTest(seeAllData=false)
private class LogAcallController_TestClass


 
    private static Lead newLead;
    private static Campaign newCampaign;
    private static Task newTask;
    private static Task newLogACall;
    private static Task newAnotherTask;
    private static User newUser;
    
      private static void init() {    
        
       newUser = InitializeTestData.createUser('cgpet00D900000010QJQ.test@demmo.com.test');
       database.insert(newUser);
        
       newCampaign = InitializeTestData.createCampaign();
       database.insert(newCampaign);
       
       newLead = InitializeTestData.createLeadWebsite(newCampaign.Id);
       newLead.DecisionMaker__c='Self';
       newLead.IsConverted = FALSE;
       database.insert(newLead);
       
        
       
       newLogACall=InitializeTestData.createLeadLogACall(newLead.Id,newUser.Id);
       database.insert(newLogACall); 
       
       System.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+newLead.Id);
          
        }

  private static TestMethod void Test1() {
   
      
         init();
        
         Test.StartTest();
       
      
            PageReference pageRef = Page.LogACallPageNew; // Add your VF page Name here
            pageRef.getParameters().put('who_id', String.valueOf(newLead.Id));
            pageRef.getParameters().put('lead_id', String.valueOf(newLead.Id));
            pageRef.getParameters().put('what_Id','');            
            Test.setCurrentPage(pageRef);

           
          //  PageReference testPage = testAccPlan.save();
             
            LogAcallController taskinfo= new LogAcallController();
            taskInfo.parentId = newLead.Id;
            taskInfo.logACall = newLogACall;
            taskInfo.createFollowUpTask = TRUE;
            taskinfo.save();
            taskinfo.cancel();
            
           // testAccPlan.save();    
        //  testAccPlan.cancel();
           
         
         
    
         
           
       Test.StopTest();
       }
   }
Hi All,

Visual Force Code:
<apex:input type="date" value="{!date}" styleclass="myStyle"/>

Apex Class Code:
public String date{get;set;}

public string getdate() {
            return date;
        }
    
 public void setdate(string date) {
            this.date= date;
        }

NOTE: I have tried using Date datatype as well instead of string, still unable to get the selected value of date from VF page in Apex Class.

Kindly, help.
Thank!
Aman
Hi all, Help me please. 
I want display a field value of a Rich text area in a Visualforce as it is formated in the layout. The must important for me is to go on the next line like in the first screenshot. 
Here is my portion of code

<p style="border: 0.08px solid black;"> {!Container__c.General_Comments__c}</p>
User-added image
public class BBH_Survey {
    public  String   Survey_res {get;set;}
	
	 Public BBH_Survey()
    {
        CasId='50023000001pb1w';
    }
	Public  static void survey_1(){
    
     List<case> lstCase=[select id,status ,Survey_fill__c from case where id =:CasId];
       
              BBH_Surveys__c bbh=new BBH_Surveys__c();
               bbh.CaseId__c=lstCase[0].id;
               bbh.Survey_Response__c= '1';
               insert bbh;
           
        
    }
	}
	
	
	<apex:page controller="BBH_Survey" sidebar="false" >
<apex:form >
<script>
    function bbh_survey_1()
    {
    survey_1();
    }


</script> 
 <apex:actionFunction name="survey_1" action="{!survey_1}"/>  
    <apex:commandButton value="1" onclick="bbh_survey_1();" styleClass="btn1" />
	</apex:form>
	<apex:page>

Hello All,

My Action function is not working please help me.

Regards
Sebastian 
Hi, 

  I want to extract owner name from below query. 
SELECT  Ownerid,Ownerid.name,
                Userid,User.name,
                opportunityaccesslevel,teammemberrole FROM UserTeamMember
I am getting below error message. not able to get the relation name please suggest me how to extract name in soql query

User-added image

Thanks
  • May 13, 2019
  • Like
  • 0
Hi All,

Our system meet a strange error recently when using the code to generate the pdf and attach it to the event. We have a trigger in event object to call a future method in the APEX. It works well for most of the time but sometimes we will receive the error email generated by the class and the pdf was not attached successfully. Could anyone please kindly help us for this issue?

APEX Code:

/**********************************************************************************
 * Created Date - 04-Aug-2016
 * Purpose - Acts as a helper to the trigger CMS_Event_PDF_Gen. 
 ********************************************************************************/
public class CMS_Event_PDF_Gen_Helper
{
    public static boolean recursiveCheck = true;
    /**
     * Method Name: public static void addPDFAttach(String sessionId, list<id> eventIds)
     * Purpose: to render the vf page CMS_MedicalEvents in pdf format and upload it under the Notes and Attachments section
     * The method is called asynchronously to allow for running the vf page.
     * */
    @Future(callout=true)
    public static void addPDFAttach(String sessionId, list<id> eventIds)
    {
        //CMS_AddPdfToAttachment.addPDF(eventIdSet);
        //Instantiate a list of attachment object
         list<attachment> insertAttachment = new list<attachment>();
         Map<id,Medical_Event_vod__c> mapIdtoEvent = new Map<Id,Medical_Event_vod__c>();
         for(Medical_Event_vod__c event : [select id,name,CMS_Status__c from Medical_Event_vod__c where id IN :eventIds])
         {
             mapIdtoEvent.put(event.id,event);
         }
         for(Id eventId: eventIds)
         {
              PageReference pdf;
              pdf = Page.CMS_MedicalEvents;
              pdf.getParameters().put('id',eventId);
              
              if(pdf!=null)
              {
                  Blob body;
                  Attachment attach = new Attachment();
                  try
                  {
                      body = pdf.getContentASPDF();
                      attach.Body = body;
                      attach.contentType='application/pdf';
                    // add the Event name as an attachment name
                    if(mapIdtoEvent.get(eventId).CMS_Status__c.equals('Review Completed') || mapIdtoEvent.get(eventId).CMS_Status__c.equals('Planned'))
                    {
                    system.debug('EventId for Plannedevent'+eventId);
                    system.debug('EventName'+mapIdtoEvent.get(eventId).name);
                      attach.Name = mapIdtoEvent.get(eventId).name+'_'+'Planned_Report.pdf';
                      }
                    else if(mapIdtoEvent.get(eventId).CMS_Status__c.equals('Approved'))
                      attach.Name = mapIdtoEvent.get(eventId).name+'_'+'Actual_Report.pdf';
                      attach.IsPrivate = false;
                    // attach the pdf to the event
                      attach.ParentId = eventId;
                  }
                  catch(VisualforceException e)
                  {
                      //body = Blob.valueOf('Exception');
                      System.debug('Exception caught while creating an attachment' + e.getMessage());

                      //PG-3925: Event planned pdf report or actual pdf report is missing in special scenarios.
                      //Added email notification when exception occurs.
                      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                      String[] toAddresses = new String[]{'testemail@163.com'};
                      mail.setToAddresses(toAddresses);
                      mail.setSubject('CMS_Event_PDF_Gen_Helper class threw a VisualforceException');
                      mail.setPlainTextBody('CMS_Event_PDF_Gen_Helper class threw a VisualforceException: ' + e.getMessage() 
                            +' at line number ' + e.getLineNumber() + ' caused by ' + e.getCause());
                      Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
                  } 
                  
                  insertAttachment.add(attach);
              }      
        }

        if(insertAttachment != null && insertAttachment.size() > 0)
        {
            try
            {
               Database.SaveResult[] savResult = Database.insert(insertAttachment); 
                for(Database.SaveResult sr:savResult){
                    system.debug('Errors-------->'+sr.getErrors());
                }
            }
            catch(DMLException e)
            {
                //PG-3925: Event planned pdf report or actual pdf report is missing in special scenarios.
                //Added email notification when exception occurs.
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresses = new String[]{'testemail@163.com'};
                mail.setToAddresses(toAddresses);
                system.debug('EventName is genrated if not dml exception'+e.getStackTraceString());
                mail.setSubject('CMS_Event_PDF_Gen_Helper class threw a DMLException');
                mail.setPlainTextBody('CMS_Event_PDF_Gen_Helper class threw a DMLException: ' + e.getMessage() 
                    +' at line number ' + e.getLineNumber() + ' caused by ' + e.getCause() + ' Stacktrace check -->' +e.getStackTraceString() 
                                     );
                Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
            }
        }
    }
}

Error Email:

CMS_Event_PDF_Gen_Helper class threw a DMLException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, ??? ??? ????: [Name]: [Name] at line number 73 caused by nullStackTraceClass.CMS_Event_PDF_Gen_Helper.addPDFAttach: line 73, column 1

Thanks a lot for your help.

David

if(suporg.Email3__c!=null){
      
       ccAddresses.add(suporg.Email3__c);
      
      mail.setccAddresses(ccAddresses);
     }
Hi, 

   In custom object Popup_Message__c there is a  custom field  Profile__c which stores comma seprated values now I need a extract a particular value using a soql 

example : In Profile__c is the value is stored as A,B,C

  I want to extract a find if Profile__c = C exit or not. Please suggest me how to extract. 

select Profile__c from Popup_Message__c where Profile__c = 'C' this is not returning 


Thanks 
SUD
  • May 02, 2019
  • Like
  • 0
I have a little challenge here please try:


I have a little challenge which I'm trying, I want whenever the checkbox is checked I want to copy the values into input text fields in visualforce page.
So here I have multiple rows and corresponding to that I have checkboxes, Whenever I click a checkbox values should pass to input text fields.
For more understanding, I'm attaching the screenshot of challenge.

User-added image

Please have look at the below link for the  more details :

https://salesforce.stackexchange.com/questions/260395/how-to-copy-when-data-to-text-fields-when-checkbox-is-checked
How do i call my interface from apex static methods.

I have a interface with below code:
global interface xyz{
    String a();
    String b();
}

Hi want to call a() and b() in another apex class .
public static void createUpdateActivity(List<Communicato_History__c> lstComHistory){
        List<id> activityids = new List<Id>();
        
        if(activityids.size() > 0 && activityids.size() == 1 ){
            // xyz.a();
         
        }

How to do it? It throws error saying non-static methods cannot be referred from static context.
 
  • April 25, 2019
  • Like
  • 0
Hi,

I have below apex class which i am not able to cover in test class.
public class createdoc
{  
public PageReference CreateDocument()
    {
                   product pr = [select id, Limited_Company_App_Form__c from product where id=:opp.product__c];
            docsetting sett = new docsetting (pr.Limited_Company_App_Form__c );                         
            string body= sett.Calldoc(opportunityId);   
              
            if(sett.AttachmentId != null)
            {
                Opp.Attachment_App_Form__c = sett.AttachmentId;
                update opp;
                           } 
               
        
        return null;
    
 }       
    }

 
How to insert value in Salutation, FirstName, Lastname, Account(LookUp) in contact object using Apex, help me with code
Hi everypone,

Please help me on fixing this error in my test class

@isTest
private class ItemizedReceiptTest {
    static testMethod void testMethodPostive(){
        Product2 prod = new Product2(
            Name = 'Test',
            IsActive = true
        );
       
        insert prod;
       
        Account acc = new Account(Name ='Test');
        insert acc;
       
       
        //Create your product
        Opportunity testOpp = new Opportunity();
        testOpp.Name='Test Opportunity' ;
        testOpp.AccountId=acc.id;
        testOpp.StageName='Order Placed';
        testOpp.CloseDate= Date.newInstance(2019,03,28);
        insert testOpp;
       
        Id pricebookId = Test.getStandardPricebookId();
       
       
        //Create your pricebook entry
        PricebookEntry pbEntry = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = prod.Id,
            UnitPrice = 100.00,
            IsActive = true
           
        );
        insert pbEntry;
        //create your opportunity line item.  This assumes you already have an opportunity created, called opp
        OpportunityLineItem oli = new OpportunityLineItem(
            OpportunityId = testOpp.Id,
            Quantity = 5,
            PricebookEntryId = pbEntry.Id,
            TotalPrice = pbEntry.UnitPrice
        );
        insert oli;

        PageReference pageRef = Page.ItemizedReceipt;
        Test.setCurrentPage(pageRef);
        system.debug('Products'+prod);
           system.debug('acc'+acc);
         system.debug('testOpp'+testOpp);
         system.debug('pbEntry'+pbEntry);
         system.debug('oli'+oli);
        ApexPages.StandardController sc = new ApexPages.StandardController(testOpp);
        ItemizedReceipt obj = new ItemizedReceipt(sc);
        obj.total();

 }
   
   
}


class:


public with sharing class ItemizedReceipt {
    public List<OpportunityLineItem> oppLst          { set; get; } //List of Products in a Opportunity
    public Double                    totalPrice_cal  { set; get; } //Variable to calculate Total Price of all the products
    public Double                    totalGST_cal    { set; get; } //Variable to calculate GST of all the products
    public Double                    totalPST_cal    { set; get; } //Variable to calculate PST of all the products
    public Double                    totalAmt_cal    { set; get; } //Variable to calculate Total Amount of all the products
    public DateTime                  getCloseDate    { set; get; } //Variable to get the Created Date
    public String                    dayOfWeek       { set; get; } //Variable to store the Day from the Created Date
    public String                    accName         { set; get; } //Variable to store the Customer Name
    public  ItemizedReceipt(ApexPages.StandardController controller) {
        if ( controller.getId() != null ) {
            oppLst = [SELECT Product2.Name, Opportunity.Id, Opportunity.CloseDate, TotalPrice, GST__c, PST__c,
                             Total_w_Tax__c, Opportunity.Account.Name
                      FROM   OpportunityLineItem
                      WHERE  Opportunity.Id=:controller.getId()
                     ];
            getCloseDate = oppLst[0].Opportunity.CloseDate;
            dayOfWeek = getCloseDate.format('EEEE');
            accName = (string)oppLst[0].Opportunity.Account.Name;
            totalPrice_cal = 0.0;
            totalGST_cal = 0.0;
            totalPST_cal = 0.0;
            totalAmt_cal = 0.0;
            total();
        }
    }  
    //Method calculates all the totals
    public  void total() {
        for ( integer i = 0; i < oppLst.size(); i++ ) {
            totalPrice_cal += oppLst[i].TotalPrice;
            totalGST_cal   += oppLst[i].GST__c;
            totalPST_cal   += oppLst[i].PST__c;
            totalAmt_cal   += oppLst[i].Total_w_Tax__c;
        }
    }
}

Thank You
Hi!

I am currently trying to add in a table to our Account View. I have been playing around with visualforce but am not getting the result I am looking for. 

Here's an example of the table:
Table

Ideally, each of the blank fields would be a text field. 

Thanks in advance!
I have looked everywhere and I can't find a good answer. I have some custom objects with standard lookup fields on them. The users are wanting those lookup fields to be able to select multiple records in the object they are looking up to. I know the functionality is there, because you can do this on the user lookup object, but not in the custom objects. 

Can someone PLEASE tell me how I can create a lookup field that will allow the user to select multiple records from the object that lookup field is looking up to?