• eticam joe
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies

Hi, 

I am beginner in apex, and I am just wondering if it's possible to write a logic that will check if an account is a member( member = account which has an active contract)and display that as a green box above the name of the account. I think the second part it is possible but I am not sure if the first one.

I also would like to calculate how many members (accounts with active contracts) we have in the system. I created a report but we have some Accounts with more than one active contract and the system treats that as more than one member eg, Company XYZ has three active contracts for the system that are 3 members, I want the system to calculate that as 1 member (unique calculation). 

Do you think I can achieve that with apex?

This is my LWC 
<template>
     <lightning-card title="" icon-name="custom:custom19">
        <lightning-file-upload
            label="Attach receipt"
            name="fileUploader"
            accept={acceptedFormats}
            record-id={recordId}
            onuploadfinished={handleUploadFinished}
            multiple>
    </lightning-file-upload>
    </lightning-card>
    <lightning-record-edit-form object-api-name="DMS__c" onsuccess={handleSuccess} onsubmit ={handleSubmit} >
        <div class="slds-grid">
            <div class="slds-col slds-size_1-of-2">
        <lightning-input-field field-name='Name'></lightning-input-field>
        <lightning-input-field field-name='Version__c'></lightning-input-field>
        <lightning-input-field field-name='Key_Words__c'></lightning-input-field>
        <lightning-input-field field-name='Doc_type__c'></lightning-input-field>
        <lightning-input-field field-name='Description__c'></lightning-input-field>
        </div>
        <div class="slds-col slds-size_1-of-2">
            <lightning-input-field field-name='Contract_LOB__c'></lightning-input-field>
            <lightning-input-field field-name='Active_Contract__c'></lightning-input-field>
            <lightning-input-field field-name='Competitor_Contract__c'></lightning-input-field>
            <lightning-input-field field-name='Folder__c'></lightning-input-field>
         </div>
        </div>
        <div class="slds-clearfix">
            <div class="slds-align_absolute-center">
        <lightning-button class="slds-m-top_small" type="submit" label="Upload"  onclick={showSuccessToast}></lightning-button>
        <lightning-button class="slds-m-top_small" label="Cancel" onclick={allowReset}></lightning-button>
        </div>
    </div>
    </lightning-record-edit-form>
</template>

Thefollowing is my .js file
import { LightningElement, api } from 'lwc';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import POST from '@salesforce/apex/docUpload.POST';  
export default class Final extends LightningElement {
    @api recordId;
    get acceptedFormats() {
        return ['.pdf', '.png','.jpg','.jpeg'];
    }
    handleUploadFinished(event) {
        // Get the list of uploaded files
        const uploadedFiles = event.detail.files;
        let uploadedFileNames = '';
        for(let i = 0; i < uploadedFiles.length; i++) {
            uploadedFileNames += uploadedFiles[i].name + ', ';
        }
          var Name = component.get("v.Name");
            var Doc_type__c = component.get("v.Doc_type__c");
            var Active_Contract__c = component.get("v.Active_Contract__c");
            var Competitor_Contract__c = component.get("v.Competitor_Contract__c");
            var Version__c = component.get("v.Version__c");
            var Key_Words__c = component.get("v.Key_Words__c");
            var Folder__c = component.get("v.Folder__c");
            var action = component.get("c.POST");
            action.setParams({ file : uploadedFiles, Name : Name, Doc_type__c : Doc_type__c, Active_Contract__c : Active_Contract__c, Competitor_Contract__c : Competitor_Contract__c, Version__c : Version__c, Key_Words__c : Key_Words__c, Folder__c : Folder__c });
            action.setCallback(this, function(response) {
                var returnValue = response.getReturnValue();
                console.log('returnValue===>'+returnValue);
            
                component.set("v.message", returnValue);
            });
            $A.enqueueAction(action);
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: uploadedFiles.length + ' Files uploaded Successfully: ' + uploadedFileNames,
                    variant: 'success',
                }),
            );
    }
       
    handleSuccess(event) {
        console.log('onsuccess event ',event.detail.id)
        
    }
    handleSubmit(event) {
        console.log('onsubmit event Newcomp'+ event.detail.fields);
       
    }
    showSuccessToast() {
        const evt = new ShowToastEvent({
            title: 'Toast Success',
            message: 'Opearion sucessful',
            variant: 'success',
            mode: 'dismissable'
        });
        this.dispatchEvent(evt);
    }
    allowReset(event) {
        const inputFields = this.template.querySelectorAll(
            'lightning-input-field'
        );
        if (inputFields) {
            inputFields.forEach(field => {
                field.reset();
            });
        }
    }
}
my apex post callout is given
public with sharing class docUpload {
    
    public String resBody {get; set;}          
        @AuraEnabled
        public static String POST(Blob file, String Name, String Doc_type__c, String Active_Contract__c, String Competitor_Contract__c, String Version__c, String Key_Words__c, String Folder__c) {
            
            Http h = new Http();
    //    String fileName = 'leads.csv';
            String url = 'https://csv-file-upload.herokuapp.com/leads/' + recordId;
            String separationString = 'da5cbc76-39ba-4f80-8b81-090b82e90cf0';
            String str = file.toString();
       //     String csvBody = EncodingUtil.base64Encode(csvBlob);
            // decode 
            Blob decodedBlob = EncodingUtil.base64Decode(str);
            system.debug('string ==>'+decodedBlob);
            // convert to string
            String result = decodedBlob.toString();
            
            // assemble the body payload
            String header = '--' + separationString + '\nContent-Disposition: form-data; name="file"; filename="' + fileName + '"\nContent-Type: application/octet-stream\n\n';
            //String body = EncodingUtil.base64Encode(file) + '\n';
            String body = result + '\n';
            String footer = '--' + separationString + '--';
            String bodyPayload = header + body + footer;
            system.debug('PAYLOAD: ' + bodyPayload);
    
            HttpRequest req = new HttpRequest();
            req.setHeader('Content-Type', 'multipart/form-data; boundary=' + separationString);
            
            req.setEndpoint(url);
            req.setMethod('POST');
            req.setBody(bodyPayload);
            system.debug('REQUEST: ' + req);
    
            // Send the request, and return a response
            HttpResponse res = h.send(req);
            System.debug(res.getBody());
            return res.getBody();
        }
}

 
Hello everyone,

I have an Account table with a custom field with data type 'Picklist'.
What I want to do is, for each record in the account table I want the picklist value and also the label for that value.

Due to some limitations I can't execute the simple query ...
SELECT Custom_Field_1__c, toLabel(Custom_Field_1__c) FROM Account"

When I execute that query I get the error ...
INVALID_FIELD:
SELECT UCB_Specialty_1__c, toLabel(UCB_Specialty_1__c) FROM Account
^
ERROR at Row:1:Column:36
duplicate field selected: UCB_Specialty_1__c ].
caused by: AxisFault

If anyone knows a work around or a solution, I'd appreciate to hear about it.
Thank you.

Greetings,

Hamid