• Balayesu Chilakalapudi
  • SMARTIE
  • 643 Points
  • Member since 2017
  • Software Developer

  • Chatter
    Feed
  • 19
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 4
    Questions
  • 174
    Replies
How to Write Test Class for Scheduled Apex Class? I manage to write Schedule class but I need help to write test class for this. I am learning Apex code. I would be grateful if someone can help me out. 

public class DeactivateInactiveUsers implements Schedulable {
    public void execute(SchedulableContext context) {
        User[] selectedUsers = [SELECT Id FROM User WHERE IsActive = TRUE AND Id NOT IN (SELECT UserId FROM LoginHistory WHERE LoginTime = LAST_N_DAYS:30)];
        for(User record: selectedUsers) {
            record.IsActive = false;
        }
        Database.update(selectedUsers, false);
    }
}
Hi Friends,

I am Trying to cover a test class for below Trigger , It's covered with 60%. Can anyone please help to cover upto 100%

@Trigger
/*
        Description: Update Preferred Price & Least Price in Indent Object
        Owner: Thabi
        Date: 17-Sep-13
        Test Class: TestOI_Indent_Creation
*/
trigger OI_UpdateIndentPrice on RawMaterial__c (after update) {
    map<id, RawMaterial__c> mapRm = new map<id,RawMaterial__c>(); 
    list<Indent__c> lstupdateindent = new list<Indent__c>();

    for(RawMaterial__c irow: trigger.new){
        if( irow.Preferred_Vendor__c != null || irow.Least_Vendor__c != null){
            mapRm.put(irow.id,irow);
        }
    }

    List<Indent__c> lstIndent = [select id, Raw_Material__c, PV_Rm_Cost__c from Indent__c
                                  where Raw_Material__c IN:mapRm.keyset() AND Product__c != NULL];
    
    if(lstIndent.size()>0){
        for(Indent__c krow : lstIndent){
            //Below Lines are not covered
            if(mapRm.containskey(krow.Raw_Material__c)){
                krow.PV_Rm_Cost__c = mapRm.get(krow.Raw_Material__c).Preferred_Price__c;
                krow.LV_Rm_Cost__c = mapRm.get(krow.Raw_Material__c).Least_Price__c;  
                lstupdateindent.add(krow);      
            }  
        
        }
        
        update lstupdateindent;
    }

}


@Test Class - I covered almost 60%
 
@IsTest
Public Class OI_RollupMaterialCost_Test{

static testMethod void RollupMaterialCostTest(){

Product2 prod = New Product2();
prod.Name = 'Test Product';
prod.HSN_Code__c = 'Prod123';
prod.Total_Material_Cost__c = 50;
prod.Total_RM_Cost__c = 100;
insert prod;

Vendor__c vr = New Vendor__c();
vr.Name = 'Test Name';
insert vr;

Vendor__c vr1 = New Vendor__c();
vr.Name = 'Test Name1';
insert vr1;

RawMaterial__c rm = New RawMaterial__c();
rm.Name = 'Test_rawMaterials';
rm.Unit__c = 'Bag';
rm.Preferred_Vendor__c = vr.Id;
rm.Preferred_Price__c =10;
rm.Least_Price__c = 20;
rm.Least_Vendor__c  = vr1.Id;
insert rm;

Indent__c ind = New Indent__c();
ind.Measurement__c = 12;
ind.PV_Rm_Cost__c =rm.Preferred_Price__c;
ind.LV_Rm_Cost__c = rm.Least_Price__c ;
ind.Product__c = prod.Id;
ind.Raw_Material__c = rm.Id;
ind.PV_Rm_Cost__c = 26;
ind.LV_Rm_Cost__c = 36;
Insert ind;

ind.Measurement__c = 14;
ind.PV_Rm_Cost__c =rm.Preferred_Price__c;
ind.LV_Rm_Cost__c = rm.Least_Price__c ;
ind.Product__c = prod.Id;
ind.Raw_Material__c = rm.Id;
Update ind;
}

}

Thanks in advance !!

Regards,
Soundar. 

 
Hi Evryone ,
   I have this pretty simple code given below. Now everything works well here. What i want to do is, rather than the record being displayed as a 1 row with 3 columns. I want it to be displayed as 1 column 3 rows. Can anyone please help me with this?

Current Display Format : Name, Narrative Technical, Narrative Staffing
Desired Display Format : Name 1
                                             Narrative Technical 1
                                             Narrative Staffing 1
                                         Name 2
                                             Narrative Technical 2
                                             Narrative Staffing 2

<apex:page standardController="Project_Form__c" recordSetVar="ProjectForms">
    <apex:sectionHeader title="Form History"/>
    <apex:form >
        <apex:pageBlock >
            <apex:pageMessages />

            <apex:pageBlockSection title="Selected Project Review Forms" columns="1">
                 <apex:pageBlockTable value="{!selected}" var="form" columns="3">
                    <apex:column value="{!form.name}"/>
                    <apex:column value="{!form.Narrative_Technical__c}"/><br></br>
                    <apex:column value="{!form.Narrative_Staffing__c}"/><br></br>
                  </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
I know this has been asked before and I tried my best to follow the previous suggestions.  But I cannot solve this after lots of experimentation.

I created a custom object called Intake Notes that is a child of Contacts.  At first I created a lookup filed based on the Contact Name.  Based on my research I changed that lookup field to a Master-Detail field

I created a VF page with the following code:

<apex:page standardController="Contact">
  <apex:relatedList list="IntakeNotes"/>
</apex:page>

I used the related list name that is displayed in the Master-Detail field:

Child Relationship Name      IntakeNotes

I have tried other related list names as well.

No matter what I do I see the following message in the Contact detail display:

Content cannot be displayed: 'IntakeNotes' is not a valid child relationship name for entity Contact
Can someone tell me why I am getting an unknown property accounts.SFDC_Account_Name__c when I pass this field as a parameter to the JS function

Save error: Unknown property 'DataIntegrityList.accounts'    
I am completely baffled as there are many examples in the forum and the web depicting this same pattern.

 
<apex:form >
		   <apex:pageBlock title="Account Data Integrity Issues List">
		      <apex:pageBlockTable value="{!accountProblemsList}" var="accounts" onRowClick="rowSelected('{!accounts.SFDC_Account_Name__c}')">
		      	
		         <apex:column value="{!accounts.PW_Account_Number_SFDC__c}"/>
		         <apex:column value="{!accounts.PW_Account_Number__c}"/>
		        
		         <apex:column value="{!accounts.SFDC_Account_Name__c}"/>
		         <apex:column value="{!accounts.SFDC_ID_PW__c}"/>        
		         <apex:column value="{!accounts.PW_Rep__c}"/>   
		         <apex:column value="{!accounts.SFDC_rep__c}"/>
		         <apex:column value="{!accounts.SFDC_repid__c}"/>
		         <apex:column value="{!accounts.PW_Acct_Status__c}"/>         
		      </apex:pageBlockTable>
		   </apex:pageBlock>
   	</apex:form>

 
Hi Guys,

I've developed a Visualforce page using jQuery for click functionality throughout my page. This is used on the Quote object and values need to change within the page without the page reloading using Ajax requests. 

I'm new to Apex and have been asked to develop the page using Apex. Will I be able to get all the functionality available using Javascript using Apex?

Thankyou in advance for any help.

Corey
I need to auto populate complete state value in a visualforce page if it fetches state codes like oh,FL with the help of apex?
I will preface this that I am fairly new at creating a controller so there several poor practices going on here.

The first Class (Contact) works fine.  and I am trying to use it to help me get the related membership to the identified contact.  I have tried several ways to get it done, but keep running into errors.  I feel I am close, but that is only good with hand grenades and horse shoes.

Here is part of my Controller:
 
public Contact getContact () {
        
        return[SELECT Id, name, email, MailingAddress, Phone, MailingCity, MailingState, MailingCountry, MailingPostalCode, MailingStreet 
               FROM Contact 
               WHERE Id IN (SELECT 	ContactId
                             From User
                             WHERE Id=:UserInfo.getUserId())
              LIMIT 1];

    }
  public Membership__c getMembership () {
        
        return[SELECT Id
               FROM Membership__c
               WHERE Contact_Associated__c = {!Contact.Id}
              LIMIT 1];
}

 
I used a standard list controller for account object . There are around 500 records in the db. But on the page i found only 20 records . i need to know why only 20 records is shown at the page, Also the code worked when i used custom controller. I shall attach the code i used below
<apex:page standardController="account" recordSetVar="acc" >
        <apex:panelGrid columns="5" id="theGrid">

    <apex:repeat value="{!acc}" var="a">
        {!a.id}    <br/>
        {!a.name}
      
    </apex:repeat>
    </apex:panelGrid>
</apex:page>


 
I am in need of some great support form one of you Awesome Salesforce Guru's!

I have a Apex Controller that I am using as an extension on a VF page to handle incoming attachments and populate a look up field when the record is created from the VF page.  

I can not get the test class to not fail for the following reason System.QueryException: List has no rows for assignment to SObject and the stack trace is - Class.backlogAttachment.getReleaseMethod1: line 20, column 1
Class.backlogAttachment.<init>: line 12, column 1
Class.backlogAttachmentTest.backlogAttachmentTestMethod: line 10, column 1


Here is my controller class and Test class...can you please help me figure out why thsi is failing and what to do to fix it?  You woudl be a hge saviour here as I am new to apex but am trying my hardest!  Thanks in advance...

Shawn


Controller Extension:
 
public with sharing class backlogAttachment {
    
    public blob getfile{get;set;}
    public attachment objAttachment{get;set;}
    public Backlog__c objcase{get;set;}
    public string filename{get;set;}
    
    public backlogAttachment(apexpages.standardcontroller controller) {
    
        objcase = new Backlog__c();
        objAttachment = new Attachment();
        Scheduled_Releases__c sr = getReleaseMethod1();
        objcase.Scheduled_Release__c = sr.Id;
       }
    
    Scheduled_Releases__c s;
    
    public Scheduled_Releases__c getReleaseMethod1(){
    
        if(s == null) s=[SELECT Id, Name FROM Scheduled_Releases__c WHERE Name ='Software Enhancement Request (Default)' LIMIT 1];
        return s;
    }
    Public PageReference saveBacklog() {
    try{
        insert objcase;
    } catch(DMLException e) {
        ApexPages.addMessages(e);
        }
    if(filename != null && fileName.trim().length()>0 && getfile != null) {
        //objAttachment = new Attachment();
        Integer i=0;
        objAttachment.clear();
        objAttachment.body = getfile;
        objAttachment.ParentId = objcase.Id;
        objAttachment.name = this.filename;
        try{
        insert objAttachment;
          }catch(Exception e){
              system.debug(e);
              }
        }
        
        pagereference pr = new pagereference('/'+objcase.id);
        return pr;
    }


}

Test Class that is failing:
 
@isTest
public class backlogAttachmentTest {
    
    
    
    static testMethod void backlogAttachmentTestMethod() {
        List<Scheduled_Releases__c> re = [SELECT Id FROM Scheduled_Releases__c WHERE Id = 'a3l4B000000CiGw' LIMIT 1];
        Backlog__c temprec = new Backlog__c();
        ApexPages.StandardController cs = new ApexPages.StandardController(temprec);
        backlogAttachment controller = new backlogAttachment(cs);
        controller.getfile = Blob.valueof('Test Data');
        controller.filename = 'TestFieName';
        controller.objcase.Scheduled_Release__c = re[0].Id;
        test.startTest();
        	controller.saveBacklog();
        test.StopTest();
        
        
    }
    
    
    
}


    
Hoping that one of you awesome Salesforce experts can help me with the following issue I am having. 

I have an force.com Site which has a VisualForce page which should open a custom object record on Salesforce.  I also have a need to have an attachment added to this VF page to then be attached to the new record being created upon the user pressing save.  

Here is what I am seeign so far, if I do not include the Controller extension, the record gets created just fine, but when I have the extension added to the VF page, no record is created. 

I am new to apex, so hoping that someone can look over my code below and provide a solution to my frustration :) 

Thank you

Shawn

VF Page Code - 
 
<apex:page standardcontroller="Backlog__c" extensions="backlogAttachment,PopulateSchedRelease"
showHeader="true">
<img src="{!$resource.AVISPL_Logo2}"></img><b/><b/>
    <apex:form >
    <apex:pageBlock >
<apex:pageBlockSection title="Software Enhancement Request" columns="1" showHeader="True" collapsible="False">
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageMessages />

        <apex:pageBlock >
        <apex:inputField value="{!objcase.Name}"/>
            <apex:pageBlockSection title="Request/Requestor Information">
                <apex:inputfield value="{!objcase.SER_Requestor__c}" required="True"/>
                <apex:inputfield value="{!objcase.Priority__c}" required="True"/>
                <apex:inputField value="{!objcase.SER_Requestor_email__c}" required="True"/>
                <apex:inputfield value="{!objcase.Stakeholder__c}" required="True"/>
                <apex:inputField value="{!objcase.Requestor_GL_Code__c}"/>
                <apex:inputfield value="{!objcase.Executive_Sponsor__c}"/>
                
                
            </apex:pageBlockSection>

            <apex:pageBlockSection title="Impact of Request">
                <apex:inputField value="{!objcase.SER_Category__c}" required="True"/>
                <apex:inputField value="{!objcase.SER_Sub_Category__c}"/>     
                <apex:inputField value="{!objcase.SER_Designation__c}" required="True"/>
                <apex:inputField value="{!objcase.Number_of_Users_Affected__c}" required="True"/>
                
                <br/>
              
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Request Description Information">
                <apex:inputField value="{!objcase.Summary__c}" required="True"/>
                <apex:inputField value="{!objcase.Reason__c}" required="True"/>     
                <apex:inputField value="{!objcase.Description__c}" required="True"/>
                <apex:inputField value="{!objcase.Benefit__c}" required="True"/>
                
                <br/>
              
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Deadlines and Project Status">
                <apex:inputField value="{!objcase.Training_Requirements__c}" required="True"/>
                <apex:inputField value="{!objcase.Target_Deadline__c}" required="True"/>
                <apex:inputField value="{!objcase.SOP_Requirements__c}" required="True"/>
                <apex:inputField value="{!objcase.List_All_U_A_T_Participants__c}" required="True"/>     
                <apex:inputField value="{!objcase.SER_Scheduled_Release__c}"/>
                <apex:inputField value="{!objcase.Scheduled_Release__c}" rendered="False"/>
                
                
                <br/>
              
            </apex:pageBlockSection>
            
         <apex:pageBlock title="Upload Attachment">
            <apex:inputFile style="width:100%" id="fileToUpload" value="{!objAttachment.Body}" filename="{!objAttachment.Name}" />
           
       </apex:pageBlock>

           <apex:commandButton value="Submit Request" action="{!saveBacklog}" />
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

First Extention to pass ID of another custom object record and populate a lookup field when record is created.
 
public class PopulateSchedRelease {

  public Backlog__c bl;

  public PopulateSchedRelease(ApexPages.StandardController controller) {
  
  this.bl = (Backlog__c)controller.getRecord();
  Scheduled_Releases__c sr = getReleaseMethod1();
  bl.Scheduled_Release__c = sr.Id;
        
   }

   Scheduled_Releases__c s;

   public Scheduled_Releases__c getReleaseMethod1() {
       if(s == null) s = [SELECT Id, Name FROM Scheduled_Releases__c WHERE Name = 'Software Enhancement Request (Default)' LIMIT 1];
       return s;
   }

}

And lastly, the second controller extension for handling the attachment.
 
public class backlogAttachment {
    
    public blob getfile{get;set;}
    public attachment objAttachment{get;set;}
    public Backlog__c objcase{get;set;}
    public string filename{get;set;}
    
    public backlogAttachment(apexpages.standardcontroller stdCon) {
    
        objcase = new Backlog__c();
        objAttachment = new Attachment();
        
       }
    
    Public PageReference saveBacklog() {
    
        insert objcase;
        objAttachment.body = getfile;
        objAttachment.ParentId = objcase.Id;
        objAttachment.name = filename;
        insert objAttachment;
        return ApexPages.currentPage();
    }


}

PLEASE HELP!!!!
I have long text area Text field 'comments__c', after entering data in comments__c text box and click on save, comment field should be read only I tried below code, but it is not working as expected. I need to display that page in SITE.please guide me.

Controller:
public class CampaignRecordIdController{
    public String campaignRecordId {get;set;}
    public String parameterValue {get;set;}
    public Campaign cam{get;set;}
    public boolean rend{get;set;}
    public boolean rend1{get;set;}
    public Campaign Campaign{get;set;}
    
    public CampaignRecordIdController() 
    {
       campaignRecordId =ApexPages.currentPage().getParameters().get('id');
       system.debug('=====campaignRecordId ===='+campaignRecordId);
       cam = [select name,Promotion_Details__c,parentid,Comments__C from Campaign member where id =: campaignRecordId ];
       rend=true;
       rend1=false;
      
        }
         public PageReference save() {
        update cam;
        rend=false;
        rend1=true;
        return null;
    }
}

Page:
<apex:page Controller="CampaignRecordIdController"  sidebar="false" showheader="false">
   <apex:form >
   <apex:pageBlock>
    
   <apex:pageBlockSection title="Current Campaign record Id is : {!campaignRecordId}" collapsible="false" columns="1" rendered="{!rend}">
   <apex:outputField value="{!cam.name}"/>
   <apex:outputField value="{!cam.Promotion_Details__c}"/>  
   <apex:outputField value="{!cam.Parentid}"/>  
   <apex:inputtext value="{!cam.Comments__c}" style="width: 360px; height: 40px"/>  
   </apex:pageBlockSection> 
   
    <apex:pageBlockSection title="Current Campaign record Id is : {!campaignRecordId}" collapsible="false" columns="1" rendered="{!rend1}">
   <apex:outputField value="{!cam.name}"/>
   <apex:outputField value="{!cam.Promotion_Details__c}"/>  
   <apex:outputField value="{!cam.Parentid}"/>  
   <apex:outputfield value="{!cam.Comments__c}" style="width: 360px; height: 40px"/>  
   </apex:pageBlockSection> 
   
     <apex:pageBlockButtons >
      <apex:commandButton action="{!save}" value="save"/>
     </apex:pageBlockButtons>
    </apex:pageBlock>
   </apex:form>
   </apex:page>

 
  • March 16, 2017
  • Like
  • 0
I tried to display campaign id in site using visulforce page, but i am not able to display.My code is not working fine. Can i use standard controller? if not please let me know. Whether i need to try different code for SITES. please guide me.

class:
public class CampaignRecordIdController{
public String campaignRecordId {get;set;}
public String parameterValue {get;set;}
public Campaign cam{get;set;}
  public CampaignRecordIdController(ApexPages.StandardController controller) {
        campaignRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        cam = [select name,Promotion_Details__c from Campaign where id =: campaignRecordId ];
        parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');      
}
}
Page:
public class CampaignRecordIdController{
public String campaignRecordId {get;set;}
public String parameterValue {get;set;}
public Campaign cam{get;set;}
   public CampaignRecordIdController(ApexPages.StandardController controller) {
       campaignRecordId  = ApexPages.CurrentPage().getparameters().get('id');
       cam = [select name,Promotion_Details__c from Campaign where id =: campaignRecordId ];
       parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
         }
}
  • March 14, 2017
  • Like
  • 0
Hi, I have an apex scheduled class and i want to deploy it to production, but it has a 0% code coverage, how can i write a test class for it? This is the code:
 
global class BorrarAsegurados implements Schedulable{
    global void execute(schedulablecontext SC){
        List<Enrollee__c> Asegurados = [select id from Enrollee__c where Policy_End_Date__c <= Yesterday ];
        if(!Asegurados.isEmpty())
            delete Asegurados;
    }

}

 
Can someone help me with this?  I have a trigger that a member made for me to checc the lead box Do Not Call  "true" if a task subject has words "Do Not Call"  Having problem writing the test class for the trigger for the check box in particular.  Does test class need to make a new lead?  I get Boolean errors etc.  I'm a bit new to the coding so could use some help.   Here is the trigger I need test class for.   And my beginnings of the test class.

trigger trgDoNotCall on Task (after update, after insert) {

 

    List<Id> lstLeadIds = new List<Id>();

    for (Task task : trigger.new){

        system.debug('task.WhoId : ' + task.WhoId);

        system.debug('task.Who.Type : ' + task.Who.Type);

        if(task.WhoId != null){

            String sSubject = task.subject;

            System.debug('sSubject ' +  sSubject);

            System.debug('sSubject.indexOf ' + sSubject.indexOf('Do Not Call'));

            if((sSubject.indexOf('Do Not Call') > -1) || (sSubject.indexOf('DoNotCall') > -1)){

                lstLeadIds .add(task.WhoId);

                system.debug('task.WhoId : ' + task.WhoId);

            }

        }

    }

     

    if(lstLeadIds.size() > 0){

        List<Lead> lstLeads = [SELECT Id, DoNotCall FROM Lead WHERE Id =: lstLeadIds];

        for( Lead lead : lstLeads){

            lead.DoNotCall = true;

            //lead.Description += 'Do Not Call';

            System.debug('lead : ' + lead);

        }
        update lstLeads;

    }
And the test class start

@IsTest
public class DoNotCallTest  {

    static testmethod void validateDoNotCall () { 
    
    
   Task t = new Task(); 
    t.Subject = 'Do Not Call'; 
    t.Priority = 'Normal';
    
    insert t;
Throwing error at line 12, when inserting (data loader) more than 100 records and Trigger works fine for less than 100 records
Please help, below is my trigger - 

trigger AccountTrigger on Account (before insert,before update){
    
    Set<String> groupIdSet = new Set<String>();
    for(Account acc : Trigger.New){
        groupIdSet.add(acc.Pro_Alpha_ID__c);
        system.debug('--Trigger size in for loop1-->'+Trigger.new.size());
        system.debug(groupIdSet);
    }
    
    Map<String,Account> parentAccMap = new Map<String,Account>();   
    List<Account> accList = new List<Account>();
    accList = [SELECT id,Pro_Alpha_ID__c FROM Account WHERE Pro_Alpha_ID__c IN: groupIdSet AND RecordtypeId =: Schema.SObjectType.Account.getRecordTypeInfosByName().get('EHG Group').getRecordTypeId()];
    for(Account acc : accList){
        parentAccMap.put(acc.Pro_Alpha_ID__c,acc);
        system.debug(parentAccMap);
    } 
    
    Map<String,List<Account>> accMap = new Map<String,List<Account>>(); 
    if(Trigger.isBefore){
        system.debug('--Trigger size in for loop3-->'+Trigger.new.size());
        
        for(Account acc : Trigger.New){
            if(acc.Pro_Alpha_ID__c != null && acc.ParentId == null && acc.RecordtypeId != Schema.SObjectType.Account.getRecordTypeInfosByName().get('EHG Group').getRecordTypeId()){
                if(parentAccMap.keySet().contains(acc.Pro_Alpha_ID__c)){
                    acc.ParentId = parentAccMap.get(acc.Pro_Alpha_ID__c).Id;
                } else {
                    if(accMap.keySet().contains(acc.Pro_Alpha_ID__c)){
                        accMap.get(acc.Pro_Alpha_ID__c).add(acc);
                    system.debug(accMap);

                    } else {
                        List<Account> accLst = new List<Account>();
                        accLst.add(acc);
                        system.debug(accLst);
                        accMap.put(acc.Pro_Alpha_ID__c,accLst); 
                        system.debug(accMap);
                    }
                 }
            }
         }
        List<Account> accountsToCreate = new List<Account>();
        
        for(String s : accMap.keySet()){
                                  
            Account accnt = new Account(RecordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('EHG Group').getRecordTypeId(),
                                        Pro_Alpha_ID__c = s,
                                        Name = accMap.get(s).get(0).Name,
                                        BillingStreet = accMap.get(s).get(0).BillingStreet,
                                        BillingCity = accMap.get(s).get(0).BillingCity,
                                        BillingState = accMap.get(s).get(0).BillingState,
                                        BillingCountry = accMap.get(s).get(0).BillingCountry,
                                        BillingPostalCode = accMap.get(s).get(0).BillingPostalCode
                                        );
                
                insert accnt;
                system.debug(accnt);
            
            for(Account acc : accMap.get(s)){
               system.debug(accMap.get(s)); 
               acc.ParentId = accnt.Id;
             }
            }
        }
}
Hi I am trying to Show COntacts Account Name on VIsualforce Page while Using Custom COntroller - 
 
Contact con = [Select id,Name,AccountId,Account.Name FROM  Contact WHERE ID =: usr.ContactId];

I am trying to Get Account.name on the head of a Page.

I am trying to use Apex:Repeat but nothing is getting displayed.
 
<apex:repeat value="{!con}" var="myCon" > <apex:outputField value="{!myCon.Account.Name}" /> </apex:repeat>

 
Im a newbie...what i need to do seems simple enough but i can't seem to get it to work.  hoping someone can help me correct my errors.  i have the following controller and test class to insert a new record into a custom object.  when i run tests and review my controller their is no blue or red marking showing me what is covered... also, code coverage percentage shows zero so im pretty sure the test is not happening.  HELP!

CONTROLLER:
public class KFGCreateTrainingReferralController {

    public Referrals__c referrals {get; set;}
   
   // blank constructor
    public KFGCreateTrainingReferralController() {
  referrals = new Referrals__c();
    }

  // save button is clicked
    public PageReference save() {
        try {
            upsert(referrals); // inserts the new record into the database
        } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new referral.'));
      return null;
        }
       
    // if successfully inserted new application, then displays the thank you page.
    return Page.TrainingReferralThankYou;
    }
}

TEST:

@isTest
public with sharing class KFGCreateTrainingReferralControllerTest {
    //==================== TEST METHOD(s) ======================================
    static testMethod void KFGCreateTrainingReferralControllerTest() {
 Referrals__c newReferrals = new Referrals__c();
 // Test insert Referrals__c
        newReferrals.Referral_Date__c = Date.Today();
        newReferrals.Referrer_First_Name__c = 'TestFirstName';
        newReferrals.Referrer_Last_Name__c = 'TestLastName';
        newReferrals.Email__c = 'testreferrer@test.com';
        newReferrals.State__c = 'ca';
  insert newReferrals;
    }
}
I need assistance building a formula for a Task creation PB.  The formula is for an action "Assign to ID". 

This is on a contact record, right now "Assign to ID" is set to "BDR_Owner_c.  However this is causing flow errors when a user creates a new contact and the BDR_Owner_c" field is blank.  Looking to replace it with a formula -
If BDR_Owner_c is blank assign to Owner of Contact.
Process Builder Actions for Task Creation
I am using 
<ui:inputDate aura:id="dateField" label="Birthday" value="2014-01-30" displayDatePicker="true"/>

I want to allow users to select only 1st of every month and want to disable all otherdays, how can i achieve it with lightning design system

Thanks,
Balayesu
I had a try-catch block like this in my class,
 
try {
	    	String shref = ApexPages.currentPage().getURL();
	    	System.debug('>>> HouseholdMemberController shref='+shref);
} catch (Exception e) {
			System.debug('>>> ERROR ='+e);
}

Please help me to cover catch block.
I want to update a field of Opportunity object with a time dependent workflow action. I have created a workflow rule and added a criteria. it is
CloseDate LESS THAN Today
I added time dependent action as field update and it will fire 1 hour after rule trigger date.
I activated the rule.When i check the time based workflow queue my workflow rule is not listing there. can any one please help me to resolve this issue. any help will be liked.

Thanks,
Balayesu
I am getting below error

System.DmlException: ConvertLead failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Validation error on Contact: This field is alpha only​

please help me to solve this error
 
Hi everyone. 
Can you provide any example how can I implement drag and drop columns in <table> without external lib. I want use only pure JS and Lightning Component.
Thank for reply.
Hello Developers,
Suppose I have a custom object 'XYZ'. This object has many fields lookup to contact and User Object.
I want to get list of  all fields which has lookup to Contact object.
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        
        query = 'select id,Name,enquiry_For__c,email,Contact__c,ownerId,CCEmail__c from Lead'+
                'where enquiry_For__c = \'MCA Email Campaign\' AND (X3rdDayOfIncorporation__c =: todayDate OR X5th_Day_of_Incorporation__c =: todayDate'+
                'OR X7th_Day_of_Incorporation__c =: todayDate OR X10th_Day_of_Incorporation__c =: todayDate OR X15th_Day_of_Incorporation__c =: todayDate'+
                'OR X20th_Day_of_Incorporation__c =: todayDate OR X30th_Day_of_Incorporation__c =: todayDate OR X35th_Day_of_Incorporation__c =: todayDate'+
                'OR X45th_Day_of_Incorporation__c =: todayDate OR X50th_Day_of_Incorporation__c =: todayDate OR X60th_Day_of_Incorporation__c =: todayDate'+
                'OR X75th_Day_of_Incorporation__c =: todayDate OR X85th_Day_of_Incorporation__c =: todayDate OR X100th_Day_of_Incorporation__c =: todayDate'+
                'OR X120th_Day_of_Incorporation__c =: todayDate OR X130th_Day_of_Incorporation__c =: todayDate OR X150th_Day_of_Incorporation__c =: todayDate'+
                'OR X180th_Day_of_Incorporation__c =: todayDate)';
                
                system.debug('--query--' +query);
                
                return Database.getQueryLocator(query);
    }
 
  • March 12, 2018
  • Like
  • 0
I want to Parse the below JSON and results should be displayed in VF Page as Accounts with related contacts.

JSON:
{"totalSize":1,"done":true,"records":[{"attributes":{"type":"Account","url":"/services/data/v39.0/sobjects/Account/00190000016V11FAAS"},"Id":"00190000016V11FAAS","Name":"birlasoft","Contacts":{"totalSize":6,"done":true,"records":[{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYh46AAD"},"Id":"0039000002MYh46AAD","Name":"Krishna K"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYgxfAAD"},"Id":"0039000002MYgxfAAD","Name":"Krishna K"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYgXrAAL"},"Id":"0039000002MYgXrAAL","Name":"Riaz Test"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYhF4AAL"},"Id":"0039000002MYhF4AAL","Name":"Deepika HR"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000002MYhHoAAL"},"Id":"0039000002MYhHoAAL","Name":"Romit Shilpe"},{"attributes":{"type":"Contact","url":"/services/data/v39.0/sobjects/Contact/0039000001AlZ2XAAV"},"Id":"0039000001AlZ2XAAV","Name":"Riazgood boy"}]}}]}

Thanks in Advance!
  • February 22, 2018
  • Like
  • 0
trigger CreateOrder on Order__c (before insert,After Insert) {
        Set<Id> OppId = new Set<Id>();
        Set<Id> OffId = new Set<Id>();
        Map<Id,Offer__c> MapOff = new Map<Id,Offer__c>();
        List<Product_Detail_for_Order__c> ordforProd = new List<Product_Detail_for_Order__c>();
        Map<Id,List<Product_Detail_for_Offer__c>> offforProd = new Map<Id,List<Product_Detail_for_Offer__c>>();
    
    if(Trigger.isbefore){
        for(Order__c ord : Trigger.new){
            if(!String.isBlank(ord.Opportunity__c))
            {
                OppId.add(ord.Opportunity__c);
            }
            else if(!String.isBlank(ord.Offer__c))
            {
                OffId.add(ord.Offer__c);
            }
        }
        if(!OppId.isEmpty())
        {
            for(Offer__c off : [Select Id,Name,Opportunity__c,Partner__c from Offer__c where Opportunity__c =:OppId ORDER BY CreatedDate ASC NULLS FIRST])
            {
                MapOff.put(off.Opportunity__c, off);
            }
        }
        if(!OffId.isEmpty())
        {
            for(Offer__c ofo : [Select Id,Name,Opportunity__c,Partner__c from Offer__c where Id =: OffId] ){
                MapOff.put(ofo.Id,ofo);
            }
        }
        for(Order__c order : Trigger.new)
        {
            if(!String.isBlank(order.Opportunity__c))
            {
                Offer__c ofs = MapOff.get(order.Opportunity__c);
                order.Partner_Name__c = ofs.Partner__c;
                order.Opportunity__c = ofs.Opportunity__c;
                order.Id = ofs.Id;
             
            }
            else if(!String.isBlank(order.Offer__c))
            {
                Offer__c ofs = MapOff.get(order.Offer__c);
                order.Partner_Name__c = ofs.Partner__c;
                order.Opportunity__c = ofs.Opportunity__c;
                
            }
        }
    }
    
    if(Trigger.isAfter)
    {
        for(Order__c order : Trigger.new)
        {
            if(!String.isBlank(order.Offer__c)){
                OffId.add(order.Offer__c);
            }
        }
        for(Product_Detail_for_Offer__c ensp  : [Select Id,Currency__c,Customer_Drawing_Number__c,Customer_Item_No_Drawing_No1__c,Model_No__c,Enquiry_Product_Backend__c,Product_Description__c,Offer__c,Offer_Type__c,Opportunity__c,Partner_Drawing_Number__c,Partner_Item_Material_Code__c,Partner_Item_No_Drawing_No__c,Parter_Model_Code__c,Product__c,Product_code_Description__c,Quantity__c,Rate_Contract__c,Regret__c,Total_Amount__c,Unit_Price__c from Product_Detail_for_Offer__c where Id =:OffId])
        {
            List<Product_Detail_for_Offer__c> eis = new List<Product_Detail_for_Offer__c>();
            if(offforProd.get(ensp.Offer__c) != null)
                eis = offforProd.get(ensp.Offer__c);
                eis.add(ensp);
                offforProd.put(ensp.Offer__c, eis);
            
        }
            for(Order__c ord : Trigger.new){
                
                List<Product_Detail_for_Offer__c> eis = new List<Product_Detail_for_Offer__c>();
                eis = offforProd.get(ord.Offer__c);
                System.debug('******eis*****'+eis);
                for(Product_Detail_for_Offer__c off : eis){
                    
                    Product_Detail_for_Order__c ordp = new Product_Detail_for_Order__c();
                    ordp.Opportunity__c = off.Opportunity__c;
                    ordp.Customer_Item_Material_Code__c = off.Customer_Item_No_Drawing_No1__c;
                    ordp.Customer_Drawing_Number__c = off.Customer_Drawing_Number__c;
                    ordp.Product__c = off.Product__c;
                    ordp.Quantity__c = off.Quantity__c;
                    ordp.Unit_Price__c = off.Unit_Price__c;
                    ordp.Order__c = ord.Id;
                    
                    ordforProd.add(ordp);
                }
            }
            System.debug('******ordforProd******'+ordforProd);
            Insert ordforProd;
        }
    }
I have a requirement Account having opportinities and contacts my question is in Account object it has to print opportunities count and contact count by using the custom field and respective names of opportunites and contacts will also printed in  Account.whenever delete the contact or opportunity it will be automatically updated count & name Automatically give me any body propercode for these....
Hi,All.
   I created a new object type(such as objectA)  that had one field(such as account__c) to refer to some account.When I called API to change one objectA to refer to another account,there was a error:"Cannot specify both an external ID reference Account__r and a salesforce id, Account__c".
   code like that(C#):
         //the old value of objectA.Account__C is accountA,now set it accountB
         objectA.Account__c = accountB.Id;
  
   What is my problem?How to solve it?
   Thanks.


Hi Expert,

I am using a test class for coverage 75% code, but few things are not covered. Can any one suggest what is going wrong.

this my test Class: --
@isTest
public class TestProfessorSelectCourse {
    @isTest static void ProfessorCourse(){
       
        
        Professor__c prof = new Professor__c(Name ='JP',Email__c='jp@gmail.com');
        insert prof;
        
        Class__c cls = new Class__c(name='12G', Class_Teacher__c = prof.id);
        insert cls;
        
        Course__c cors = new Course__c(Professor__c=prof.id,Class__c =cls.id, name='Ruby', Start_Date__c= Date.today() , End_date__c= Date.newInstance(2017,03,20));
       	//Professor__c prof = new Professor__c(Name ='JP');
        //cors.Professor__c = prof.Name;
        insert cors;
    }
}

and below is my main class


User-added image

Thanks 
Mukesh

HI,

 

To give permissions (create,edit,delete,view)on a particular object we use profiles.

But in sharing settings sections we can find the feature called organization wide default. Here we can give the public readonly, public read/write ..... permissions. 

 

what is the difference between these profile based and organization wide default permissions?

I observed that, profile will overides org wide default permissions. is it right? if it is correct then  which situation we use the org wide default settings for an org once we have profile permissions?

 

 

please clarify this