-
ChatterFeed
-
1Best Answers
-
0Likes Received
-
0Likes Given
-
2Questions
-
13Replies
Prevent opening a new record on a custom object depending on "status" field
I have a custom object (object1) that has multiple objects from another custom object (object2). There are three statuses for records object2: In Progress, Cancelled, and Completed. As long as there is an In Progress or Cancelled record, I want to avoid the creation of a new record related to a single object1 record. The idea is for there to only be one step/process "In Progress" at any given time until the object1 record is "completed".
- Carrlos Boyd
- March 14, 2018
- Like
- 0
- Continue reading or reply
Message body missing in multipart/form-data while attaching image file
Hi All,
I want to add attachment with image and send to the given number via API.
I am able to send Message with x-www-form-urlencoded but when i am trying to send image with multipart/form-data then i am getting forbidden status in response with 403 status code. In response body "Message body missing".
Code :
public static void uploadFileattach(Blob filebody, String filename, String reqEndPoint){
String smessageFrom = '+19999999999';
String smessageTo = '+19999999999';
String messageBody = 'Hi Test message !';
system.debug('----- Values in uploadFileattach filebody='+filebody+'filename='+filename+'reqEndPoint='+reqEndPoint);
String boundary = '----SomethingsBoundary7MA4YWxkTrZu0gW';
String finalbody = boundary+'\nContent-Disposition: form-data; name="PhoneNumber"\n\n'+smessageFrom+'\n'
+boundary+'\nContent-Disposition: form-data; name="To"\n\n'+smessageTo+'\n'
+boundary+'\nContent-Disposition: form-data; name="File"; filename="'+filename+'";'
+'\nContent-Type: image/png\n\n'+boundary;
String bodyEncoded = EncodingUtil.base64Encode(filebody);
String sendBody;
sendbody = finalbody+bodyEncoded;
HttpRequest req = new HttpRequest();
req.setHeader('AdminAccountId', 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX');
req.setHeader('AdminPassword', 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX');
req.setHeader('Content-Type','multipart/form-data; boundary='+boundary);
req.setMethod('POST');
req.setEndpoint(reqEndPoint);
req.setBody(sendbody);
req.setTimeout(120000);
String bodyString = req.getBody();
System.debug('## Output body:'+bodyString );
Http http = new Http();
HTTPResponse res = http.send(req);
system.debug('----response----'+res.getBody());
}
When i use setBodyAsBlob showimg same response.
I want to add attachment with image and send to the given number via API.
I am able to send Message with x-www-form-urlencoded but when i am trying to send image with multipart/form-data then i am getting forbidden status in response with 403 status code. In response body "Message body missing".
Code :
public static void uploadFileattach(Blob filebody, String filename, String reqEndPoint){
String smessageFrom = '+19999999999';
String smessageTo = '+19999999999';
String messageBody = 'Hi Test message !';
system.debug('----- Values in uploadFileattach filebody='+filebody+'filename='+filename+'reqEndPoint='+reqEndPoint);
String boundary = '----SomethingsBoundary7MA4YWxkTrZu0gW';
String finalbody = boundary+'\nContent-Disposition: form-data; name="PhoneNumber"\n\n'+smessageFrom+'\n'
+boundary+'\nContent-Disposition: form-data; name="To"\n\n'+smessageTo+'\n'
+boundary+'\nContent-Disposition: form-data; name="File"; filename="'+filename+'";'
+'\nContent-Type: image/png\n\n'+boundary;
String bodyEncoded = EncodingUtil.base64Encode(filebody);
String sendBody;
sendbody = finalbody+bodyEncoded;
HttpRequest req = new HttpRequest();
req.setHeader('AdminAccountId', 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX');
req.setHeader('AdminPassword', 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX');
req.setHeader('Content-Type','multipart/form-data; boundary='+boundary);
req.setMethod('POST');
req.setEndpoint(reqEndPoint);
req.setBody(sendbody);
req.setTimeout(120000);
String bodyString = req.getBody();
System.debug('## Output body:'+bodyString );
Http http = new Http();
HTTPResponse res = http.send(req);
system.debug('----response----'+res.getBody());
}
When i use setBodyAsBlob showimg same response.
- Aamir Khan
- January 11, 2016
- Like
- 0
- Continue reading or reply
Stale session exception in Lightning component
Hi,
We are trying to create a lightning component and use it on VF page with ltng:out.
Suddenly we are geting exception on VF page on 7/JAN/2016.
Stale Session Exception
"The page you submitted was invalid for your session. Please try your action again."
setcallback response state is INCOMPLETE, instead of SUCCESS.
Helper Code :
({
getmessage : function(component) {
//var msg get the value from textarea.
var msg = component.get("v.getmessageBodyL");
console.log('****msg helper****',msg);
//recordId get value from VF pages parameter.
var recordId = component.get("v.recordId");
console.log('****recordId helper****',recordId);
//action will call msgBody aura enabled method.
var action = component.get("c.msgBody");
console.log('****action**** ',action);
//params provide parameter to msgBody from lightning component to apex controller
//both variable defined same in msgBody parameter.
var params = {
"msgBodyVar" : msg,
"recordId" : recordId
};
//set paramerter.
action.setParams(params);
action.setCallback(this, function(response) {
var state = response.getState();
console.log('****State**** ',state);
if (state === "SUCCESS") {
console.log('****state inside if **** ',state);
component.set("v.showSuccess","TRUE");
}
});
$A.enqueueAction(action);
},
Please help
We are trying to create a lightning component and use it on VF page with ltng:out.
Suddenly we are geting exception on VF page on 7/JAN/2016.
Stale Session Exception
"The page you submitted was invalid for your session. Please try your action again."
setcallback response state is INCOMPLETE, instead of SUCCESS.
Helper Code :
({
getmessage : function(component) {
//var msg get the value from textarea.
var msg = component.get("v.getmessageBodyL");
console.log('****msg helper****',msg);
//recordId get value from VF pages parameter.
var recordId = component.get("v.recordId");
console.log('****recordId helper****',recordId);
//action will call msgBody aura enabled method.
var action = component.get("c.msgBody");
console.log('****action**** ',action);
//params provide parameter to msgBody from lightning component to apex controller
//both variable defined same in msgBody parameter.
var params = {
"msgBodyVar" : msg,
"recordId" : recordId
};
//set paramerter.
action.setParams(params);
action.setCallback(this, function(response) {
var state = response.getState();
console.log('****State**** ',state);
if (state === "SUCCESS") {
console.log('****state inside if **** ',state);
component.set("v.showSuccess","TRUE");
}
});
$A.enqueueAction(action);
},
Please help
- Aamir Khan
- January 11, 2016
- Like
- 0
- Continue reading or reply
Prevent opening a new record on a custom object depending on "status" field
I have a custom object (object1) that has multiple objects from another custom object (object2). There are three statuses for records object2: In Progress, Cancelled, and Completed. As long as there is an In Progress or Cancelled record, I want to avoid the creation of a new record related to a single object1 record. The idea is for there to only be one step/process "In Progress" at any given time until the object1 record is "completed".
- Carrlos Boyd
- March 14, 2018
- Like
- 0
- Continue reading or reply
Sandbox User Emails are not Changing on Edit
Our users in Salesforce have the email format on creation:
jcarroll=mycompany.com@example.com
Somehow I've managed to change my email address to a proper form of
rsmith@mycompany.com.
When I try to change any other users' emails the format always reverts back to the same as in the first example. In other words, I cannot change it from jcarroll=mycompany.com@example.com to jcarroll@mycompany.com.
Rather than log a case I though I'd get input from people here first.
jcarroll=mycompany.com@example.com
Somehow I've managed to change my email address to a proper form of
rsmith@mycompany.com.
When I try to change any other users' emails the format always reverts back to the same as in the first example. In other words, I cannot change it from jcarroll=mycompany.com@example.com to jcarroll@mycompany.com.
Rather than log a case I though I'd get input from people here first.
- Frances Allen
- March 13, 2018
- Like
- 0
- Continue reading or reply
Multiplication for Roll-Up Summary Field
Hello,
I have a custom object called "Line Item", that has a master-detail relationship on Opportunity.
On an opportunity, I can have multiple "Line items". Each line item has a value.
I would like to multiply these values, and get the result in a field on opportunity.
Example:
"My opportunity":
I have a custom object called "Line Item", that has a master-detail relationship on Opportunity.
On an opportunity, I can have multiple "Line items". Each line item has a value.
I would like to multiply these values, and get the result in a field on opportunity.
Example:
"My opportunity":
- Line item 1: 2
- Line item 2: 10
- Line item 3: 2
Field "my multiplication" on "My opportunity": 2*10*2=40
What I'm trying to achieve is actually a custom field with a field type "Roll up summary", but Salesforce only allows to calcualte Min, Max, Count, Sum...
Any ideas how I can achieve this?
- Bertrand DB
- March 12, 2018
- Like
- 0
- Continue reading or reply
Am designed a lightning component show it for two recordtypes how can i show it?
Apex Class:
public with sharing class CreateOpportunityRecord
{
/**
* Create a new Opportunity Record
*
* @param Opportunity record to be inserted
*
*/
@AuraEnabled
public static String createRecord(Opportunity opp)
{
try
{
System.debug('CreateOpportunityRecord::createRecord::opp'+opp);
if(opp!= null)
insert opp;
}
catch (Exception ex)
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,string.valueof(ex)));
return null;
}
return null;
}
}
Component:
<aura:component controller="CreateOpportunityRecord"
implements="lightning:actionOverride,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes"
access="global" >
<!-- Include Static Resource-->
<ltng:require styles="/resource/bootstrap1/css/bootstrap.min.css"
scripts="/resource/bootstrap1/js/jquery.js,/resource/bootstrap/js/bootstrap.min.js"/>
<!-- Define Attribute-->
<aura:attribute name="selectedLookUpRecord" type="sObject" default="{}"/>
<aura:attribute name="number" type="integer"/>
<aura:attribute name="recType" type="RecordType"/>
<aura:attribute name="myText" type="String"/>
<aura:attribute name="opp" type="Opportunity" default="{'sobjectType': 'Opportunity',
'Owner': '',
'Name': '',
'RecordType': '',
'Account__c': '',
'LeadSource': '',
'Amount': '',
'StageName': '',
'CloseDate': '',
'Description': '',
}"/><br/>
<div style="background-color:white;padding:10pt;border-radius:5px;">
<div>
<table>
<tr>
<td>
<h2 style="font-weight:bold;font-size:12px;margin-left:5%">New Opportunity Edit</h2>
<h1 style="font-weight:bold;font-size:18px;margin-left:5%">New Opportunity</h1>
</td>
</tr>
</table>
</div><br/>
<table>
<tr>
<td width="45%">
<h1 style="font-weight:bold;font-size:12px;margin-left:5%">Opportunity Edit</h1>
</td>
<td width="55%">
<lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
<lightning:button variant="brand" label="Cancel" onclick="{!c.cancel}"/>
</td>
</tr>
</table><br/>
<h3 class="slds-section__title slds-theme_shade">
<span class="slds-truncate slds-p-horizontal_small" title="Opportunity Information">Opportunity Information</span>
</h3>
<div class="slds-grid slds-gutters">
<div class="slds-col" style="width:500px;">
<table class="slds-table slds-table--bordered slds-table--cell-buffer">
<thead>
<tr>
<td width="45%">
<table>
<tr>
<td>
<p class="title">Owner</p>
<ui:outputText value="{!v.opp.Owner}"/>
</td>
</tr>
<tr>
<td>
<p class="title">Opportunity Name</p>
<ui:inputText value="{!v.opp.Name}"/>
</td>
</tr>
<tr>
<td><c:customLookup objectAPIName="account" IconName="standard:account" label="Account" selectedRecord="{!v.selectedLookUpRecord}"/></td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Lead Source</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.opp.LeadSource}">
<ui:inputSelectOption text="None"/>
<ui:inputSelectOption text="Web"/>
<ui:inputSelectOption text="Phone Enquiry"/>
<ui:inputSelectOption text="Partner Refferal"/>
<ui:inputSelectOption text="Purchased List"/>
<ui:inputSelectOption text="Other"/>
</ui:inputSelect>
</td>
</tr>
</div>
</table>
</td>
<td width="10%"></td>
<td width="45%">
<table>
<tr>
<td>
<p class="title">Opportunity Record Type</p>
<ui:outputText value="{!v.opp.RecordType}"/>
</td>
</tr>
<tr>
<td>
<p class="title">Amount</p>
<ui:inputNumber value="{!v.opp.Amount}"/>
</td>
</tr>
<div class="form-group">
<tr>
<td>
<p class="title">Stage</p>
<ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}" value="{!v.opp.StageName}">
<ui:inputSelectOption text="None"/>
<ui:inputSelectOption text="Prospecting"/>
<ui:inputSelectOption text="Qualification"/>
<ui:inputSelectOption text="Needs Analysis"/>
<ui:inputSelectOption text="Value Proposition"/>
<ui:inputSelectOption text="Id. Decision Makers"/>
<ui:inputSelectOption text="Perception Analysis"/>
<ui:inputSelectOption text="Proposal/Price Quote"/>
<ui:inputSelectOption text="Negotiation/Review"/>
<ui:inputSelectOption text="Closed Won"/>
<ui:inputSelectOption text="Closed Lost"/>
</ui:inputSelect>
</td>
</tr>
</div>
<tr>
<td>
<label>Close Date</label>
<ui:inputDate displayDatePicker="true" value="{!v.opp.CloseDate}"/>
</td>
</tr>
</table>
</td>
</tr>
</thead>
</table>
<h3 class="slds-section__title slds-theme_shade">
<span class="slds-truncate slds-p-horizontal_small" title="Description Information">Description Information</span>
</h3>
<table class="slds-table slds-table--bordered slds-table--cell-buffer">
<thead>
<tr>
<td>
<p class="title">Description</p>
<ui:inputTextArea value="{!v.opp.Description}" rows="5" class="desc"/>
</td>
</tr>
</thead>
</table>
<br/>
<div class="de">
<lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
<lightning:button variant="brand" label="Cancel" onclick="{!c.cancel}"/>
</div>
<br/>
</div>
</div>
</div>
</aura:component>
Controller:
({
create : function(component, event, helper) {
console.log('Create record');
//getting the opportunity information
var opp = component.get("v.opp");
opp.Account__c = null;
/***************Validation
if($A.util.isEmpty(opp.Account__c) || $A.util.isUndefined(opp.Account__c)){
alert('Account Name is Required');
return;
}*************************************************/
/*if(component.find("LeadSource").get("v.value") == ''){
alert('picklist field is required');
}*/
if(component.get("v.selectedLookUpRecord").Id != undefined){
opp.Account__c = component.get("v.selectedLookUpRecord").Id;
}
//Calling the Apex Function
var action = component.get("c.createRecord");
//Setting the Apex Parameter
action.setParams({
opp : opp
});
//Setting the Callback
action.setCallback(this,function(a){
//get the response state
var state = a.getState();
//check if result is successfull
if(state == "SUCCESS"){
//Reset Form
var newOpportunity = {'sobjectType': 'Opportunity',
'Name': '',
'Account__c': '',
'LeadSource': '',
'Amount': '',
'StageName': '',
'CloseDate': '',
'Description': '',
};
//resetting the Values in the form
component.set("v.opp",newOpportunity);
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/006/o"
});
urlEvent.fire();
//alert('Record is Created Successfully');
} else if(state == "ERROR"){
alert('Please enter Name,Account,Stage and Close Date');
}
});
//adds the server-side action to the queue
$A.enqueueAction(action);
},
cancel : function (component, event, helper) {
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/006/o"
});
urlEvent.fire();
},
onSingleSelectChange: function(cmp,event,helper) {
var selectCmpValue = event.getSource().get("v.value");
//alert(selectCmpValue);
},
/*onSingleSelectChange: function(cmp) {
var selectCmp = cmp.find("InputSelectSingle");
var resultCmp = cmp.find("singleResult");
resultCmp.set("v.value", selectCmp.get("v.value"));
},*/
onChange: function(cmp) {
var dynamicCmp = cmp.find("InputSelectDynamic");
var resultCmp = cmp.find("dynamicResult");
resultCmp.set("v.value", dynamicCmp.get("v.value"));
}
})
- Sai Subhash 6
- March 12, 2018
- Like
- 0
- Continue reading or reply
Please do help with test class
HI Folks
I got strucked with test class, Please help with Test Class for below class.
I got strucked with test class, Please help with Test Class for below class.
@RestResource(urlMapping='/api/IVR/*') global class IVRRestAPI { @HttpPost global static List<IVR__c> CreateIVR(List<createIVR> icretIVR) { try{ Set<String> loanId = new Set<String>(); List<Loan__c> loanlst = new List<Loan__c>(); Map<String,String> mpidtoname = new Map<String,String>(); List<IVR__c> IVRlst = new List<IVR__c>(); for(createIVR icret:icretIVR) { if(icret.LoanID != null) { loanId.add(icret.LoanID); } } System.debug('loanId '+loanId); if(loanId.size() > 0) { loanlst = [SELECT Id,Name FROM Loan__c WHERE Name IN:loanId]; } System.debug('loanlst '+loanlst); if(loanlst.size() > 0) { for(Loan__c iloan:loanlst) { mpidtoname.put(iloan.Name,iloan.Id); } } System.debug('mpidtoname '+mpidtoname); for(createIVR icret:icretIVR) { IVR__c IVR = new IVR__c(); IVR.Name = icret.IVRId; IVR.Disbursed_Amount__c = Decimal.valueOf(icret.DisbursedAmount); IVR.Merchant_Name__c = icret.MerchantName; IVR.Disbursed_Date_Time__c = date.ValueOf(icret.DisbursedDateTime); IVR.IVR_Number__c = icret.IVRNumber; if(mpidtoname.containskey(icret.LoanID)) { IVR.Loan_Id__c = mpidtoname.get(icret.LoanID); } IVRlst.add(IVR); } if(IVRlst.size() > 0) { insert IVRlst; return IVRlst; } return null; }catch(exception e){System.debug(e.getmessage() + e.getlinenumber());return null;} } global class createIVR { public String IVRId; public String LoanID; public String DisbursedAmount; public String MerchantName; Public String DisbursedDateTime; Public String IVRNumber; } }
I have tried with test class to get test code but unfortunately i got just "0" Please do help.
@istest public class IVRRestAPITest{ static testMethod void IVRRestAPI(){ IVR__c TestOpp=new IVR__c (); TestOpp.name='TestOpp1'; TestOpp.Disbursed_Amount__c=234567; TestOpp.IVR_Number__c ='2345678'; TestOpp.Merchant_Name__c ='Test'; insert TestOpp; IVRRestAPI reqst=new IVRRestAPI(); String JsonMsg=JSON.serialize(reqst); Test.startTest(); RestRequest req = new RestRequest(); RestResponse res = new RestResponse(); req.requestURI = '/services/apexrest/api/IVR/CreateIVR'; //Request URL req.httpMethod = 'POST'; req.requestBody = Blob.valueof(JsonMsg); RestContext.request = req; RestContext.response= res; Test.stopTest(); } }
Please do help.
Thanks in Advance.
- R R M
- March 12, 2018
- Like
- 0
- Continue reading or reply
Not getting test class code coverage for If() condition
I tried several times to get the code coverage for the below test class now I need someone's help to get code coverage for red color coding in the Image How can I ???
Here the below image shows the code coverage.
My trigger
Test class
Here the below image shows the code coverage.
My trigger
trigger customsolinsert on Price_Study__c (after update, after insert) { // Find the existing (0 or 1) Custom_solution__c that reference Price_Study__c Map<Id, Custom_solution__c> m = new Map<Id, Custom_solution__c>(); list<Custom_solution__c> oblist=[ select id, Price_Study__c from Custom_solution__c where Price_Study__c in :Trigger.newMap.keySet() ]; for (Custom_solution__c ob : oblist) { m.put(ob.Price_Study__c, ob); } // Insert or update the Custom_solution__c List<Custom_solution__c> csol= new List<Custom_solution__c>(); for (Price_Study__c b : trigger.new) { // Get record to update Custom_solution__c ob = m.get(b.id); if(b.Analysis_Done_By__c<>Null){ if (ob == null) { // If no record to update, add a record to be inserted ob = new Custom_solution__c(Price_Study__c = b.id); } ob.Price_Study__c=b.Id; ob.Country__c=b.Country_of_Treatment__c; ob.Who_Deals__c=b.Analysis_Done_By__c; ob.Customer__c=b.Account_Name__c; ob.Product_line__c=b.Product_line__c; ob.Function_Focus__c=b.Function_Focus__c; ob.Comments__c=b.Generic_Comments__c; ob.Nbrs_Post__c=b.Nbrs_Post__c; ob.Series_Row_nbr__c=b.Series_Row_nbr__c; csol.add(ob); } } upsert csol;
Test class
@istest(isParallel=true) public class Testcustomsolinsert{ @istest Static void Testcustomsol1(){ Profile prof = [select id from profile where name='system Administrator']; List<User> lstUser = [Select u.Profile.Name, u.ProfileId, u.IsActive, u.Id From User u Where IsActive = true AND Profile.Name = 'System Administrator']; system.runAs(lstUser[0]){ Account acc=new account(Name='NicoTestacc',BillingCountry='India'); insert acc; Opportunity op1= new opportunity(Name='NicoTestOpp',CloseDate=date.today(),StageName='Qualification',Product_Type__c='DPI',Accountid=acc.Id); insert op1; System.assertEquals(op1.name,'NicoTestOpp'); Price_Study__c ps=new Price_Study__c(Country_of_Treatment__c='India',Series_Row_nbr__c=3, Nbrs_Post__c=2,Analysis_Done_By__c=op1.OwnerId, Generic_Comments__c='asdfds',Function_Focus__c='sdad', Product_line__c='CMM'); Insert Ps; Map<Id, Custom_solution__c> m = new Map<Id, Custom_solution__c>(); Custom_solution__c cs1=new Custom_solution__c(Price_Study__c=PS.Id,Country__c=Ps.Country_of_Treatment__c); Insert cs1; delete cs1; Custom_solution__c cs=new Custom_solution__c(); cs.Price_Study__c=ps.Id; cs.Country__c=Ps.Country_of_Treatment__c; cs.Who_Deals__c=ps.Analysis_Done_By__c; cs.Customer__c=ps.Account_Name__c; cs.Product_line__c='Cmm'; cs.Function_Focus__c=ps.Function_Focus__c; cs.Comments__c=ps.Generic_Comments__c; cs.Nbrs_Post__c=ps.Nbrs_Post__c; cs.Series_Row_nbr__c=ps.Series_Row_nbr__c; Insert cs; cs.Function_Focus__c=ps.Function_Focus__c; Update cs; } } }
- vinod kumar 364
- March 12, 2018
- Like
- 0
- Continue reading or reply
How can I write SOQL query for returning invitees for an event in sfdc
Hi All,
Please help me to write a query for returning invitees for an event which has been invited a user. I have researched already about it, I got "isinvitee" boolean value for ensuring the user has invited or not. But I can't see the field name in that Event object.
Thanks,
Rakshana
Please help me to write a query for returning invitees for an event which has been invited a user. I have researched already about it, I got "isinvitee" boolean value for ensuring the user has invited or not. But I can't see the field name in that Event object.
Thanks,
Rakshana
- Rakshana Cube84
- March 12, 2018
- Like
- 0
- Continue reading or reply