• Akshay Alandkar 8
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 0
    Replies
public with sharing class BulkRequestDetailTriggerHelper extends GNT.TriggerHelper{
public static boolean skipTrigger = false;
Set<Id> bulkReqId = new Set<Id>();
Set<Id> uniqueGrantIdsSet = new Set<Id>();
Set<Id> grantId = new Set<Id>();
Set<Id> currentRecordId = new Set<Id>();
List<LSC_Bulk_Request__c> bulkRequestListToUpdate = new List<LSC_Bulk_Request__c>();
List<LSC_Bulk_Request_Detail__c> bulkReqDetList = new List<LSC_Bulk_Request_Detail__c>();
Set<String> selectedTypes;

public BulkRequestDetailTriggerHelper(){
}

public override void processBeforeInsert(){
if (skipTrigger==false) {
// checkDuplicates((List<LSC_Bulk_Request_Detail__c>) Trigger.New);
}
}
public override void processAfterInsert(){
if (skipTrigger==false) {
updateBulkRequest((List<LSC_Bulk_Request_Detail__c>) Trigger.New);
UpdateNoofAmendmentRequests(Trigger.New);
UpdateNoOfProgressReport(Trigger.New);
UpdateNoofPaymentRequests(Trigger.New);
}
}
public override void processBeforeDelete(){
if (skipTrigger==false) {
//updtGrntCountBR((List<LSC_Bulk_Request_Detail__c>) Trigger.Old);
System.debug('we are Trigger.Old==>>'+Trigger.Old);
}
}

private void updateBulkRequest(List<LSC_Bulk_Request_Detail__c> bulkReqDetailList) {
for(LSC_Bulk_Request_Detail__c bkDet : bulkReqDetailList) {
bulkReqId.add(bkDet.Bulk_Request__c);
}
System.debug('bulkReqId==>>'+bulkReqId);
List<LSC_Bulk_Request_Detail__c> allBulkDetailRecords = [Select id, Name,Bulk_Request__c,GrantId__c from LSC_Bulk_Request_Detail__c
where Bulk_Request__c = :bulkReqId];

if(allBulkDetailRecords.size() > 0){
for(LSC_Bulk_Request_Detail__c det: allBulkDetailRecords){
uniqueGrantIdsSet.add(det.GrantId__c);
System.debug('uniqueGrantIdsSet==>>'+uniqueGrantIdsSet);
}
}

List<LSC_Bulk_Request__c> bulkRecord = [Select Id,Status__c from LSC_Bulk_Request__c where Id = :bulkReqId];
system.debug('bulkRecord==>>'+bulkRecord);
if(bulkRecord.size() > 0){
for(LSC_Bulk_Request__c bk : bulkRecord){
//bk.TotalGrantsIncluded__c = uniqueGrantIdsSet.size();
bk.Status__c = 'Created';
// bk.Id = bulkRecord.Id;
bulkRequestListToUpdate.add(bk);
system.debug('coming here==>>'+bulkRequestListToUpdate);
}
}
if(bulkRequestListToUpdate.size() >0){
system.debug('bulkRequestListToUpdate==>>'+bulkRequestListToUpdate.size());
BulkRequestTriggerHelper.skipTrigger = true;
update bulkRequestListToUpdate;
BulkRequestTriggerHelper.skipTrigger = false;
}
}
//check if grant already selected
/* private void checkDuplicates(List<LSC_Bulk_Request_Detail__c> bulkReqDetailList) {
System.debug('bulkReqDetailList==>>'+bulkReqDetailList);
List<LSC_Bulk_Request_Detail__c> existing = [SELECT Bulk_Request__c,GrantId__c,Id,Name FROM LSC_Bulk_Request_Detail__c];
System.debug('existing ==>>'+existing);
for(LSC_Bulk_Request_Detail__c brdn : bulkReqDetailList){
for(LSC_Bulk_Request_Detail__c brde : existing){
if(brde.GrantId__c == brdn.GrantId__c){
System.debug('brde.GrantId__c==>>'+brde.GrantId__c);
System.debug('brdn.GrantId__c==>>'+brdn.GrantId__c);
brdn.addError('Duplicate grants cannot be added');
//ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING,GNT.ErrorMessageHelper.fetchMessage('P07-GRNTR-34616')));
}
}
}
}*/

//Added by Parul on 12/10/2022
private void UpdateNoofAmendmentRequests(List<LSC_Bulk_Request_Detail__c> lstBulkRec){
Set<Id> grntIds = new Set<Id>();
List<Grant__c> zeroLst = new List<Grant__c>();
for (LSC_Bulk_Request_Detail__c bdr: lstBulkRec){
if (bdr.GrantId__c != null){
Grant__c grnt = new Grant__c();
grnt.id = bdr.GrantId__c;
grnt.NoOfAmendmentReq__c = 0;
zeroLst.add(grnt);
grntIds.add(bdr.GrantId__c);
}
}
System.debug('grntIds==>>'+grntIds);
if(grntIds.size() == 0){
return;
}
List<Grant__c> grntsFieldsToup = new List<Grant__c>();
for(AggregateResult ar : [SELECT Grant__c,COUNT(Id) pendngAmd FROM AmendmentRequest__c WHERE Grant__c =:grntIds AND
Status__c NOT IN ('Approved', 'Rejected','Force Closed')group by Grant__c]){
System.debug('ar ==>>'+ar);
Grant__c gnt = new Grant__c();
gnt.Id = (Id)ar.get('Grant__c');
gnt.NoOfAmendmentReq__c = (Integer)ar.get('pendngAmd');
grntsFieldsToUp.add(gnt);
}
// GrantTriggerHelper.skipTrigger = true;
update grntsFieldsToUp;
// GrantTriggerHelper.skipTrigger = false;
//update count zero if nothing pending
if(grntsFieldsToUp.size() == 0){
update zeroLst;
}
}
private void UpdateNoofPaymentRequests(List<LSC_Bulk_Request_Detail__c> lstBulkRec){
Set<Id> grntIds = new Set<Id>();
List<Grant__c> zeroLst = new List<Grant__c>();
for (LSC_Bulk_Request_Detail__c bdr : lstBulkRec){
if (bdr.GrantId__c != null){
Grant__c grnt = new Grant__c();
grnt.id = bdr.GrantId__c;
grnt.NoOfPaymentReq__c = 0;
zeroLst.add(grnt);
grntIds.add(bdr.GrantId__c);
}
}
System.debug('grntIds==>>'+grntIds);
if(grntIds.size() == 0){
return;
}
List<Grant__c> grntsFieldsToup = new List<Grant__c>();
for(AggregateResult ar : [SELECT Grant__c,COUNT(Id) pymntCount FROM PaymentRequest__c WHERE Grant__c =:grntIds AND
Status__c NOT IN :new List<String>{PaymentRequestStaticUtility.PAYMENT_REQUEST_STATUS_PAID,PaymentRequestStaticUtility.PAYMENT_REQUEST_STATUS_REJECTED, PaymentRequestStaticUtility.PAYMENT_REQUEST_STATUS_APPROVED, PaymentRequestStaticUtility.PAYMENT_REQUEST_STATUS_FORCECLOSED} group by Grant__c]){
System.debug('ar ==>>'+ar);
Grant__c gnt = new Grant__c();
gnt.Id = (Id)ar.get('Grant__c');
gnt.NoOfPaymentReq__c = (Integer)ar.get('pymntCount');
grntsFieldsToUp.add(gnt);
}
// GrantTriggerHelper.skipTrigger = true;
update grntsFieldsToUp;
// GrantTriggerHelper.skipTrigger = false;
//update count zero if nothing pending
if(grntsFieldsToUp.size() == 0){
update zeroLst;
}
}

private void UpdateNoOfProgressReport(List<LSC_Bulk_Request_Detail__c> lstBulkRec){
Set<Id> grntIds = new Set<Id>();
List<Grant__c> zeroLst = new List<Grant__c>();
for (LSC_Bulk_Request_Detail__c bdr : lstBulkRec){
if (bdr.GrantId__c != null){
Grant__c grnt = new Grant__c();
grnt.id = bdr.GrantId__c;
grnt.NoOfProgRep__c = 0;
zeroLst.add(grnt);
grntIds.add(bdr.GrantId__c);
}
}
System.debug('grntIds==>>'+grntIds);
if(grntIds.size() == 0){
return;
}
List<Grant__c> grntsFieldsToup = new List<Grant__c>();
for(AggregateResult ar : [SELECT Grant__c,COUNT(Id) prgRCount FROM ProgressReports__c WHERE Grant__c =:grntIds AND
Status__c NOT IN ('Approved','Rejected','Force Closed') group by Grant__c]){
System.debug('ar ==>>'+ar);
Grant__c gnt = new Grant__c();
gnt.Id = (Id)ar.get('Grant__c');
gnt.NoOfProgRep__c = (Integer)ar.get('prgRCount');
grntsFieldsToUp.add(gnt);
}
// GrantTriggerHelper.skipTrigger = true;
update grntsFieldsToUp;
//GrantTriggerHelper.skipTrigger = false;
//update count zero if nothing pending
if(grntsFieldsToUp.size() == 0){
update zeroLst;
}
}
}

i have created visualforce page and its class 

<apex:page showHeader="false" standardStylesheets="false" sidebar="false" controller="Feedbackpagehandler"> 
    <style>
        .field {
            box-sizing: border-box;
        }
        .field > div {
            box-sizing: border-box;
            display: inline-block;
            padding-top: 5px;
            padding-bottom: 5px;
        }
        .field > div:first-child {
            width: 20%;
            float: left;
            padding-right: 10px;
            vertical-align: top;
            text-align: right;
        }
        .field > div:first-child + div {
            width: 50%;
        }
        .required {
            color: red;
        }
    </style>
    <GNT:ExternalLibrary />   
    <apex:composition template="GNT__ModalTemplate">
        <apex:define name="ModalContent"> 
        
            <apex:form > 
                <GNT:PageMessages id="editPageErrors"/>
        <!--        <apex:actionFunction name="submitCase" action="{!submitCase}" status="requestIcon">
                    <apex:param name="requestString" value="" assignTo="{!requestString}"/>
                </apex:actionFunction>
           -->     
                    <apex:define name="Header">
                        <h2>Create Feedback</h2>
                    </apex:define>
                    <apex:define name="Inputs">
                   
            <!--            <input value="Submit" type="button" class="customBtn" id="submitcase"/>   -->
                     <button style="float:Right;" type="cancel" class="customBtn" onclick="javascript:window.location='https://lsc-grantease--qa--c.sandbox.vf.force.com/apex/PhaseView?t=GrantorHome';">Cancel</button>  
                     <apex:commandbutton action="{!SaveMethod}" style="float:Right;" value="Submit"   onclick="javascript:window.location='https://lsc-grantease--qa--c.sandbox.vf.force.com/apex/PhaseView?t=GrantorHome';"/>  
                    
                   
                    </apex:define>
                    <apex:define name="Body">
                        
                        <div id="issueType" class="field">
                            <div>
                                <strong>Issue Type<span class="required">*</span> </strong>
                            </div>
                            <div>
                                <apex:inputField value="{!LSCFeedback.Type__c}" required="true"/>
                            </div>
                        </div>
                        <div id="subject" class="field">
                            <div>
                                <strong>Subject<span class="required">*</span> </strong>
                            </div>
                            <div>
                                <apex:inputText value="{!LSCFeedback.Subject__c}" size="80" required="true"/>
                            </div>
                        </div>
                        <div id="issueDescription" class="field">
                            <div>
                                <strong>Description<span class="required">*</span> </strong>
                            </div>
                            <div>
                                <apex:inputTextarea value="{!LSCFeedback.Description__c}" richText="true" required="true"/>
                            </div>
                        </div>
                        <div id="issueLocation" class="field">
                            <div>
                                <strong>URL </strong>
                            </div>
                            <div>
                                <apex:inputText value="{!LSCFeedback.URL__c}" size="80" required="false"/>
                            </div>
                        </div>
                        <div id="attachments" class="field">
                            <div>
                                <strong>Add Attachment </strong>
                            </div>
                            <div>
                                <apex:inputFile id="Attachment" filename="{!attachmentName}" value="{!attachment}" accept="image/*"/>
                            </div>
                        </div>
                        
                       

   </apex:define>
   </apex:form>
   </apex:define>
   
   </apex:composition>
</apex:page>



and its class 

 

public without sharing class Feedbackpagehandler{

public PageReference cancel() {
return null;
}

public LSCFeedback__c LSCFeedback{get;set;}
public Boolean isInternal {get;set;}
public Blob attachment {get;set;}
public String attachmentName {get;set;}
public String returnURL {get;set;}
private User user;

public Feedbackpagehandler() {
LSCFeedback = new LSCFeedback__c();
user = [SELECT id, Email, ProfileId, UserType FROM User WHERE id =: UserInfo.getUserId()];

isInternal = isInternalUser();
returnURL = setReturnURL();

}



//Save Method
public PageReference SaveMethod(){
Insert LSCFeedback;


Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

String[] toAddresses = new String[] { 'abcd@yopmail.com' };




mail.setToAddresses(toAddresses);
mail.setSubject('New Feedback Form created');
mail.setBccSender(false);
mail.sethtmlBody('Issue Type: ' + LSCFeedback.Type__c +
'<br/><br/> Subject: '+LSCFeedback.Subject__C +
'<br/><br/> Description: '+LSCFeedback.Description__c +
'<br/><br/> URL: '+LSCFeedback.URL__c
);


// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });




PageReference pageRef = new PageReference('/apex/PhaseView?t=GrantorHome');
pageRef.setRedirect(true);
return pageRef;



}






private Boolean isInternalUser() {
Boolean isInternal = false;
if(user.UserType.contains('Standard')) {
isInternal = true;
}
return isInternal;
}

private String setReturnURL() {
String returnURL = '/apex/PhaseView?t=GrantorHome';
/* if(isInternal) {
returnURL += 'GrantorHome';
} else {
returnURL += 'RecipientHome';
}
*/
return returnURL;
}
}


But when i submit this form and open email 
User-added imagedidnt get attachment ,can you please tell me how to get attachment to mail 

Hi all , want to create vf page like below 
User-added image

 

 

For this i have written vf page code as
<apex:page id="FeedbackPage" controller="FeedbackClass"   standardStylesheets="false"  showHeader="false" sidebar="false">
    
    <c:ExternalLibrary />
    
    <apex:composition template="GNT__ModalTemplate">
        <apex:define name="ModalContent">
    
    
     <apex:form >
        <apex:pageBlock title="New feedback">
           
            <apex:pageBlockSection >
              
              
        &nbsp;&nbsp;&nbsp;     Type<apex:inputText value="{!Type}"/>   
        &nbsp;&nbsp;&nbsp;     Subject<apex:inputText value="{!Subject}"/>
        &nbsp;&nbsp;&nbsp;     Description<apex:inputTextArea richText="true" value="{!Description}"/>
        &nbsp;&nbsp;&nbsp;     URL<apex:inputText value="{!URL}"/>
              
              
               
            
                 
                <apex:commandButton value="Submit" onclick="alrt()" action="{!save}"/>
            </apex:pageBlockSection>
            
           
        
        
        </apex:pageBlock>
    </apex:form>
    
        </apex:define>
    </apex:composition> 
</apex:page>

 

and Controller is 

public without sharing class FeedbackClass{


public String Description{get;set;}
public String Subject{get;set;}
public String Type{get;set;}
public String URL{get;set;}
public PageReference save() {
Feedback__c ac = new Feedback__c();
ac.Description__c= Description;
ac.Subject__c= Subject;
ac.Type__c= Type;
ac.URL__c= URL;
insert ac;
this.Description = null;
this.Subject= null;
this.Type = null;
return null;
}

}

 

and got result 

User-added image so how to add Picklist field and attachment tab to this vf page please help 

public class populateDefaultReportDetailsForm implements Queueable, Database.AllowsCallouts { 
    
      public static final Map<String, Set<String>> GARDetailSectionsByFormName = new Map<String, Set<String>>{
            'GAR_GranteeLevelForm2021' => new Set<String>{
            },
            'GAR_SelfInspectionForm2021' => new Set<String>{
                    'Self-Inspection'
            },
            'GAR_OngoingComplianceReviewForm2021' => new Set<String>{
                    'Ongoing Compliance Review /Quality Control'
            },
            'LSC_GAR_ServiceAreaForm2021' => new Set<String>{
                    '1. Personnel Expenses',
                    '2. Non-Personnel Expenses',
                    '1. LSC Revenue',
                    '2. Non-LSC Revenue',
                    '3. Client Service Income',
                    'Staff Open Cases',
                    'PAI Open Cases',
                    'Gender',
                    'Veteran Status',
                    'Ethnicity',
                    'Language',
                    'Pro Bono',
                    'Compensated',
                    'Number of Group Clients'
            }
    };

      List<ProgressReportForm__c> progressReportForms = new List<ProgressReportForm__c> (); 
      public populateDefaultReportDetailsForm(List<ProgressReportForm__c> progressReportForms ) { 
        this.progressReportForms.addAll(progressReportForms);         
      } 

     public void execute(QueueableContext context) { 
        Set<String> sectionTypeSet = new Set<String>();
        for (Set<String> subset : GARDetailSectionsByFormName.values()) {
            sectionTypeSet.addAll(subset);
        }
        Map<String, List<LSC_ProgressReportDetail__c>> masterProgressReportsBySection = new Map<String, List<LSC_ProgressReportDetail__c>>();
        List<LSC_ProgressReportDetail__c> masterProgressReportDetails = LSC_GARProgressReportHelper.getMasterTemplateRecords(sectionTypeSet);
        for (LSC_ProgressReportDetail__c progressReportDetail : masterProgressReportDetails) {
            if (!masterProgressReportsBySection.containsKey(progressReportDetail.LSC_GAR_SectionType__c)) {
                masterProgressReportsBySection.put(progressReportDetail.LSC_GAR_SectionType__c, new List<LSC_ProgressReportDetail__c>());
            }
            masterProgressReportsBySection.get(progressReportDetail.LSC_GAR_SectionType__c).add(progressReportDetail);
        }
        List<LSC_ProgressReportDetail__c> relatedProgressReportDetails = new List<LSC_ProgressReportDetail__c>();
        for (ProgressReportForm__c progressReportForm : [SELECT Id,Name,ProgressReport__c,ConfigForm__c,ConfigForm__r.Name FROM ProgressReportForm__c WHERE Id IN:this.progressReportForms]) {
            if (!GARDetailSectionsByFormName.isEmpty() && GARDetailSectionsByFormName.get(progressReportForm.ConfigForm__r.Name) != null) {
                Set<String> sectionTypes = GARDetailSectionsByFormName.get(progressReportForm.ConfigForm__r.Name);
                if (!sectionTypes.isEmpty()) {
                    for (String sectionName : sectionTypes) {
                        if (!masterProgressReportsBySection.isEmpty() && masterProgressReportsBySection.get(sectionName) != null) {
                            List<LSC_ProgressReportDetail__c> masterProgressDetailList = masterProgressReportsBySection.get(sectionName);
                            for (LSC_ProgressReportDetail__c progressReportDetail : masterProgressDetailList) {
                                LSC_ProgressReportDetail__c prDetail = progressReportDetail.clone(false);
                                prDetail.Copied_From__c = progressReportDetail.Id;
                                prDetail.Is_Master__c = false;
                                prDetail.Progress_Report_Form__c = progressReportForm.Id;
                                relatedProgressReportDetails.add(prDetail);
                            }
                        }
                    }
                }
            }
        }
        if (!relatedProgressReportDetails.isEmpty()) {
            insert relatedProgressReportDetails;
        }
     }

}