-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
7Questions
-
10Replies
Test class for below HTTPRequest code
global static void postingFacebookPage()
{
Facebook__c objData = Facebook__c.getValues('Facebook Data');
String accessToken = objData.Access_Token__c;
String message =objData.Message__c;
String groupId =objData.Page_Id__c;
list<facebook_Post__c> lstData= [select id , status__c , name, Event_Date_time__c from facebook_post__c];
for(facebook_Post__c obj :lstData)
{
if(obj.status__c =='Approved')
{
String url ='https://graph.facebook.com/v15.0/'+groupId+'/feed';
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('POST');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
req.setBody('access_token='+accessToken+'&message='+message);
Http http = new Http();
HTTPResponse res = http.send(req);
if(res.getStatusCode()==200)
{
system.debug('Success Response :- '+res.getBody());
}
else {
system.debug('Failed Response :- '+res.getBody());
}
}
}
}
}
-
- Hitesh Algamwar
- January 13, 2023
- Like
- 0
- Continue reading or reply
Aura Component is not working in salesforce mobile app
I have one component in aura where when I tried to use it from mobile then all visual force pages and aura components is working but one functionality is not working which is word file i have added the screen shot there ..
below is the code :-
<div class="slds-p-horizontal_medium">
<div class="slds-grid slds_wrap slds-grid_pull-padded">
<aura:renderIf isTrue="{!v.objWrapper.userRole == 'Admin' || v.objWrapper.userRole == 'Owner'}">
<div class="slds-size_1-of-1 slds-medium-size_1-of-3 slds-col_padded">
<aura:renderIf isTrue="{!v.objWrapper.userRole == 'Admin'}">
<label class="slds-form-element__label" for="form-element-01">On Behalf Of</label>
<div class="slds-form-element slds-m-bottom_medium">
<force:inputField value="{!v.objPlatoon.User__c}" class="lookupHeight"/>
</div>
<aura:set attribute="else">
<lightning:select value="{!v.objPlatoon.User__c}" label="On Behalf Of">
<option value="">--None--</option>
<aura:iteration var="objUserMapping" items="{!v.objWrapper.lstUserWrapper}">
<option value="{!objUserMapping.userId}">{!objUserMapping.userName}</option>
</aura:iteration>
</lightning:select>
</aura:set>
</aura:renderIf>
</div>
</aura:renderIf>
In the on be half of search box I am not able to search any name or that search button is not working in the mobile platform.
Can you suggest if any code change is required or any other changes required.
-
- Hitesh Algamwar
- January 02, 2023
- Like
- 0
- Continue reading or reply
I have written test class for rest resource class of Post method where i am facing error.
@RestResource(URLMapping='/SendEmailForOTP/*')
global class WordpressIntegrationForEmail {
@HTTPPOST
global static FinalReturnWrapper SendEmailMsg(string email , string otp,string mob,boolean send_otp_if_exists)
{
FinalReturnWrapper returnResponse = new FinalReturnWrapper();
cls_data objData = new cls_data();
Integer otpSize = otp.length();
if(otpSize == 5)
{
list<contact> conList = [Select id,Do_Not_Mail__c,Email_Verification_Status__c, Email_Verification_Status_Date__c,LastName from contact where email =: email Limit 1];
if(conList.size() > 0 ) // If the email id is exist then ...
{
objData.contact_exists = true;
for(contact c : conList)
{
objData.contact_id =c.id;
objData.name=c.LastName;
if(c.Do_Not_Mail__c == false && c.Email_Verification_Status__c == null && c.Email_Verification_Status_Date__c == null)
{
OtpViaEmail.sendEmail(email,otp); //Sending Email
objData.otp_sms_sent = true;
objData.otp_email_sent = true;
}else
{
objData.bounced_email=true;
}
}
returnResponse.obj = objData;
System.debug('returnResponse:'+returnResponse);
return returnResponse;
}
else // If the email id not exist then...
{
if(send_otp_if_exists==false)
{
objData.contact_exists = false;
objData.contact_id =null;
OtpViaEmail.sendEmail(email,otp); //Sending Email
objData.otp_sms_sent = true;
objData.otp_email_sent = true;
returnResponse.obj =objData;
System.debug('returnResponse:'+returnResponse);
return returnResponse;
}
objData.contact_exists = null;
objData.contact_id =null;
objData.otp_sms_sent = false;
objData.otp_email_sent = false;
objData.name=null;
returnResponse.obj = objData;
System.debug('returnResponse:'+returnResponse);
return returnResponse;
}
}
objData.contact_exists = null;
objData.contact_id =null;
objData.otp_sms_sent = false;
objData.otp_email_sent = false;
objData.name=null;
returnResponse.obj = objData;
System.debug('returnResponse:'+returnResponse);
return returnResponse;
}
global class FinalReturnWrapper {
public cls_data obj ;
}
public class cls_data {
public boolean contact_exists;
public boolean otp_sms_sent;
public boolean otp_email_sent;
public string contact_id;
public boolean bounced_email;
public string name;
}
}
__________________________________
ANd here is the test class :-
@IsTest
public class WordpressIntegrationForEmailTest {
public static testMethod void testPostRestService(){
contact c = new contact ();
c.LastName = 'Pav';
c.Email = 'pavan@intuitiolabs.com';
c.Do_Not_Mail__c=false;
c.Email_Verification_Status__c=null;
c.Email_Verification_Status_Date__c=null;
insert c;
Test.startTest();
string email = 'pavan1@intuitiolabs.com';
string otp='11223';
string mob='987654321';
boolean send_otp_if_exists = false;
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/services/apexrest/WordpressIntegrationForEmail'; //Request URL
req.httpMethod = 'POST';//HTTP Request Type
req.requestBody = Blob.valueof('TestMsg');
req.addParameter(name, value)
RestContext.request = req;
RestContext.response= res;
WordpressIntegrationForEmail.SendEmailMsg(email,otp,mob,send_otp_if_exists);
Test.stopTest();
}
}
The error I am facing is below :- System.NullPointerException: Argument cannot be null.
-
- Hitesh Algamwar
- December 09, 2022
- Like
- 0
- Continue reading or reply
I have one rest resource class where in the post method i need to return response in json format.
Below is my program :-
@RestResource(URLMapping='/SendEmailForOTP/*')
global class WordpressIntegrationForEmail {
@HTTPPOST
global static FinalReturnWrapper SendEmailMsg(string email , string otp,string mob,boolean send_otp_if_exists)
{
FinalReturnWrapper returnResponse = new FinalReturnWrapper();
cls_data objData = new cls_data();
contact_data cobjData = new contact_data();
string failed = 'Email not exist'; //Need to create custom label
string success = 'Email successfully sent to email address' ;//Need to create custom label
list<contact> conList = [Select id,Do_Not_Mail__c,Email_Verification_Status__c, Email_Verification_Status_Date__c from contact where email =: email Limit 1];
if(conList.size() > 0 ) // If the email id is exist then ...
{
objData.contact_exists = true;
for(contact c : conList)
{
objData.contact_id =c.id;
cobjData.name=c.Name;
if(c.Do_Not_Mail__c == false && c.Email_Verification_Status__c == null && c.Email_Verification_Status_Date__c == null)
{
OtpViaEmail.sendEmail(email,otp);
objData.otp_sms_sent = true;
objData.otp_email_sent = true;
}
}
returnResponse.obj = objData;
returnResponse.cobj= cobjData ;
return returnResponse;
}
else // If the email id not exist then...
{
if(send_otp_if_exists ==false )
{
OtpViaEmail.sendEmail(email,otp);
objData.otp_sms_sent = true;
objData.otp_email_sent = true;
return returnResponse;
}
}
}
global class FinalReturnWrapper {
public cls_data obj ;
public contact_data cobj;
}
public class cls_data {
public boolean contact_exists;
public boolean otp_sms_sent;
public boolean otp_email_sent;
public string contact_id;
}
public class contact_data {
public string name;
}
}
See here i need to return FinalReturnWrapper but when i called this from postman so getting error as parser error.
So can someone please let me know how can I change the response to json file. Please guid me the code.
-
- Hitesh Algamwar
- December 07, 2022
- Like
- 0
- Continue reading or reply
how we can access the variable which is created in try block and we need to use than in the catch block.
class A{
try {
string a = abc ;
}catch(exception e)
{
// now here i want to create one object record
object b = new object ();
b.stringval = now here i need to update the value which in string a in try block.
}
}
-
- Hitesh Algamwar
- November 30, 2022
- Like
- 0
- Continue reading or reply
test class for integration class for below code
global class RestAccountIntegration {
@HTTPPOST
global static string CreateAcc(string email , string otp)
{
string failed = 'Email not exist'; //Need to create custom label
string success = 'Email successfully sent to email address' ;//Need to create custom label
list<contact> conList = [Select id,Do_Not_Mail__c,Email_Verification_Status__c, Email_Verification_Status_Date__c from contact where email =: email];
if(conList.size() > 0 && conList.size() < 1 ) // If the email id is exist then ...
{
for(contact c : conList)
{
if(c.Do_Not_Mail__c == false && c.Email_Verification_Status__c == null && c.Email_Verification_Status_Date__c == null)
{
// EmailSending.emailSend(email,otp);
EmailSending.sendEmail(email,otp);
system.debug('Email Id :- '+email);
system.debug('OTP :- '+ otp);
return success ;
}
}
return null ;
}
else // If the email id not exist then...
{
return failed ;
}
}
}
-
- Hitesh Algamwar
- November 29, 2022
- Like
- 0
- Continue reading or reply
test class for email class
public static void sendEmail(string emailId1 ,string otp1)
{
EmailTemplate emailTemplate = [select Id, Subject, HtmlValue, Body from EmailTemplate where name =:'AmazonOTP'];
String plainBody = emailTemplate.Body;
// integer ot = otp1;
plainBody = plainBody.replace('{OTPData}', otp1);
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = new String[] {emailId1 };
message.optOutPolicy = 'FILTER';
message.subject = emailTemplate.subject;
message.plainTextBody = plainBody;
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
if (results[0].success)
{
System.debug('The email was sent successfully.');
} else
{
System.debug('The email failed to send: ' + results[0].errors[0].message);
}
}
-
- Hitesh Algamwar
- November 28, 2022
- Like
- 0
- Continue reading or reply
Test class for below HTTPRequest code
global static void postingFacebookPage()
{
Facebook__c objData = Facebook__c.getValues('Facebook Data');
String accessToken = objData.Access_Token__c;
String message =objData.Message__c;
String groupId =objData.Page_Id__c;
list<facebook_Post__c> lstData= [select id , status__c , name, Event_Date_time__c from facebook_post__c];
for(facebook_Post__c obj :lstData)
{
if(obj.status__c =='Approved')
{
String url ='https://graph.facebook.com/v15.0/'+groupId+'/feed';
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('POST');
req.setHeader('Content-Type', 'application/x-www-form-urlencoded');
req.setBody('access_token='+accessToken+'&message='+message);
Http http = new Http();
HTTPResponse res = http.send(req);
if(res.getStatusCode()==200)
{
system.debug('Success Response :- '+res.getBody());
}
else {
system.debug('Failed Response :- '+res.getBody());
}
}
}
}
}
- Hitesh Algamwar
- January 13, 2023
- Like
- 0
- Continue reading or reply
Aura Component is not working in salesforce mobile app
I have one component in aura where when I tried to use it from mobile then all visual force pages and aura components is working but one functionality is not working which is word file i have added the screen shot there ..
below is the code :-
<div class="slds-p-horizontal_medium">
<div class="slds-grid slds_wrap slds-grid_pull-padded">
<aura:renderIf isTrue="{!v.objWrapper.userRole == 'Admin' || v.objWrapper.userRole == 'Owner'}">
<div class="slds-size_1-of-1 slds-medium-size_1-of-3 slds-col_padded">
<aura:renderIf isTrue="{!v.objWrapper.userRole == 'Admin'}">
<label class="slds-form-element__label" for="form-element-01">On Behalf Of</label>
<div class="slds-form-element slds-m-bottom_medium">
<force:inputField value="{!v.objPlatoon.User__c}" class="lookupHeight"/>
</div>
<aura:set attribute="else">
<lightning:select value="{!v.objPlatoon.User__c}" label="On Behalf Of">
<option value="">--None--</option>
<aura:iteration var="objUserMapping" items="{!v.objWrapper.lstUserWrapper}">
<option value="{!objUserMapping.userId}">{!objUserMapping.userName}</option>
</aura:iteration>
</lightning:select>
</aura:set>
</aura:renderIf>
</div>
</aura:renderIf>
In the on be half of search box I am not able to search any name or that search button is not working in the mobile platform.
Can you suggest if any code change is required or any other changes required.
- Hitesh Algamwar
- January 02, 2023
- Like
- 0
- Continue reading or reply
I have written test class for rest resource class of Post method where i am facing error.
@RestResource(URLMapping='/SendEmailForOTP/*')
global class WordpressIntegrationForEmail {
@HTTPPOST
global static FinalReturnWrapper SendEmailMsg(string email , string otp,string mob,boolean send_otp_if_exists)
{
FinalReturnWrapper returnResponse = new FinalReturnWrapper();
cls_data objData = new cls_data();
Integer otpSize = otp.length();
if(otpSize == 5)
{
list<contact> conList = [Select id,Do_Not_Mail__c,Email_Verification_Status__c, Email_Verification_Status_Date__c,LastName from contact where email =: email Limit 1];
if(conList.size() > 0 ) // If the email id is exist then ...
{
objData.contact_exists = true;
for(contact c : conList)
{
objData.contact_id =c.id;
objData.name=c.LastName;
if(c.Do_Not_Mail__c == false && c.Email_Verification_Status__c == null && c.Email_Verification_Status_Date__c == null)
{
OtpViaEmail.sendEmail(email,otp); //Sending Email
objData.otp_sms_sent = true;
objData.otp_email_sent = true;
}else
{
objData.bounced_email=true;
}
}
returnResponse.obj = objData;
System.debug('returnResponse:'+returnResponse);
return returnResponse;
}
else // If the email id not exist then...
{
if(send_otp_if_exists==false)
{
objData.contact_exists = false;
objData.contact_id =null;
OtpViaEmail.sendEmail(email,otp); //Sending Email
objData.otp_sms_sent = true;
objData.otp_email_sent = true;
returnResponse.obj =objData;
System.debug('returnResponse:'+returnResponse);
return returnResponse;
}
objData.contact_exists = null;
objData.contact_id =null;
objData.otp_sms_sent = false;
objData.otp_email_sent = false;
objData.name=null;
returnResponse.obj = objData;
System.debug('returnResponse:'+returnResponse);
return returnResponse;
}
}
objData.contact_exists = null;
objData.contact_id =null;
objData.otp_sms_sent = false;
objData.otp_email_sent = false;
objData.name=null;
returnResponse.obj = objData;
System.debug('returnResponse:'+returnResponse);
return returnResponse;
}
global class FinalReturnWrapper {
public cls_data obj ;
}
public class cls_data {
public boolean contact_exists;
public boolean otp_sms_sent;
public boolean otp_email_sent;
public string contact_id;
public boolean bounced_email;
public string name;
}
}
__________________________________
ANd here is the test class :-
@IsTest
public class WordpressIntegrationForEmailTest {
public static testMethod void testPostRestService(){
contact c = new contact ();
c.LastName = 'Pav';
c.Email = 'pavan@intuitiolabs.com';
c.Do_Not_Mail__c=false;
c.Email_Verification_Status__c=null;
c.Email_Verification_Status_Date__c=null;
insert c;
Test.startTest();
string email = 'pavan1@intuitiolabs.com';
string otp='11223';
string mob='987654321';
boolean send_otp_if_exists = false;
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/services/apexrest/WordpressIntegrationForEmail'; //Request URL
req.httpMethod = 'POST';//HTTP Request Type
req.requestBody = Blob.valueof('TestMsg');
req.addParameter(name, value)
RestContext.request = req;
RestContext.response= res;
WordpressIntegrationForEmail.SendEmailMsg(email,otp,mob,send_otp_if_exists);
Test.stopTest();
}
}
The error I am facing is below :- System.NullPointerException: Argument cannot be null.
- Hitesh Algamwar
- December 09, 2022
- Like
- 0
- Continue reading or reply
how we can access the variable which is created in try block and we need to use than in the catch block.
class A{
try {
string a = abc ;
}catch(exception e)
{
// now here i want to create one object record
object b = new object ();
b.stringval = now here i need to update the value which in string a in try block.
}
}
- Hitesh Algamwar
- November 30, 2022
- Like
- 0
- Continue reading or reply
test class for integration class for below code
global class RestAccountIntegration {
@HTTPPOST
global static string CreateAcc(string email , string otp)
{
string failed = 'Email not exist'; //Need to create custom label
string success = 'Email successfully sent to email address' ;//Need to create custom label
list<contact> conList = [Select id,Do_Not_Mail__c,Email_Verification_Status__c, Email_Verification_Status_Date__c from contact where email =: email];
if(conList.size() > 0 && conList.size() < 1 ) // If the email id is exist then ...
{
for(contact c : conList)
{
if(c.Do_Not_Mail__c == false && c.Email_Verification_Status__c == null && c.Email_Verification_Status_Date__c == null)
{
// EmailSending.emailSend(email,otp);
EmailSending.sendEmail(email,otp);
system.debug('Email Id :- '+email);
system.debug('OTP :- '+ otp);
return success ;
}
}
return null ;
}
else // If the email id not exist then...
{
return failed ;
}
}
}
- Hitesh Algamwar
- November 29, 2022
- Like
- 0
- Continue reading or reply
test class for email class
public static void sendEmail(string emailId1 ,string otp1)
{
EmailTemplate emailTemplate = [select Id, Subject, HtmlValue, Body from EmailTemplate where name =:'AmazonOTP'];
String plainBody = emailTemplate.Body;
// integer ot = otp1;
plainBody = plainBody.replace('{OTPData}', otp1);
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = new String[] {emailId1 };
message.optOutPolicy = 'FILTER';
message.subject = emailTemplate.subject;
message.plainTextBody = plainBody;
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
if (results[0].success)
{
System.debug('The email was sent successfully.');
} else
{
System.debug('The email failed to send: ' + results[0].errors[0].message);
}
}
- Hitesh Algamwar
- November 28, 2022
- Like
- 0
- Continue reading or reply