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

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 26
    Replies
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? 

 
 
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;}
    
}

}
Hi All,

I am getting all the records of associated deals as expected, but as the nuimber of record in database are large, so it is dispalying in different pages. 
Now the issue is Table header valures "talent Name" & "Service Type" is coming only on First page(because we didnot apply any repeat functionlity over the header) not on all pages, on all other pages, there is first row blank....Is there ay way to repeat the header values only after the page break..


Thanks in Advance for the help..
<apex:outputpanel rendered="{!(dealRequest.ad.size > 0)}" >
             <div class="slds-m-bottom--x-large">
                <h3 class="slds-p-around--x-small slds-theme--info slds-text-heading--medium"><strong>Associated Deals</strong></h3>
                
                <table class="slds-box slds-table slds-table--bordered slds-table--col-bordered slds-no-row-hover colBordered">
                  
                  <thead>
                  <tr class="slds-text-title--caps slds-theme--shade">
                      <th scope="col">
                      
                        <div class="slds-truncate">Talent Name</div>
                        
                      </th>
                      <th colspan="2" scope="col">
                        <div class="slds-truncate">Service Type</div>
                      </th>
                    </tr>
                    </thead>
                    
                  <tbody>
                    <apex:repeat value="{!dealRequest.ad}" var="assDeals">
                      <tr>
                      <td>
                        <div class="slds-truncate">{!assDeals.Talent_Name__r.Name}</div>
                      </td>
                      <td>
                        <div class="slds-truncate">{!assDeals.Service_Type__c}</div>
                      </td>
                    </tr>
                    </apex:repeat>
                  </tbody>
                </table>
             </div>
            </apex:outputpanel>

 
I have to write test class for this. please help.

Thanks, in Advance.
/********
Class Name : CableDealRequestHeaderCreateExtension
Created By :
Created Date :
Purpose :
Last Modified By:
Test Class Name
Code Coverage
*********/

public class CableDealRequestHeaderCreateExtension {
    
    public CableDealRequestHeaderCreateExtension (ApexPages.StandardController controller) {
        
    }
    
    public PageReference createDealHeader() {
        
		try{
			String dealHeaderId = CablepitchTalentController.createDealRequest(ApexPages.currentPage().getParameters().get('id'), new List<String>());
        PageReference editPage = new PageReference('/apex/CableDealRequestOpenEditPage?id='+dealHeaderId);
        editPage.setRedirect(true);
        return editPage;
		}catch(Exception e){
		string error = ExceptionLogger.createExceptionsRecord(e.getMessage(), 'CableDealRequestHeaderCreateExtension', e.getStackTraceString());
            throw new AuraHandledException(error);
		}
    }
     public PageReference createDealHeaderFromProject() {
	 
        String projectId = ApexPages.currentPage().getParameters().get('id');
        Cable_Project__c project = [SELECT Id, Cable_Title__c,Ownership__c,Production_Slated_Month__c,Level__c,Default_Budget__c,Development_Budget_Notes__c,Cable_Production_Year__c,Cable_Program_Type1__c,Cable_Program_Category__c,Cable_Project_Phase__c, Cable_Production_Phase__c, Network_Platform__c, Cable_Genre__c, Cable_Camera_View__c,Cable_Logline__c,
                                Cable_ABC_Network_Creative_Executive__c, Cable_Program_Length__c, Cable_Program_Type__c , Cable_Project_Type__c, Name FROM Cable_Project__c WHERE Id = :projectId];
                                 
        Deal_Request_Header__c dealHeader = new Deal_Request_Header__c();
        dealHeader.Cable_Project_Phase__c= project.Cable_Project_Phase__c;
        dealHeader.Cable_Production_Phase__c= project.Cable_Production_Phase__c;
        dealHeader.Cable_Current_Working_Title__c= project.Id;
        
        if(String.isBlank(project.Network_Platform__c)) {
            dealHeader.Cable_Network__c= '';
        } else {
            dealHeader.Cable_Network__c= project.Network_Platform__c;
        }
        dealHeader.Cable_Deal_Type__c= project.Cable_Project_Type__c;
        dealHeader.Cable_Program_Format__c= project.Cable_Program_Type__c;
        if(project.Cable_Project_Phase__c!=''){
            dealHeader.Cable_Program_Length__c= project.Cable_Program_Length__c;
        }else{
            dealHeader.Cable_Program_Length__c=null;   
        }
        dealHeader.Cable_Genre__c= project.Cable_Genre__c;
         if(project.Cable_Camera_View__c=='Not Applicable'){
            dealHeader.Cable_Camera_View__c= 'Other';
         }
         else{
        dealHeader.Cable_Camera_View__c= project.Cable_Camera_View__c;
         }
        dealHeader.Cable_Logline__c= project.Cable_Logline__c;
        dealHeader.Cable_Ownership__c=project.Ownership__c;
        dealHeader.Cable_Production_Year__c=project.Cable_Production_Year__c;
        dealHeader.Cable_Program_Type__c=project.Cable_Program_Type1__c;
        dealHeader.Cable_Program_Category__c=project.Cable_Program_Category__c; 
        dealHeader.Cable_Current_Working_Title__c=projectId;
        dealHeader.Cable_Deal_Header_Status__c='Draft';
        dealHeader.Default_Budget__c=project.Default_Budget__c;
        dealHeader.Development_Budget_Notes__c=project.Development_Budget_Notes__c;
        dealHeader.Production_Slated_Month__c=project.Production_Slated_Month__c;
        dealHeader.Cable_Production_Year__c=project.Cable_Production_Year__c;
        dealHeader.Level__c=project.Level__c;
        try {
            insert dealHeader;
        } catch(Exception e) {
		
			string error = ExceptionLogger.createExceptionsRecord(e.getMessage(), 'CableDealRequestHeaderCreateExtension', e.getStackTraceString());
            throw new AuraHandledException(error);
            dealHeader.Cable_Program_Format__c= null;
            dealHeader.Cable_Program_Length__c=null;
            insert dealHeader;
            
        }
        if(String.isNotBlank(project.Cable_ABC_Network_Creative_Executive__c)) {
            Cable_Deal_Request_Creative_Executive__c Cableexec = new Cable_Deal_Request_Creative_Executive__c();
            Cableexec.Creative_Executive__c = project.Cable_ABC_Network_Creative_Executive__c;
            Cableexec.Cable_Deal_Request_Header__c= dealHeader.Id;
            //exec.Primary__c = TRUE;
            insert Cableexec;
        } 
         system.debug('deal id is '+dealHeader.Id);
        PageReference editPage = new PageReference('/apex/CableDealRequestOpenEditPage?id='+dealHeader.Id);
        editPage.setRedirect(true);
        return editPage;
    }
    
}

 
I have to cover "sendEmailOnSubmission" method in my test class, please suggest how to cover this method.
class CableDealRequestTriggerHandler is handler class of a trigger.

public class CableDealRequestTriggerHandler{  
  //Method for sending Email to BA/DL 
    public void sendEmailOnSubmission(List<Cable_Deal_Request__c> cdrList,Map<id,Cable_Deal_Request__c> cdrOldMap,Map<Id,Deal_Request_Header__c> headerMap){
        
        try{
            
        //sending Email to BA/DL
        
        for(Cable_Deal_Request__c cdr : cdrList){
            system.debug('Cable Deal Request==>>>' + cdr);
            system.debug('If stateemnt==> ' + cdr.Cable_Deal_Status__c + '   ' + cdrOldMap.get(cdr.id).Cable_Deal_Status__c);
            if((cdr.Cable_Deal_Status__c == 'Submitted' || cdr.Cable_Deal_Status__c == 'Submitted to BA') && (cdrOldMap.get(cdr.id).Cable_Deal_Status__c=='Pending Finance Approval' || cdrOldMap.get(cdr.id).Cable_Deal_Status__c=='Open')){
                List<String>ccList = new List<String>();
                List<String>toList = new List<String>();
                system.debug('Enter after submitted');
                
                //toList.add(headerMap.get(cdr.Deal_Request_Header__c).user__r.email);
                
                if(headerMap.get(cdr.Deal_Request_Header__c).createdby.email != null)
                    ccList.add(headerMap.get(cdr.Deal_Request_Header__c).createdby.email);
                if(headerMap.get(cdr.Deal_Request_Header__c).Cable_Requested_By__r.email != null)
                    ccList.add(headerMap.get(cdr.Deal_Request_Header__c).Cable_Requested_By__r.email);
                for(Cable_Deal_Request_Creative_Executive__c cdre : headerMap.get(cdr.Deal_Request_Header__c).Cable_Deal_Request_Creative_Executives__r){
                    ccList.add(cdre.Creative_Executive__r.email);
                }
                
                if(cdr.Cable_Network_Platform__c.contains('Freeform')){
                    DisneyCableDls__c dsCable = DisneyCableDls__c.getInstance('Freeform DL');
                    toList.add(dsCable.DL_Email__c);

                }
                else{
                    DisneyCableDls__c dsCable = DisneyCableDls__c.getInstance('DCWW Dl');
                    toList.add(dsCable.DL_Email__c);
                }
                system.debug('List of reciepient==>> ' + ccList +'   ' + toList);
                
                contact tstCont = new Contact();
                tstCont.lastName='TEst';
                tstCont.email = 'test@test.com';
                insert tstCont;
                
                EmailTemplate templateId = [Select id from EmailTemplate where DeveloperName = 'Cable_Deal_Submitted_Email_Template' limit 1];
                
                List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setToAddresses(toList);
                mail.setTemplateID(templateId.Id); 
                mail.setccAddresses(ccList);
                mail.setTargetObjectId(tstCont.id);
                mail.setWhatId(cdr.id);
                mail.setSaveAsActivity(false);
                allmsg.add(mail);
                system.debug('Email Information ==>>' + mail);
                Messaging.sendEmail(allmsg); 
                delete tstCont;    
                
            }
        }
        }catch(Exception e){
            //string error = ExceptionLogger.createExceptionsRecord(e.getMessage(), 'CableDealRequestTriggerHandler', e.getStackTraceString());
            //throw new AuraHandledException(error);
           saveExceptionLogs(e.getMessage(),'CableDealRequestTriggerHandler',e.getStackTraceString());
        }
        
    }
}    
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 for the below class: 
Please suggest:




public without sharing class generateGreensheetPDF {
    
    private Greensheet__c greensheet{get;set;} 
    public String idGreensheet {get;set;}
    
    public generateGreensheetPDF(){    }
    
    
    public generateGreensheetPDF(ApexPages.StandardController cntrll){
        idGreensheet = ApexPages.currentPage().getParameters().get('id');
        greensheet = (Greensheet__c)cntrll.getRecord();
        System.debug('idGreensheet '+idGreensheet);
    }
    
    @Future(callout=true)
    public static void attachingPDFOnStatusChange(String id,String name){
        system.debug('==== Executing attachingPDFOnStatusChange Started============');
        String pdfName = name+'.pdf';
        PageReference pgPDFAtachment = Page.greensheetpdf;
        pgPDFAtachment.getParameters().put('id',id);
        Blob blobPDF = pgPDFAtachment.getContent();
        String tmpName = '';
        
        Attachment attachPDF = new Attachment(parentid= id,Name=pdfName,body=blobPDF);
        insert attachPDF;
        system.debug('==== Executing attachingPDFOnStatusChange Completed============');
    }   
    
    @Future(callout=true)
    public static void attachingPDFOnStatusChange(String idGreensheetrec,String strTitle,String statusCurr){
        system.debug('==== Executing attachingPDFOnStatusChange Started============');
        String pdfName = '';
        PageReference pgPDFAtachment = Page.greensheetpdf;
        pgPDFAtachment.getParameters().put('id',idGreensheetrec);
        Blob blobPDF = pgPDFAtachment.getContent();
        String tmpName = '';
        pdfName = genFileNameForGreensheetAtt(idGreensheetrec,strTitle, statusCurr);
        Attachment attachPDF = new Attachment(parentid= idGreensheetrec,Name=pdfName,body=blobPDF);
        insert attachPDF;
        system.debug('==== Executing attachingPDFOnStatusChange Completed============');
    }   
    
    public static String genFileNameForGreensheetAtt(String idGreensheetrec,String strTitle,String statusCurr){
        //idGreensheetrec = 'a1IV00000018Uy7MAE';
        //strTitle = 'Fox Movie Package';
        //statusCurr = 'Paperwork Complete%';
        system.debug('idGreensheetrec '+idGreensheetrec+'====strTitle :'+strTitle+'=====statusCurr :'+statusCurr);
        String strSearchQuery = strTitle +'_'+ statusCurr;
        
        String strFileName ='';
        /*
List<Attachment> lstAtt = [SELECT count(Name) FROM Attachment    //SELECT Id,Name,ParentId,SystemModstamp FROM Attachment 
WHERE ParentId =:idGreensheetrec  AND Name LIKE :strSearchQuery 
ORDER BY SystemModstamp DESC NULLS FIRST ];
if(lstAtt!=null && lstAtt.size()>0){
//tmpName = lstAtt.get(0).Name;
//pdfName = lstAtt.get(0).Name.split('_')[0]
}else{

}*/
        
        AggregateResult[] aresult = [select count(ParentId) attatchmentCnt From Attachment Where ParentId=:idGreensheetrec AND Name LIKE :strSearchQuery+'%' ];
        
            for(AggregateResult ar : aresult){
                system.debug(' Res -->'+ar.get('attatchmentCnt'));
                if((Integer)ar.get('attatchmentCnt')>0){
                    system.debug('QueryRes :'+(Integer)ar.get('attatchmentCnt'));
                    strFileName = strSearchQuery+'_'+ar.get('attatchmentCnt')+'.pdf';        
                    
                }else{
                    strFileName = strSearchQuery+'.pdf';
                }    
            }    
        
        system.debug('FileName Generated :'+strFileName);
        return strFileName;
    }
    
    public PageReference attachingPDF(){
        String pdfName = [select Name from Greensheet__c where Id=:idGreensheet limit 1][0].Name+'.pdf';
        PageReference pgPDFAtachment = Page.greensheetpdf;
        pgPDFAtachment.getParameters().put('id',idGreensheet);
        Blob blobPDF = pgPDFAtachment.getContent();
        // Attachment attachPDF = new Attachment(parentid= greensheet.Id,Name=pdfName,body=blobPDF);
        Attachment attachPDF = new Attachment(parentid= idGreensheet,Name=pdfName,body=blobPDF);
        insert attachPDF;
        
        PageReference redirectToPage = new ApexPages.StandardController(greensheet).view();
        redirectToPage.setRedirect(true);
        return redirectToPage;
    }   
    
    
}
I have this trigger, need to write test class for this: 
Please help.

trigger AccountInitiationDate on Account (before insert) {
    List<Account> lstacc = new List<Account>();
    for(Account account : trigger.new){
        //if(account.Initiation_Date__c==null){
                account.Initiation_Date__c=System.today();
                account.Approval_Date__c=null;
                account.Status__c='Draft';
                lstacc.add(account);
            System.debug('AccountInitiationDate Initiated ');
        //}
    }
}
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 folks,
Can anyone tell me how to get the dependent picklist values based on the Controlling picklist value in Apex?
I need a Optimise code for that..

Thanks,

I already have this code and it is working fine, bu i need optimise code.

public static Map<String,List<String>> GetDependentOptions(String pObjName, String pControllingFieldName, String pDependentFieldName){
        Map<String,List<String>> objResults = new Map<String,List<String>>();
        //get the string to sobject global map
        Map<String,Schema.SObjectType> objGlobalMap = Schema.getGlobalDescribe();
        if (!objGlobalMap.containsKey(pObjName))
            return objResults;
        //get the type being dealt with
        Schema.SObjectType pType = objGlobalMap.get(pObjName);
        Map<String, Schema.SObjectField> objFieldMap = pType.getDescribe().fields.getMap();
        //verify field names 
        if (!objFieldMap.containsKey(pControllingFieldName) || !objFieldMap.containsKey(pDependentFieldName))
            return objResults;     
        //get the control values   
        List<Schema.PicklistEntry> ctrl_ple = objFieldMap.get(pControllingFieldName).getDescribe().getPicklistValues();
        //get the dependent values
        List<Schema.PicklistEntry> dep_ple = objFieldMap.get(pDependentFieldName).getDescribe().getPicklistValues();
        //iterate through the values and get the ones valid for the controlling field name
        TStringUtils.Bitset objBitSet = new TStringUtils.Bitset();
        //set up the results
        for(Integer pControllingIndex=0; pControllingIndex<ctrl_ple.size(); pControllingIndex++){            
            //get the pointer to the entry
            Schema.PicklistEntry ctrl_entry = ctrl_ple[pControllingIndex];
            //get the label
            String pControllingLabel = ctrl_entry.getLabel();
            //create the entry with the label
            objResults.put(pControllingLabel,new List<String>());
        }
        //cater for null and empty
         objResults.put('',new List<String>());
         objResults.put(null,new List<String>());
        //check the dependent values
        for(Integer pDependentIndex=0; pDependentIndex<dep_ple.size(); pDependentIndex++){            
            //get the pointer to the dependent index
               Schema.PicklistEntry dep_entry = dep_ple[pDependentIndex];
               //get the valid for
            String pEntryStructure = JSON.serialize(dep_entry);                
            TStringUtils.TPicklistEntry objDepPLE = (TStringUtils.TPicklistEntry)JSON.deserialize(pEntryStructure, TStringUtils.TPicklistEntry.class);
            //if valid for is empty, skip
            if (objDepPLE.validFor==null || objDepPLE.validFor==''){
                continue;
            }
            //iterate through the controlling values
            for(Integer pControllingIndex=0; pControllingIndex<ctrl_ple.size(); pControllingIndex++){    
                if (objBitSet.testBit(objDepPLE.validFor,pControllingIndex)){                    
                    //get the label
                    String pControllingLabel = ctrl_ple[pControllingIndex].getLabel();
                    objResults.get(pControllingLabel).add(objDepPLE.label);
                }
            }
        } 
        return objResults;
    }
I have one custom object, there are two fields, one multiselect picklist and second Text Field.
 
In multiselect picklist, there are 5 values : Mango, Apple, Orange, Guava and Grapes.
 
The requirement is that if I select Mango in picklist, then It needs to show Yellow Color fruit in the second text field.
If I select Apple in picklist , then it must show Red Color fruit in the second text field..
If I select Mango and Orange, then it should show Yellow Color Fruit, red Color Fruit in the second text field.
 
I need to write a trigger for this. Please help how to acheive the same.

Do I need to store these values, "Yellow Color Fruit", "red Color Fruit" somewhere in the same object....
Can Anyone explain the Power of External Id in salesforce?
HI,
My requirement is that I am using the wrapper class to display records of the Account along with checkbox(lets take 10 records), Now if I select any 3 checkboxes randomly, then the accounts record asociated with these checkbox reflected in other table. It is done and working as expected.
Now I have to add some more functionality in it. Example: If we select any of the two records and click on button(say update) then those 2 selected accounts open in pop-up window in Edit mode, and from there I can update these 2 account record(that we selected previously) and again in this pop-up window, there should be a button(lats say save), when we click on save button after updateing those 2 records, these account records must have been updated on its detail page.

Please suggest.
Hi All, I had a requirement in which there were two objects ABC and DEF with master detail relation, ABC as master. Both objects hav a checkbox field.Abc has Has_condition__c checkbox whereas Def has Active__c checkbox. NOw I had to write the trigger if anyone of the child record has checkbox=true, then master record must have checkbox true, otherwise false if there is no child record with checkbox=true. I wrote the trigger for this and that is working fine. NOw I have to wite test class for this using fatory data class. Please help me out in this..

trigger hasActiveCheckboxCondition on Def__c (After insert, After update)
{   
    if(Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate))
    {
            hasActiveCheckboxDef_Abc t = new hasActiveCheckboxDef_Abc();
            t.insertCondition(trigger.new);
            
    }  
}        
********************************
Apex class:

public class hasActiveCheckboxDef_Abc
{
    public void insertdef(List<def__c> tab1)
    {
        Set<Id> stemp = new Set<Id >();
    for(def__c c : tab1)
    {
        stemp.add(c.abc__c);
    }
    
    //Map<id,List<def__c>> mpDb=new Map<id,List<def__c>>();
    List<abc__c> tabToBeUpdated = new List<abc__c>();
    Map<id, abc__c> mapId = new Map<id,abc__c>();
       
    for(abc__c tab : [select id,Has_Condition__c,(Select id,name,abc__c,Active__c from abcs__r) from abc__c where id IN :stemp])
    {
          
        Boolean flag = false;           
        for(def__c cond : tab.defs__r)
        {
            if(cond.Active__c) {
                flag = true;
                tab.Has_Condition__c = true;
                break;
             }
            
            
        }
        if(flag == false)
        {
          tab.Has_Condition__c = false;  
        }
        mapId.put(tab.id,tab);
           
    }
    if(mapId != null)
    update mapId.values();
    }
}
 
Hi, There are 2 custom objects, Abc and Def. There is a field on Def object, named number. The values in Number field must be unique(Not duplicate) for each the Abc object. I wrote the below code and it is working fine, now I need to write the test class for this trigger. Below is the trigger code:

trigger duplicatenumberWithSameAbc on Def__c (before insert, before update)
{   
    if(Trigger.isBefore && Trigger.isInsert)
    {
            duplicatenumberWithSameAbc dup=new duplicatenumberWithSameAbc();
            dup.insertDef(trigger.new);
    }   
        
    if(Trigger.isBefore && Trigger.isUpdate)
    {
        for(Def__c tb: Trigger.new)
        {
            if(Trigger.oldMap.get(tb.id).number__c != Trigger.newMap.get(tb.Id).number__c)
            {
                duplicatenumberWithSameAbc dup=new duplicatenumberWithSameAbc();
                dup.insertDef(trigger.new);
            }
        }   
    }       
}


Apex class for this trigger:

public class duplicatenumberWithSameAbc 
{
    public void insertDef(List<Def__c> tab1)
    {
        set<Id> stTemp=new set<Id>();
    for(Def__c t:tab1)
    {
        stTemp.add(t.Abc__c);
    }

    Map<id,List<Def__c>> mpDb=new Map<id,List<Def__c>>();
   
    for(Def__c t : [select id,name,Abc__c,number__c from Def__c where Abc__c IN :stTemp])
    {
       
       List<Def__c> tab = new List<Def__c>();
       
       if(mpDb.get(t.Abc__c) != null)
       {
           tab = mpDb.get(t.Abc__c);
           tab.add(t);
           mpDb.put(t.Abc__c , tab);
           
       }
       else{
           List<Def__c> newList = new List<Def__c>();
           newList.add(t);
           mpDb.put(t.Abc__c , newList);
       }
       
    }
    
    for(Def__c t:tab1)
    {
        if(mpDb.containskey(t.Abc__c))
        {
            List<Def__c> tabs = mpDb.get(t.Abc__c);
            
            for(Def__c t1 : tabs)
            {
                if(t.number__c  == t1.number__c  )
                {
                    t.addError('You cannot add duplicate Value in Number Field');
                }
            }
            
        }
    }
}
}
 
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;}
    
}

}
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 =============');  
}
I have one custom object, there are two fields, one multiselect picklist and second Text Field.
 
In multiselect picklist, there are 5 values : Mango, Apple, Orange, Guava and Grapes.
 
The requirement is that if I select Mango in picklist, then It needs to show Yellow Color fruit in the second text field.
If I select Apple in picklist , then it must show Red Color fruit in the second text field..
If I select Mango and Orange, then it should show Yellow Color Fruit, red Color Fruit in the second text field.
 
I need to write a trigger for this. Please help how to acheive the same.

Do I need to store these values, "Yellow Color Fruit", "red Color Fruit" somewhere in the same object....
HI,
My requirement is that I am using the wrapper class to display records of the Account along with checkbox(lets take 10 records), Now if I select any 3 checkboxes randomly, then the accounts record asociated with these checkbox reflected in other table. It is done and working as expected.
Now I have to add some more functionality in it. Example: If we select any of the two records and click on button(say update) then those 2 selected accounts open in pop-up window in Edit mode, and from there I can update these 2 account record(that we selected previously) and again in this pop-up window, there should be a button(lats say save), when we click on save button after updateing those 2 records, these account records must have been updated on its detail page.

Please suggest.
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

  • January 18, 2012
  • Like
  • 0