• ashu 6112
  • NEWBIE
  • 85 Points
  • Member since 2015
  • SalesforceDeveloper

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 28
    Replies
public class UpdateMassSessionattendanceCls {

    public list<fieldWrapper>lstfieldWrapper{get;set;}
    public list<string>lsttableHeader{get;set;}
    public list<Session_Attendance__c>lstSession_Attendance{get;set;}
    public  string sessionId{get;set;}
    public UpdateMassSessionattendanceCls(ApexPages.StandardController controller) 
    {
        Session__c objSession = (Session__c)controller.getRecord();
         string sessionId =objSession.id;

        //string sessionId= 'a0o1D0000007TdA';
        lstfieldWrapper = new list<fieldWrapper>();
        
        string FieldSetName= label.SessionAttendanceMassUpdate;
        set<string>setFieldName= new set<string>();
        setFieldName.add('id');
         Map<String, Schema.FieldSet> FsMap =   Schema.SObjectType.Session_Attendance__c.fieldSets.getMap();
        
        Schema.SObjectType targetType = Schema.getGlobalDescribe().get('Session_Attendance__c');
        Sobject Object_name = targetType.newSObject();
        Schema.sObjectType sobject_type = Object_name.getSObjectType();
        Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe();
        Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap();
       
        if(FsMap.containskey(FieldSetName))
        {
              Schema.FieldSet fs1 = FsMap.get(FieldSetName);
              for(Schema.FieldSetMember f : fs1.getFields())
              {
                    fieldWrapper objfieldWrapper = new fieldWrapper();
                    objfieldWrapper.APIName = f.fieldPath;
                    objfieldWrapper.Label = f.label;
                    Schema.DescribeFieldResult dsr = field_map.get(objfieldWrapper.APIName).getDescribe();
                    objfieldWrapper.isEditable = dsr.isUpdateable();
                    objfieldWrapper.fieldType = String.valueOf(f.getType());
                    setFieldName.add(objfieldWrapper.APIName);
                    if(objfieldWrapper.fieldType == 'REFERENCE' )
                    {
                        string fieldAPINameReference = objfieldWrapper.APIName.replace('__c','__r.name');
                        setFieldName.add(fieldAPINameReference);
                        objfieldWrapper.fieldReferenceName= fieldAPINameReference;
                    }
                    lstfieldWrapper.add(objfieldWrapper);
              }
              system.debug('lstfieldWrapper--'+lstfieldWrapper);
              lstSession_Attendance = new list<Session_Attendance__c>();
              list<string>lstallField= new list<string>();
              lstallField.addALL(setFieldName);
              string query= 'select '+String.join(lstallField, ',') + ' from Session_Attendance__c where Session__c = \''+sessionId+'\'';
              lstSession_Attendance= Database.query(query);
              system.debug('Query --'+query);
              
        }
        
        
        
        
        
    }

public pagereference saveData()
{
    try
    {
    update lstSession_Attendance;
     apexpages.Message msg = 
      new Apexpages.Message(ApexPages.Severity.Info,'Record(s) Update successfully');
    apexpages.addmessage(msg);
    }
    catch(Exception e)
    {
         apexpages.Message msg = 
      new Apexpages.Message(ApexPages.Severity.Error,e.getmessage());
    apexpages.addmessage(msg);
    }
    return null;
}


public class fieldWrapper
{
    public string APIName{get;set;}
    public boolean isEditable{get;set;}
    public string Label{get;set;}
    public string fieldType{get;set;}
    public string fieldReferenceName{get;set;}
    
}

}
I've gone through every step successfully but am banging my head against the wall with step 8. I have more than adequate code coverage but continue to get this error message:
User-added image
I have gone back and rewritten OrderTests twice according to the requirements but can't get past this error. Anyone else had any luck with this?

Here's my code for reference:
@isTest (SeeAllData=false)
private class OrderTests {
    
    static void SetupTestData() {
	    TestDataFactory.InsertTestData(5);
    }
 
    @isTest static void OrderExtension_UnitTest() {
        PageReference pageRef = Page.OrderEdit;
        Test.setCurrentPage(pageRef);
        SetupTestData();
        ApexPages.StandardController stdcontroller = new ApexPages.StandardController(TestDataFactory.orders[0]);        
        OrderExtension ext = new OrderExtension(stdcontroller);        
       	System.assertEquals(Constants.DEFAULT_ROWS, ext.orderItemList.size());
        ext.OnFieldChange();
        ext.SelectFamily();
        ext.Save();
        ext.First();
        ext.Next();
        ext.Previous();
        ext.Last();
        ext.GetHasPrevious();
        ext.GetHasNext();
        ext.GetTotalPages();
        ext.GetPageNumber();
        List<SelectOption> options = ext.GetFamilyOptions();
    }
    
@isTest
public static void OrderUpdate_UnitTest(){
    setupTestData();
    
   
    Test.startTest();
    
    List<Order> orders = TestDataFactory.orders;
    for (Order o : orders){
        o.Status = Constants.ACTIVATED_ORDER_STATUS;
    }
    List<Product2> oldProducts = TestDataFactory.products;
    Set<Id> productIds = new Set<Id>();
    for (Product2 oldProd : oldProducts){
        productIds.add(oldProd.Id);
    }
    oldProducts = [SELECT Id, Quantity_Ordered__c FROM Product2 WHERE ID IN :productIds];
    Map<Id, Integer> quantities = new Map<Id, Integer>();
    for (OrderItem oi : TestDataFactory.orderItems){
        Integer quantity = 0;
        List<PricebookEntry> pricebookentries = TestDataFactory.pbes;
        for (PricebookEntry pbe : pricebookentries){
            if (oi.PricebookEntryId == pbe.Id){                
                if (quantities.containsKey(pbe.Product2Id)){
                    quantity = quantities.get(pbe.Product2Id);
                }
                quantity += (Integer)oi.Quantity;
                quantities.put(pbe.Product2Id, quantity);
                break;
            }
        }
    }
   
    update orders;
    Map<Id, Product2> currentProducts = new Map<Id, Product2>([Select Id, Quantity_Ordered__c FROM Product2 WHERE Id IN :productIds]);
  
    for (Product2 prod : oldProducts){
      
        TestDataFactory.VerifyQuantityOrdered(prod, currentProducts.get(prod.Id), quantities.get(prod.Id));
  }
  Test.stopTest();
}
}

 
Hi All, 

In the Knowledge page layout, we have the option to add related list by drag and drop so that Approval History can be displayed. 

User-added image

We can include some more columns to this related list but they are limited.

User-added image

I want to add some more columns which are not listed in above screenshot - These fields exist in knowledge object and are my custom fields.
Is this achievable? 

 
 

Is there anyway to either open a Lightning page from a record page action button (with the recordid included)
OR
to open a Lightning component from a record page action button but in full screen width (not just a pop up dialog)?

Thanks,
Matt

Here's my component code:

<aura:component implements="force:lightningQuickAction,force:hasRecordId" access="global"  >
<ui:inputText aura:id="PlanName" label="Plan Name" required="true" change="{!c.onChange}"/>   
<ui:inputnumber aura:id="Amount" label="Amount" required="true" change="{!c.onChange}" />
<lightning:button label="Add New Card"   aura:id="newcard"    onclick="{!c.chargefun}"  />  
</aura:component >
   
component.js code :

({
 onChange : function(component, event, helper)
    {        
            var selectCmp = event.getSource();
          selectCmp.set("v.errors",null);
    },

chargefun : function(component,event,helper)
{
  var PlanName = component.find("PlanName").get("v.value");
  var amt = component.find("Amount");
  var amount = amt.get("v.value");
   if($A.util.isEmpty(amount) ||  $A.util.isEmpty(PlanName ))
   {
       if ($A.util.isEmpty(amount))
           {
             amt.set("v.errors", [{message:"Please Enter Value"}]);
           }
           if ($A.util.isEmpty(PlanName))
           {
             component.find("PlanName").set("v.errors", [{message:"Please Enter Value..."}]);
           }
   },

})


In above code,  event.getSource() was not working for <ui:inputnumber>. So iam not able to remove error message.
public static Account insertIntoAccount(Account account){
		try{
			insert account;
			return account;
		}catch(Exception e){
		   string error = ExceptionLogger.createExceptionsRecord(e.getMessage(), 'DealReqContactController', e.getStackTraceString());
			throw new AuraHandledException(error);
			return null;
	   }
    }

Hi All, 
I have to cover code coverage of catch block.

Please help:

 
Hi All,

I have to write test class for the below trigger helper class.  NEED HELP.




public class CableDealHeaderTriggerHandler {
    
    //method to update all related Deal Request
    public static void updateDealRequest(List<Deal_Request_Header__c> drhNewList, Map<id,Deal_Request_Header__c>drhOldMap){
        List<Cable_Deal_Request__c> cdrListUpdate = new List<Cable_Deal_Request__c>();
        
        //Query on Deal Request Header with Inner Query to get all related Deal Request
        List<Deal_Request_Header__c> drhList = [select id,name,Cable_Ownership__c, Cable_Program_Category__c,
                                                Cable_Network__c,Cable_Requested_By__c,Cable_Project_Phase__c,Cable_Program_Type__c,Cable_Genre__c,
                                                Cable_Program_Format__c,Cable_Program_Length__c, Cable_Camera_View__c, Deal_Request_Date__c,
                                                Cable_Submitted_Date__c,
                                                (select id,Cable_Network_Platform__c,Cable_Requesting_Executive__c,Cable_Project_Phase__c,Cable_Ownership__c,
                                                Cable_Program_Type__c,Cable_Program_Category__c,Genre__c,Cable_Program_Format__c,Cable_Program_Length__c,
                                                Cable_Camera_View__c,Deal_Request_Date__c,Cable_Submitted_Date__c from Cable_Deal_Requests__r)
                                                from Deal_Request_Header__c where id in : drhNewList];
        
        //For loop to iterate and check if fields are saved or not                                        
        for(Deal_Request_Header__c drh : drhList){
            if( (drh.Cable_Ownership__c != drhOldMap.get(drh.id).Cable_Ownership__c) || (drh.Cable_Program_Category__c != drhOldMap.get(drh.id).Cable_Program_Category__c) || 
                (drh.Cable_Network__c != drhOldMap.get(drh.id).Cable_Network__c) || (drh.Cable_Requested_By__c != drhOldMap.get(drh.id).Cable_Requested_By__c) ||
                (drh.Cable_Project_Phase__c != drhOldMap.get(drh.id).Cable_Project_Phase__c) || (drh.Cable_Program_Type__c != drhOldMap.get(drh.id).Cable_Program_Type__c) ||
                (drh.Cable_Program_Type__c != drhOldMap.get(drh.id).Cable_Program_Type__c) || (drh.Cable_Genre__c != drhOldMap.get(drh.id).Cable_Genre__c) ||
                (drh.Cable_Program_Format__c != drhOldMap.get(drh.id).Cable_Program_Format__c) || (drh.Cable_Program_Length__c != drhOldMap.get(drh.id).Cable_Program_Length__c) ||
                (drh.Cable_Camera_View__c != drhOldMap.get(drh.id).Cable_Camera_View__c) || (drh.Deal_Request_Date__c != drhOldMap.get(drh.id).Deal_Request_Date__c) ||
                (drh.Cable_Submitted_Date__c != drhOldMap.get(drh.id).Cable_Submitted_Date__c))
            {
                if(drh.Cable_Deal_Requests__r.size()>0){
                    //for loop on related Deal Request
                    for(Cable_Deal_Request__c cdr : drh.Cable_Deal_Requests__r){
                        if(drh.Cable_Network__c != drhOldMap.get(drh.id).Cable_Network__c)
                            cdr.Cable_Network_Platform__c = drh.Cable_Network__c;
                        if(drh.Cable_Requested_By__c != drhOldMap.get(drh.id).Cable_Requested_By__c)
                            cdr.Cable_Requesting_Executive__c = drh.Cable_Requested_By__c;
                        if(drh.Cable_Project_Phase__c != drhOldMap.get(drh.id).Cable_Project_Phase__c)
                            cdr.Cable_Project_Phase__c = drh.Cable_Project_Phase__c;
                        if(drh.Cable_Ownership__c != drhOldMap.get(drh.id).Cable_Ownership__c)
                            cdr.Cable_Ownership__c = drh.Cable_Ownership__c;
                        if(drh.Cable_Program_Type__c != drhOldMap.get(drh.id).Cable_Program_Type__c)
                            cdr.Cable_Program_Type__c = drh.Cable_Program_Type__c;
                        if(drh.Cable_Program_Category__c != drhOldMap.get(drh.id).Cable_Program_Category__c)
                            cdr.Cable_Program_Category__c = drh.Cable_Program_Category__c;
                        if(drh.Cable_Genre__c != drhOldMap.get(drh.id).Cable_Genre__c)
                            cdr.Genre__c = drh.Cable_Genre__c;
                        if(drh.Cable_Program_Format__c != drhOldMap.get(drh.id).Cable_Program_Format__c)
                            cdr.Cable_Program_Format__c = drh.Cable_Program_Format__c;
                        if(drh.Cable_Program_Length__c != drhOldMap.get(drh.id).Cable_Program_Length__c)
                            cdr.Cable_Program_Length__c = drh.Cable_Program_Length__c;
                        if(drh.Cable_Camera_View__c != drhOldMap.get(drh.id).Cable_Camera_View__c)
                            cdr.Cable_Camera_View__c = drh.Cable_Camera_View__c;
                        if(drh.Deal_Request_Date__c != drhOldMap.get(drh.id).Deal_Request_Date__c)
                            cdr.Deal_Request_Date__c = drh.Deal_Request_Date__c;
                        if(drh.Cable_Submitted_Date__c != drhOldMap.get(drh.id).Cable_Submitted_Date__c)
                            cdr.Cable_Submitted_Date__c = drh.Cable_Submitted_Date__c;
                        cdrListUpdate.add(cdr);
                    }
                }
                
            }
        }
        
        if(cdrListUpdate.size()>0)
            update cdrListUpdate;
    }
}
Hi All, Need your help:
​Need to write test clas for this trigger:


trigger updateLicensorContact on Greensheet__c (after update)  
{
    Set<Id> stemp = new Set<Id>();
    
    for(Greensheet__c g : trigger.new)
    {
        stemp.add(g.Licensor_Contact__c);
    }
    List<Contact> contacttobeUpdated = new List<Contact>();
    
    if(Trigger.isUpdate )
    {
    Map<Id,Contact> mapid = new Map<Id,Contact>([select id,FirstName,LastName,MiddleName,Phone,Suffix,Email,Title,MobilePhone,BillingStreet__c,BillingCity__c,BillingState__c,BillingCountry__c,BillingPostalCode__c,(select id,First_Name__c,Last_Name__c,Phone__c,Title__c,Mobilephone__c,Suffix__c,Middle_Name__c,Email__c,BillingStreet__c,BillingState__c,BillingCity__c,BillingCountry__c,BillingPostalCode__c from Greensheets__r) from Contact where Id IN:stemp]);    
    System.debug('Mapid*****'+mapid);
    //Map<Id,Contact> mapidd = new Map<Id,Contact>([select id,FirstName,LastName,MiddleName,Phone,Suffix,Email,Title,MobilePhone,BillingStreet__c,BillingCity__c,BillingState__c,BillingCountry__c,BillingPostalCode__c,(select id,First_Name__c,Last_Name__c,Phone__c,Title__c,Mobilephone__c,Suffix__c,Middle_Name__c,Email__c,BillingStreet__c,BillingState__c,BillingCity__c,BillingCountry__c,BillingPostalCode__c from Greensheets__r) from Contact where Id IN:stemp]); 
    for(Greensheet__c gs : trigger.new)
    {
        Contact c = mapid.get(gs.Licensor_Contact__c);
        //Licensor_Contact__c=mapidd.get(c.id);
        If(gs.Licensor_Contact__c != null && gs.Licensor_Contact__c  == Trigger.OldMap.get(gs.id).Licensor_Contact__c   )
        {
         
           c.FirstName = gs.First_Name__c;
           // c.id = gs.id;
            c.LastName = gs.Last_Name__c;             
            c.Phone = gs.Phone__c ;
           c.MiddleName = gs.Middle_Name__c;
            c.Email = gs.Email__c;
            c.Title = gs.Title__c ;
            c.MobilePhone = gs.Mobilephone__c;
            c.BillingStreet__c = gs.BillingStreet__c ;
            c.BillingCity__c = gs.BillingCity__c;
            c.BillingState__c = gs.BillingState__c ;
            c.BillingCountry__c = gs.BillingCountry__c ;
            c.BillingPostalCode__c = gs.BillingPostalCode__c ;
            
            contacttobeUpdated.add(c);
            }
            
          
           
    
  
 
       
       }
    //update mapid.values();
    update contacttobeUpdated;
    
    //system.debug('@@@@@'+mapid);
    }
    
}
I need to write test class along with test data factory class for the below class, anyone help plz..


public class ApprovalProcessDemoController {

    @AuraEnabled
     public static void submitAndProcessApprovalRequest(String firtTextBoxId) {
        
         ApprovalProcessDemo__c ApprovalObj = new ApprovalProcessDemo__c();
         ApprovalObj.Name = firtTextBoxId;
         //ApprovalObj.First_Value__c = 'Submitted';
         insert ApprovalObj;
         
         User user1 = [SELECT Id FROM User WHERE Alias Like:'%ggarg%' limit 1];
         
         // Create an approval request for the Approval Process Demo
        Approval.ProcessSubmitRequest req1 = 
            new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setObjectId(ApprovalObj.Id);
        
          // Submit on behalf of a specific submitter
        req1.setSubmitterId(user1.Id); 
        
        // Submit the record to specific process and skip the criteria evaluation
        req1.setProcessDefinitionNameOrId('Demo_Approval_Process');
        req1.setSkipEntryCriteria(true);
        
        // Submit the approval request for the account
        Approval.ProcessResult result = Approval.process(req1);
        
        // Verify the result
        System.debug('+++++ :' +result.isSuccess());
         System.debug('+++++ Pending:' +result.getInstanceStatus());
          System.debug('+++++ :' +result.getInstanceStatus());
         
        
        // Approve the submitted request
        // First, get the ID of the newly created item
       /* List<Id> newWorkItemIds = result.getNewWorkitemIds();
        
        // Instantiate the new ProcessWorkitemRequest object and populate it
        Approval.ProcessWorkitemRequest req2 = 
            new Approval.ProcessWorkitemRequest();
        req2.setComments('Approving request.');
        req2.setAction('Approve');
        req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
        
        // Use the ID from the newly created item to specify the item to be worked
        req2.setWorkitemId(newWorkItemIds.get(0));
        
        // Submit the request for approval
        Approval.ProcessResult result2 =  Approval.process(req2);
        
        // Verify the results
        System.debug(result2.isSuccess() + '  Result Status :  ' +result2.isSuccess());
        
        System.debug(  'Approved   -   '+ result2.getInstanceStatus()); 
           System.debug( 'Instance Status -   '+result2.getInstanceStatus());         
     */    
      
    }
    
}
Hi,

I have wrote a trigger to send an attachment once the Account Field 'Status' field value changed to 'Approved/Submitted to BA' OR 'Paperwork Complete'.
All is working fine except it is attaching the document 2 times, we have to attach only one time.

trigger SendAttachmentonAccount on Account (after update) 

    List<Account> lstGreensheet = new List<Account>();
    system.debug('======= AccountAttachment Started =============');
    Account AccountOld = trigger.old[0];
    Account AccountNew = trigger.new[0];
    system.debug('AccountOld '+ AccountOld.get('Status__c'));   
    system.debug('AccountNew '+ AccountNew.get('Status__c'));
        
    if((AccountOld.get('Status__c') != AccountNew.get('Status__c')) && 
       (AccountNew.get('Status__c') == 'Approved/Submitted to BA' ||
        AccountNew.get('Status__c') == 'Paperwork Complete' ))
        {
        
            generateAccountPDF.attachingPDFOnStatusChange((String)AccountNew.get('Id'),(String)AccountNew.get('Name'));    
               
        }
        system.debug('======= Account Attachment Completed =============');  
}
Hi,
Below is my code for the trigger for  duplicate prevention on the account . It works well, but if I have 50k records this impacts scalability and not feasible.
So please any one can help to code in better way.
thanks in advance.
trigger AccountDuplicate on Account (before insert) {
 List<Account> dup = new List<Account>();
 dup = [Select id, Name from Account];
 for(Account a:Trigger.New){
 for(Account a1:dup){
 if(a.Name==a1.Name){
 a.Name.addError('Name already Exist ');
 }
 }
 }   
 }
I want to show formula field that is in Lead Object,And this formula field contains Image. when i call this field in component in OutputText it show url of Image. please help me. I don't know how to use OUTPUTRICHTEXT
Component:

<aura:component controller="LeadLightningContoller">
	 <ltng:require styles="/resource/SLDS103/assets/styles/salesforce-lightning-design-system.min.css"/>
    <aura:attribute name="Leads" type="Lead[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

 <aura:iteration items="{!v.Leads}" var="lead">

 <ui:outputText value="{!lead.Rating_Image__c}"/>

 </aura:iteration>
 
helper Class

({
	getLeadList : function(component) {
        
        var action=component.get("c.ShowLead");
        action.setCallback(this,function(res){
           
            var status=res.getState();
            if(status=="SUCCESS"){
                component.set("v.Leads",res.getReturnValue());
            }
        });
		$A.enqueueAction(action);
	}
})
Controller


public class LeadLightningContoller {
    
    @AuraEnabled
    public static List<Lead> ShowLead(){
        
        List<Lead> leadList=new List<Lead>();
        
        leadList=[select Name,Email,Status,Phone,No_of_days_Open__c,Rating,Fax,Rating_Image__c from Lead limit 10];
        return leadList;
       
    }

}
Application

<aura:application >
  <c:LeadData />
</aura:application>

 
How to write trigger to avoid duplicate email when bulkfying the trigger

my trigger is:

trigger AvoidDuplicate on contact (before insert,before update)
{
   if(Trigger.isInsert||Trigger.isUpdate)
      for(contact a:trigger.new)
     {
         integer count=[select count from contact where email=:a.email];
         if(count>0)
          {
                 a.Email.adderror('This email already exists');
          }
     }
}

this is working fine when inserting single records

but it shows error when working with dataloader...... Please help to to over come this error


I would appriciate for any kind of replay...............

Hi All,

 

I want to get all fieldnames of a object in apex. How can I do this?

 

For example for User object I want to get all its field names like AboutMe, AccountId , Email etc.

 

Any help on this really appreciated.

 

Regards,

Naren