• Amol wagh
  • NEWBIE
  • 60 Points
  • Member since 2017
  • Sr. Salesforce Developer
  • Cloudwaale


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 10
    Replies
Hi All,

I have created a batch class to update the fields. 
i want the count of the field updated based on the condition.
Global class BatchUpdateTrainer implements Database.Batchable<Sobject> {
    
    
    Global database.QueryLocator start(database.BatchableContext BC){
        return Database.getQueryLocator('Select id, Background_Check_Done__c, LinkedIn_Profile__c, Verification_Status__c from Trainer_Master__c);
    }
    
    Global void execute(database.BatchableContext BC, List<Trainer_Master__c> Scope){
	list<Trainer_Master__c> lstTM = new list<Trainer_Master__c>();
        for (Trainer_Master__c trainer : Scope){
		system.debug('Background Check Done >>>> ' + trainer.Background_Check_Done__c);
		system.debug('LinkedIn Profile >>>> ' + trainer.LinkedIn_Profile__c);
            if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c == null){
                trainer.Verification_Status__c = 'Details Needed';
				system.debug('Verification_Status__c1 ' + trainer.Verification_Status__c);
            }
            else if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Non Verified';
				system.debug('Verification_Status__c2 ' + trainer.Verification_Status__c);
            }
            else if(trainer.Background_Check_Done__c =='Yes' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Verified';
				system.debug('Verification_Status__c3 ' + trainer.Verification_Status__c);
            }
			lstTM.add(trainer);
        }
        
        if(!lstTM.IsEmpty()){
		update lstTM;
		}
    }
    Global void finish(database.BatchableContext BC){
        
    }
}


TO Execute
BatchUpdateTrainer M = new BatchUpdateTrainer (); 
Database.executeBatch(M);

Above is my Batch class code and I want to count the number of records with the Verification_Status__c = 'Non Verified'.

Kindly help me in enhancing the code.

Thanks in advance.

Regards,
Sanjay Vinayak T

Hello, 
I want to upload about 5000 images to Salesforce via Apex. I used this code but I hit the callout limit (getContent method is treated as callout):

List<ContentVersion> contentVersionList = new List<ContentVersion>();

for(Object singleImage: images) {
String imageURL = singleImage.imageURL;
PageReference pageRef = new PageReference(imageURL);
ContentVersion cv = new ContentVersion();
cv.VersionData = pageRef.getContent();
cv.Title = 'Image Name';
cv.PathOnClient = imageURL ;
cv.Origin = 'H';//Chatter
contentVersionList.add(cv);
}
insert contentVersionList;

I tried to get a blob from imageURL and assign it to ContentVersion.VersionData , but it does not work for me.
I did not find any other solution how to insert images to Salesforce.
Any idea will be appreciated.
Thanks!

HI,
I am facing following issues while working on PDF can you please help me to resolve.

I am updating Approval Status field from field update(Approval process stage 1) once the record is Approved, And the same object I have one process builder who checks Status if Approved it will call apex class, from apex class I am generating pdf to send to email. But I am not getting updated values of status in the PDF.

I got that problem is because of the transaction is not committed and that's the reason I am getting old values of Status field.

But is there any workaround to resolve this issue.

Thanks.
Hi All,

I have created a batch class to update the fields. 
i want the count of the field updated based on the condition.
Global class BatchUpdateTrainer implements Database.Batchable<Sobject> {
    
    
    Global database.QueryLocator start(database.BatchableContext BC){
        return Database.getQueryLocator('Select id, Background_Check_Done__c, LinkedIn_Profile__c, Verification_Status__c from Trainer_Master__c);
    }
    
    Global void execute(database.BatchableContext BC, List<Trainer_Master__c> Scope){
	list<Trainer_Master__c> lstTM = new list<Trainer_Master__c>();
        for (Trainer_Master__c trainer : Scope){
		system.debug('Background Check Done >>>> ' + trainer.Background_Check_Done__c);
		system.debug('LinkedIn Profile >>>> ' + trainer.LinkedIn_Profile__c);
            if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c == null){
                trainer.Verification_Status__c = 'Details Needed';
				system.debug('Verification_Status__c1 ' + trainer.Verification_Status__c);
            }
            else if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Non Verified';
				system.debug('Verification_Status__c2 ' + trainer.Verification_Status__c);
            }
            else if(trainer.Background_Check_Done__c =='Yes' && trainer.LinkedIn_Profile__c!= null){
                trainer.Verification_Status__c = 'Verified';
				system.debug('Verification_Status__c3 ' + trainer.Verification_Status__c);
            }
			lstTM.add(trainer);
        }
        
        if(!lstTM.IsEmpty()){
		update lstTM;
		}
    }
    Global void finish(database.BatchableContext BC){
        
    }
}


TO Execute
BatchUpdateTrainer M = new BatchUpdateTrainer (); 
Database.executeBatch(M);

Above is my Batch class code and I want to count the number of records with the Verification_Status__c = 'Non Verified'.

Kindly help me in enhancing the code.

Thanks in advance.

Regards,
Sanjay Vinayak T
Hello,
Is there a way that we can rename the Related list like Files, Attachments with another name as per requirement.
If there's a way can anyone help me out in this one.
Really Appreciated. Thanks
 
I stepped into an ORG which had an trigger done on Opportunity, now producing the attached error.  Here is the Trigger.
------------------------

1
2
3
4
5
6
7
8
9
trigger OpportunityUpdate on Opportunity(after insert) 
{    
      list<opportunity> lstOpp = [Select id,account.type,Client_Type__c from opportunity];
      for (opportunity o : lstOpp)
      {
        o.Client_Type__c = o.account.type;
      }
      update lstOpp;
 }------------------------------
Apex Trigger Error?

Hello, 
I want to upload about 5000 images to Salesforce via Apex. I used this code but I hit the callout limit (getContent method is treated as callout):

List<ContentVersion> contentVersionList = new List<ContentVersion>();

for(Object singleImage: images) {
String imageURL = singleImage.imageURL;
PageReference pageRef = new PageReference(imageURL);
ContentVersion cv = new ContentVersion();
cv.VersionData = pageRef.getContent();
cv.Title = 'Image Name';
cv.PathOnClient = imageURL ;
cv.Origin = 'H';//Chatter
contentVersionList.add(cv);
}
insert contentVersionList;

I tried to get a blob from imageURL and assign it to ContentVersion.VersionData , but it does not work for me.
I did not find any other solution how to insert images to Salesforce.
Any idea will be appreciated.
Thanks!

I need to upload a csv file from Apex to a global bucket in s3 and keep the URL.

Below described is my approach for the same using AWS request signing process.
 
public static void uploadCSVFileToS3(String csvFile, String filename, String awsAccessKey, String awsSecretKey, String bucketname){
        try{
            String formattedDateString = Datetime.now().format('EEE, dd MMM yyyy HH:mm:ss');
            String requestType = 'PUT';
            String contentType = 'text/csv';
            String filePath = 'https://s3.amazonaws.com' + '/'+ bucketname + '/' + 'demo.csv';
            
            HttpRequest req = new HttpRequest();
            req.setMethod(requestType);
            req.setHeader('Host','https://s3.amazonaws.com');
            req.setEndpoint(filePath);
            req.setHeader('Content-Length', String.valueOf(csvFile.length()));
            req.setHeader('Content-Type', contentType);
            req.setHeader('Date', formattedDateString);
            req.setHeader('ACL', 'public-read-write');
            Blob CSV = Blob.valueof(csvFile);
            req.setBodyAsBlob(CSV);
            
            String auth = createAuthHeader(requestType, contentType, filename, formattedDateString, bucketname, awsAccessKey, awsSecretKey);
            
            Http http = new Http();
            
            HTTPResponse res = http.send(req);
            System.debug('RESPONSE STRING: ' + res.toString());
            System.debug('RESPONSE STATUS: ' + res.getStatus());
            System.debug('STATUS_CODE: ' + res.getStatusCode());
        } catch(System.CalloutException e) {
            system.debug('AWS Service Callout Exception: ' + e.getMessage());
            system.debug('AWS Service Callout Exception: ' + e.getCause());
            system.debug('Exception: ' + e.getStackTraceString());
        } catch(Exception e) {
            system.debug('Exception: ' + e.getMessage());
            system.debug('Exception: ' + e.getStackTraceString());
        }  
    }

    public static String createAuthHeader(String method, String contentType, String filename, String formattedDateString, String bucket, String key, String secret){
        string auth;
        
        String stringToSign = method+'\n'+bucket+'/'+filename+'\n';
        Blob mac = Crypto.generateMac('HmacSHA1', blob.valueof(stringToSign), blob.valueof(secret));
        String sig = EncodingUtil.base64Encode(mac);
        auth = 'AWS' + ' ' + key + ':' + sig;
        
        
        return auth;
    }

I have followed the link here (https://developer.salesforce.com/forums/?id=906F0000000BMDFIA4) for the approach used.

I am able to upload the file to same bucket from ruby or javascript using the aws sdk's, but it is giving me a response code of 400 (Bad Request).
I think this is a problem of the process of signing request.

It will be highly appreciated if someone can help me here.
HI,
I am facing following issues while working on PDF can you please help me to resolve.

I am updating Approval Status field from field update(Approval process stage 1) once the record is Approved, And the same object I have one process builder who checks Status if Approved it will call apex class, from apex class I am generating pdf to send to email. But I am not getting updated values of status in the PDF.

I got that problem is because of the transaction is not committed and that's the reason I am getting old values of Status field.

But is there any workaround to resolve this issue.

Thanks.
Hi to all,
I am trying to made my first integration flow with the Salesforce system just to get back the sessionId and the url where to submit my future request but I am facing this error:

com.sap.aii.mapping.lookup.LookupException: Exception during processing the payload. Error when calling an adapter by using the communication channel CC_SOAP_TEST_CONNECTION (Party: , Service: BS_VEEVA_DEV, Object ID: 6b493826b23a350a8862e992e805addf) XI AF API call failed. Module exception: 'com.sap.engine.interfaces.messaging.api.exception.MessagingException: iaik.security.ssl.SSLCertificateException: Peer certificate rejected by ChainVerifier'. Cause Exception: 'iaik.security.ssl.SSLCertificateException: Peer certificate rejected by ChainVerifier'. com.sap.aii.mapping.lookup.LookupException: Error when calling an adapter by using the communication channel CC_SOAP_TEST_CONNECTION (Party: , Service: BS_VEEVA_DEV, Object ID: 6b493826b23a350a8862e992e805addf) XI AF API call failed. Module exception: 'com.sap.engine.interfaces.messaging.api.exception.MessagingException: iaik.security.ssl.SSLCertificateException: Peer certificate rejected by ChainVerifier'. Cause Exception: 'iaik.security.ssl.SSLCertificateException: Peer certificate rejected by ChainVerifier'.

I was following this tutorial and it doesn't speaks about any certificate:

https://archive.sap.com/kmuuid2/50a76cfa-4966-2d10-aba7-da496d9b5bcf/Salesforce.com%20Integration%20Using%20SAP%20PI%3A%20A%20Case%20Study

Do I need to use a certificate provided me from Salesforce? Where I can download it? Then I have to use it in my chanel specifing it in this section?

SOAP channel
Thanks and regards,
Antonello

Hi

Can someone help me with sending an email via Apex class?

Scenario:
Recipient: sammypuppy09876@gmail.com
Sender: no_reply@sammypuppy.com
Subject: "User Login Failed" 
Text: "My Custom Text with one field from above user record" 

I did workflow as well to sent out the email, but now I wanted to do same customization via Apex code (learning curve).

Thanks

I'm experiencing a strange problem that cropped up yesterday morning.  I am suddenly getting a 'page not found' error when trying to access my community in my sandbox org.  I have not changed any of the custom URL settings in weeks and was accessing and using the sandbox community the very night before without issue.

Sandbox: https://sandbox-hirebotics.cs51.force.com/ (<-- page not found error)

Production:  https://robots.hirebotics.com (<-- works fine)

After three phone calls / go-to-meetings with salesforce support they can't figure out what's going on.  Their latest guess is that my product custom URL in sandbox (which is copied into sandbox upon a refresh, which I haven't done in a week) is set to "in development".  But they can't tell me why that's a problem now nor how to change that, assuming that's the problem.  They suggested I post here.  See below.
Custom URL in Sandbox

Now, I also tried spinning out another developers sandbox from my working production org and I'm seeing the exact same problem accessing the login page hosted from this new dev org.

Note that the error page below is being served from my org as the email us link connects to my email address.
Community Error Page

Also, both my sandbox and dev sandbox are hosted on CS51, if that's relevant.

Any idea what's going on?  
 

UPDATE:

 

I've gotten it working, made a button, it is attaching the file properly and everything.  But now, when I go to open the .xfdf file, it just downloads another copy, or get stuck in a loop without ever opening the form.  Now what!?

 

 

I am trying to create a button that will call a Visualforce page which calls the below code to make a .xfdf file.  For whatever reason, it won't let me make a button.  What am I doing wrong?  Any help is HUGELY appreciated!  Thanks in advance!

 





 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public with sharing class CreateIO {

    DateTime nowDT=System.now();
    String formatted=nowDT.format('dd_MM_yyyy');

private String getXmlString(JJSale__c a)
{

    
    String s = '<?xml version="1.0" encoding="UTF-8"?>' +
        '<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">' +
        '<f href="https://cs9.salesforce.com/resource/1304098375000/IO_JJ"/>' +
        '<fields>' +
        '<field name="Acct Rep"><value>' + a.CreatedBy.Name + '</value></field>' +
        '<field name="Ad Cost"><value>' + a.Ad_Price__c + '</value></field>' +
        '<field name="Address"><value>' + a.Organization__r.BillingStreet + '</value></field>' +
        '<field name="Advertiser"><value>' + a.Organization__c + '</value></field>' +
        '<field name="Bill to"><value>x</value></field>' +
        '<field name="City"><value>' + a.Organization__r.BillingCity + '</value></field>' +
        '<field name="Contact"><value>' + a.Contact__c + '</value></field>' +
        '<field name="Date"><value>' + formatted + '</value></field>' +
        '<field name="Email"><value>' + a.Contact__r.Email + '</value></field>' +
        '<field name="Fax"><value>' + a.Contact__r.Fax + '</value></field>' +
        '<field name="INSERTION DATES AND NOTES 1"><value>' + a.Journal_Issue__c + '</value></field>' +
        '<field name="INSERTION DATES AND NOTES 2"><value>' +
            a.Page_Requested__c + ',' + a.Insertion_Notes__c + '</value></field>' +
        '<field name="Phone"><value>' + a.Contact__r.Phone + '</value></field>' +
        '<field name="State"><value>' + a.Organization__r.BillingState + '</value></field>' +
        '<field name="Todays Date"><value>' + formatted + '</value></field>' +
        '<field name="Zip"><value>' + a.Organization__r.BillingPostalCode + '</value></field>' +
        '</fields><ids original="CB86FA72BFC7A2744D5052A67D1686EE" modified="C0A949601A5BB74AB94C1DAA08D65D2F"/>' +
        '</xfdf>';
        
    return s;
}

public PageReference XFDFInit()
{
    JJSale__c a = [SELECT Id, CreatedBy.Name, Ad_Price__c, Organization__r.BillingStreet, Organization__c,
                         Organization__r.BillingCity, Contact__c, Contact__r.Email, Contact__r.Fax,
                         Journal_Issue__c, Page_Requested__c, Insertion_Notes__c, Contact__r.Phone,
                         Organization__r.BillingState, Organization__r.BillingPostalCode
                         FROM JJSale__c
                         WHERE id = :ApexPages.currentPage().getParameters().get('id')];
    String xmlContent = getXmlString(a);
    
    Attachment attachment = new Attachment();
        attachment.Body = Blob.valueof(xmlContent);
        attachment.Name = a.Organization__c + formatted + '.XFDF';
        attachment.ParentId = a.Id;
        insert attachment;
    
    PageReference salePage = new PageReference('/' + a.id);
    salePage.setRedirect(true);
    return salePage;
}

}
<apex:page showHeader="true"
    controller="CreateIO"
    action="{!XFDFInit}">
</apex:page>