-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
5Questions
-
10Replies
Add contacts as a campaign member when the field on account is populated for first time.
Hi Team,
Can someone please help me with below requirement.
When a specific field on account is populated for the first time, its active contacts should get added on campaign(contact country same as campaign country)as campaign member.
Thanks
Can someone please help me with below requirement.
When a specific field on account is populated for the first time, its active contacts should get added on campaign(contact country same as campaign country)as campaign member.
Thanks
- Haneef S
- November 14, 2019
- Like
- 0
- Continue reading or reply
insert a new record using custom button
Hi All,
I am new to lightning, can some one please help me with the below code:
I have my existing code that displays accounts and when clicked particular account it shows its own contacts.
Now, on the same page there should be one button for Add Account. On click of this button, popup will ask for account details and after click on submit button this new account will add to database, go to previous page and previous page also will refresh.
when I click on preview I get below error:
Below is my code:
component:
<aura:component controller="AccountPagination" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<ltng:require styles="/resource/SLDS244/styles/salesforce-lightning-design-system.css" />
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<h1 class="slds-text-heading--medium">Accounts List</h1>
</div>
</div>
</div>
<aura:attribute name="acccountList" type="Account[]" />
<aura:attribute name="contacts" type="Contact[]"/>
<aura:attribute name="paginationList" type="Account[]"/>
<aura:attribute name="pageSize" type="Integer" default="15"/>
<aura:attribute name="totalSize" type="Integer"/>
<aura:attribute name="start" type="Integer" />
<aura:attribute name="end" type="Integer"/>
<table class="slds-table slds-table--bordered ">
<thead>
<tr style="color:Grey;font-weight:bold">
<!--<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading-/-medium">Id</h1></th>
</div>
</div>
</div></td>-->
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Name</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">AccountNumber</h1></th>
</div>
</div>
</div></td>
<!--<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading-/-medium">AccountOwnerId</h1></th>
</div>
</div>
</div></td>-->
<!--<th>Id</th>
<th>Name</th>
<th>Phone</th>
<th>AccountNumber</th>
<th>BillingAddress</th>-->
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.paginationList}" var="item">
<tr>
<!--<td><lightning:input value="{!item.Id}"/></td>
<td><lightning:input value="{!item.Name}"/></td>
<td><lightning:input value="{!item.AccountNumber}"/></td>
<td><lightning:input value="{!item.OwnerId}"/></td>
<td><lightning:input value="{!item.Owner.Name}"/></td>-->
<!--<td><ui:outputText value="{!item.Id}" /></td>-->
<td><a href="javascript:void(0);" onclick="{!c.Clicked}" data-value="{!item.Id}">{!item.Name}
</a></td>
<td><ui:outputText value="{!item.AccountNumber}"/></td>
<!--<td><ui:outputText value="{!item.OwnerId}"/></td>-->
</tr>
</aura:iteration>
<!-- <lightning:button label="Previous" disabled="{!v.start == 0}" onclick="{!c.previous}" />
<lightning:button label="Next" disabled="{!v.end >= v.totalSize}" onclick="{!c.next}" />-->
</tbody>
</table>
<lightning:button label="Previous" disabled="{!v.start == 0}" onclick="{!c.previous}" />
<lightning:button label="Next" disabled="{!v.end >= v.totalSize}" onclick="{!c.next}" />
<lightning:button label="Create New account" onclick="{!c.createRecord}" />
<div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<h1 class="slds-text-heading--medium">Contacts associated with account</h1>
</div>
</div>
</div>
<table class="slds-table slds-table--bordered ">
<thead>
<tr style="color:Grey;font-weight:bold">
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Contact Id</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Contact Name</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Account Id</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Account Name</h1></th>
</div>
</div>
</div></td>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.contacts}" var="con">
<tr>
<td><ui:outputText value="{!con.Id}" /></td>
<td><ui:outputText value="{!con.Name}" /></td>
<td><ui:outputText value="{!con.AccountId}" /></td>
<td><ui:outputText value="{!con.Account.Name}" /></td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
Accountpaginationcontroller.js
({
doInit : function(component, event, helper)
{
var pageSize = component.get("v.pageSize");
var action = component.get("c.getAccounts");
action.setCallback(this, function(response)
{
var state = response.getState();
if (component.isValid() && state === "SUCCESS")
{
console.log(response.getReturnValue());
component.set('v.acccountList', response.getReturnValue());
component.set("v.totalSize", component.get("v.acccountList").length);
component.set("v.start",0);
component.set("v.end",pageSize-1);
var paginationList = [];
for(var i=0; i< pageSize; i++)
{
paginationList.push(response.getReturnValue()[i]);
}
component.set('v.paginationList', paginationList);
}
});
$A.enqueueAction(action);
},
next : function(component, event, helper)
{
var accountList = component.get("v.acccountList");
var end = component.get("v.end");
var start = component.get("v.start");
var pageSize = component.get("v.pageSize");
var paginationList = [];
var counter = 0;
for(var i=end+1; i<end+pageSize+1; i++)
{
if(accountList.length > end)
{
paginationList.push(accountList[i]);
counter ++ ;
}
}
start = start + counter;
end = end + counter;
component.set("v.start",start);
component.set("v.end",end);
component.set('v.paginationList', paginationList);
},
previous : function(component, event, helper)
{
var accountList = component.get("v.acccountList");
var end = component.get("v.end");
var start = component.get("v.start");
var pageSize = component.get("v.pageSize");
var paginationList = [];
var counter = 0;
for(var i= start-pageSize; i < start ; i++)
{
if(i > -1)
{
paginationList.push(accountList[i]);
counter ++;
}
else
{
start++;
}
}
start = start - counter;
end = end - counter;
component.set("v.start",start);
component.set("v.end",end);
component.set('v.paginationList', paginationList);
},
Clicked : function(component, event, helper){
var ctarget = event.currentTarget;
var id_str = ctarget.dataset.value;
console.log(id_str);
var action = component.get("c.getContactRecords");
action.setParams({ accId : id_str});
action.setCallback(this, function(response) {
var state = response.getState(); //Checking response status
console.log("contactsss... "+JSON.stringify(response.getReturnValue()));
if (component.isValid() && state === "SUCCESS"){
if(response.getReturnValue() !=''){
component.set("v.contacts", response.getReturnValue());
}
else{
alert('contacts are not available for this account');
// Adding values in Aura attribute variable.
}
} });
$A.enqueueAction(action);
},
createRecord: function(component, event, helper) {
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Account" // using account standard object for this sample
});
createRecordEvent.fire();
}
})
accountpagination.apxc
public with sharing class AccountPagination
{
/*@AuraEnabled
public static List<Account> getAccounts()
{
List<Account> accs = [SELECT Id, Name,Phone,AccountNumber,BillingAddress,Fax,OwnerId,Owner.Name,(SELECT Id,FirstName,LastName,Email from contacts) FROM Account];
return accs;
}*/
@AuraEnabled
public static List<Account> getAccounts() {
return new List<Account>([SELECT Id, Name,Phone,AccountNumber,BillingAddress,Fax,OwnerId,Owner.Name FROM Account]);
}
@AuraEnabled
public static List<Contact> getContactRecords(string accId) {
return new List<Contact>([Select id,Name,Account.Name,AccountId from Contact Where AccountId =: accId LIMIT 100]);
}
}
accountpaginationapp.app:
<aura:application >
<c:AccountPagination/>
</aura:application>
Can anyone please help
I am new to lightning, can some one please help me with the below code:
I have my existing code that displays accounts and when clicked particular account it shows its own contacts.
Now, on the same page there should be one button for Add Account. On click of this button, popup will ask for account details and after click on submit button this new account will add to database, go to previous page and previous page also will refresh.
when I click on preview I get below error:
Below is my code:
component:
<aura:component controller="AccountPagination" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<ltng:require styles="/resource/SLDS244/styles/salesforce-lightning-design-system.css" />
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<h1 class="slds-text-heading--medium">Accounts List</h1>
</div>
</div>
</div>
<aura:attribute name="acccountList" type="Account[]" />
<aura:attribute name="contacts" type="Contact[]"/>
<aura:attribute name="paginationList" type="Account[]"/>
<aura:attribute name="pageSize" type="Integer" default="15"/>
<aura:attribute name="totalSize" type="Integer"/>
<aura:attribute name="start" type="Integer" />
<aura:attribute name="end" type="Integer"/>
<table class="slds-table slds-table--bordered ">
<thead>
<tr style="color:Grey;font-weight:bold">
<!--<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading-/-medium">Id</h1></th>
</div>
</div>
</div></td>-->
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Name</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">AccountNumber</h1></th>
</div>
</div>
</div></td>
<!--<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading-/-medium">AccountOwnerId</h1></th>
</div>
</div>
</div></td>-->
<!--<th>Id</th>
<th>Name</th>
<th>Phone</th>
<th>AccountNumber</th>
<th>BillingAddress</th>-->
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.paginationList}" var="item">
<tr>
<!--<td><lightning:input value="{!item.Id}"/></td>
<td><lightning:input value="{!item.Name}"/></td>
<td><lightning:input value="{!item.AccountNumber}"/></td>
<td><lightning:input value="{!item.OwnerId}"/></td>
<td><lightning:input value="{!item.Owner.Name}"/></td>-->
<!--<td><ui:outputText value="{!item.Id}" /></td>-->
<td><a href="javascript:void(0);" onclick="{!c.Clicked}" data-value="{!item.Id}">{!item.Name}
</a></td>
<td><ui:outputText value="{!item.AccountNumber}"/></td>
<!--<td><ui:outputText value="{!item.OwnerId}"/></td>-->
</tr>
</aura:iteration>
<!-- <lightning:button label="Previous" disabled="{!v.start == 0}" onclick="{!c.previous}" />
<lightning:button label="Next" disabled="{!v.end >= v.totalSize}" onclick="{!c.next}" />-->
</tbody>
</table>
<lightning:button label="Previous" disabled="{!v.start == 0}" onclick="{!c.previous}" />
<lightning:button label="Next" disabled="{!v.end >= v.totalSize}" onclick="{!c.next}" />
<lightning:button label="Create New account" onclick="{!c.createRecord}" />
<div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<h1 class="slds-text-heading--medium">Contacts associated with account</h1>
</div>
</div>
</div>
<table class="slds-table slds-table--bordered ">
<thead>
<tr style="color:Grey;font-weight:bold">
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Contact Id</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Contact Name</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Account Id</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Account Name</h1></th>
</div>
</div>
</div></td>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.contacts}" var="con">
<tr>
<td><ui:outputText value="{!con.Id}" /></td>
<td><ui:outputText value="{!con.Name}" /></td>
<td><ui:outputText value="{!con.AccountId}" /></td>
<td><ui:outputText value="{!con.Account.Name}" /></td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
Accountpaginationcontroller.js
({
doInit : function(component, event, helper)
{
var pageSize = component.get("v.pageSize");
var action = component.get("c.getAccounts");
action.setCallback(this, function(response)
{
var state = response.getState();
if (component.isValid() && state === "SUCCESS")
{
console.log(response.getReturnValue());
component.set('v.acccountList', response.getReturnValue());
component.set("v.totalSize", component.get("v.acccountList").length);
component.set("v.start",0);
component.set("v.end",pageSize-1);
var paginationList = [];
for(var i=0; i< pageSize; i++)
{
paginationList.push(response.getReturnValue()[i]);
}
component.set('v.paginationList', paginationList);
}
});
$A.enqueueAction(action);
},
next : function(component, event, helper)
{
var accountList = component.get("v.acccountList");
var end = component.get("v.end");
var start = component.get("v.start");
var pageSize = component.get("v.pageSize");
var paginationList = [];
var counter = 0;
for(var i=end+1; i<end+pageSize+1; i++)
{
if(accountList.length > end)
{
paginationList.push(accountList[i]);
counter ++ ;
}
}
start = start + counter;
end = end + counter;
component.set("v.start",start);
component.set("v.end",end);
component.set('v.paginationList', paginationList);
},
previous : function(component, event, helper)
{
var accountList = component.get("v.acccountList");
var end = component.get("v.end");
var start = component.get("v.start");
var pageSize = component.get("v.pageSize");
var paginationList = [];
var counter = 0;
for(var i= start-pageSize; i < start ; i++)
{
if(i > -1)
{
paginationList.push(accountList[i]);
counter ++;
}
else
{
start++;
}
}
start = start - counter;
end = end - counter;
component.set("v.start",start);
component.set("v.end",end);
component.set('v.paginationList', paginationList);
},
Clicked : function(component, event, helper){
var ctarget = event.currentTarget;
var id_str = ctarget.dataset.value;
console.log(id_str);
var action = component.get("c.getContactRecords");
action.setParams({ accId : id_str});
action.setCallback(this, function(response) {
var state = response.getState(); //Checking response status
console.log("contactsss... "+JSON.stringify(response.getReturnValue()));
if (component.isValid() && state === "SUCCESS"){
if(response.getReturnValue() !=''){
component.set("v.contacts", response.getReturnValue());
}
else{
alert('contacts are not available for this account');
// Adding values in Aura attribute variable.
}
} });
$A.enqueueAction(action);
},
createRecord: function(component, event, helper) {
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Account" // using account standard object for this sample
});
createRecordEvent.fire();
}
})
accountpagination.apxc
public with sharing class AccountPagination
{
/*@AuraEnabled
public static List<Account> getAccounts()
{
List<Account> accs = [SELECT Id, Name,Phone,AccountNumber,BillingAddress,Fax,OwnerId,Owner.Name,(SELECT Id,FirstName,LastName,Email from contacts) FROM Account];
return accs;
}*/
@AuraEnabled
public static List<Account> getAccounts() {
return new List<Account>([SELECT Id, Name,Phone,AccountNumber,BillingAddress,Fax,OwnerId,Owner.Name FROM Account]);
}
@AuraEnabled
public static List<Contact> getContactRecords(string accId) {
return new List<Contact>([Select id,Name,Account.Name,AccountId from Contact Where AccountId =: accId LIMIT 100]);
}
}
accountpaginationapp.app:
<aura:application >
<c:AccountPagination/>
</aura:application>
Can anyone please help
- Haneef S
- October 24, 2018
- Like
- 0
- Continue reading or reply
I am facing error for the below test class
I have created test class and facing below exception:
Error:System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: []
stacktrace:
Class.OpportunityLineItemMultiInsertTest.setData: line 54, column 1
Class.OpportunityLineItemMultiInsertTest.testInsertOLI: line 112, column 1
Apex class:
public class OpportunityLineItemMultiInsert{
public List<OLIWrapper> wrappers {get; set;}
public List<OpportunityLineItem> olis {get; set;}
public Opportunity oppty {get; set;}
public String opportunityId {get; set;}
private Id opptyId ;
private List<string> pbeIds;
private List<string> pbeIdscleaned;
public static Integer toDelIdent {get; set;}
public static Integer addCount {get; set;}
private Integer nextIdent=0;
public Boolean showReload {get; set;}
public OpportunityLineItemMultiInsert() {
opportunityId = ApexPages.currentPage().getParameters().get('opptyid');
showReload = false;
opptyId = ApexPages.currentPage().getParameters().get('opptyid');
pbeIds = ApexPages.currentPage().getParameters().get('ids').split(',');
pbeIdscleaned = new List<string>();
for (String currIdent : pbeIds ) {
if (currIdent != '') {
pbeIdscleaned.add(currIdent);
}
}
Map<Id, String> allPBEs = new Map<Id, String>();
for (PricebookEntry currPBEc : [select id, Name, UnitPrice from PricebookEntry where id in :pbeIdscleaned]) {
allPBEs.put(currPBEc.Id, currPBEc.Name);
}
wrappers=new List<OLIWrapper>();
//nextIdent = pbeIds.size()+1;
for (Integer idx=0; idx<pbeIdscleaned.size(); idx++)
{
OLIWrapper curr = new OLIWrapper(nextIdent++);
curr.acc.PricebookEntryId = pbeIdscleaned[idx]; //'01u24000004Nq7yAAC';
curr.productName = allPBEs.get(pbeIdscleaned[idx]);
/*
if (allPBEs.get(pbeIdscleaned[idx]).length() > 17) {
curr.acc.zz_Previous_OLI_ID__c= allPBEs.get(pbeIdscleaned[idx]).substring(0,17);
} else {
curr.acc.zz_Previous_OLI_ID__c= allPBEs.get(pbeIdscleaned[idx]);
}
*/
curr.acc.UnitPrice = 1;
curr.acc.OpportunityId = opptyId ;
wrappers.add(curr );
}
oppty = [select id, Name from Opportunity where id = :opptyId];
/*
olis = [select Id,
Name,
Quantity,
TotalQtyHelper__c,
Duration_months__c,
Unit_Margin__c,
Units_for_Quantity__c,
Qty_month__c,
Unit_Cost__c,
UnitPrice,
TotalPrice,
Total_Cost__c,
ServiceDate,
Invoice_Date__c,
Description,
CurrencyIsoCode
from OpportunityLineItem
where id in : pbeIdscleaned];
*/
//qtyToQtyHelper();
}
public PageReference save() {
List<OpportunityLineItem > accs=new List<OpportunityLineItem >();
for (OLIWrapper wrap : wrappers)
{
wrap.acc.Quantity = wrap.acc.TotalQtyHelper__c;
accs.add(wrap.acc);
}
System.debug('olis:' + accs);
insert accs;
showReload = true;
//return new PageReference('/' + opptyId);
return null;
}
public PageReference cancel() {
return new PageReference('/' + opptyId);
}
public class OLIWrapper
{
public OpportunityLineItem acc {get; private set;}
public Integer ident {get; private set;}
public String productName {get; set;}
public OLIWrapper(Integer inIdent)
{
ident=inIdent;
acc=new OpportunityLineItem (description = String.valueOf(ident));
}
}
// TotalQtyHelper__c allows to leave the field blank where Quantity can't be blank
private void qtyToQtyHelper() {
for (OpportunityLineItem oli : olis) {
oli.TotalQtyHelper__c = oli.Quantity;
}
}
}
Test class:
@isTest
private class OpportunityLineItemMultiInsertTest {
private static OpportunityLineItem opptyLineItemObj;
private static Opportunity opportunityObj;
private static List<OpportunityLineItem> oliList ;
private static void setData() {
Account accountObj = (Account)TestDataHelper.createSObject('Account');
accountObj.SAP_id__c='0011254999';
accountObj.BillingCity = 'pune' ;
accountObj.BillingStreet = 'bhel chowk' ;
accountObj.BillingCountry = 'india' ;
accountObj.BillingPostalCode = '345210' ;
insert accountObj;
Organization__c organizationObj = (Organization__c)TestDataHelper.createSObject('Organization__c');
//organizationObj.Active__c = true;
insert organizationObj;
RecordType rec = [Select id,name from recordtype where developername = 'Solution'];
Product2 prod = new Product2(Name = 'Laptop X200',
Family = '2_PLA_BUSS',
Hierarchy_Level__c = 'SKU',
ProductCode = 'abc123',
CanUseRevenueSchedule=true,
CanUseQuantitySchedule=true,
recordtypeId = rec.id
);
insert prod;
/* RecordType rec = [Select id,name from recordtype where developername = 'Solution'];
Product2 prod1 = new Product2(Name = 'Laptop X200',
Family = '2_PLA_BUSS',
Hierarchy_Level__c = 'SKU',
ProductCode = 'abc123',
CanUseRevenueSchedule=true,
CanUseQuantitySchedule=true,
recordtypeId = rec.id
);
insert prod1;
*/
Id pricebookId = Test.getStandardPricebookId();
PricebookEntry standardPBE = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = prod.Id,
UnitPrice = 10000, IsActive = true,UseStandardPrice = true);
system.debug(standardPBE);
insert standardPBE;
//List<PricebookEntry> pbe = [select id, name, CurrencyIsoCode from PriceBookEntry where Pricebook2id =: 'VALUE' and Product2.Id in: VALUE.keySet() ];
/*PricebookEntry standardPBE1 = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = prod1.Id,
UnitPrice = 10000, IsActive = true);
insert standardPBE1;
*/
opportunityObj = (Opportunity)TestDataHelper.createSObject('Opportunity');
opportunityObj.Accountid= accountObj.id;
opportunityObj.Pricebook2Id=pricebookId;
opportunityObj.CurrencyIsoCode=standardPBE.CurrencyIsoCode;
opportunityObj.Organization__c=organizationObj.id;
insert opportunityObj;
opportunityObj = (Opportunity)TestDataHelper.createSObject('Opportunity');
opportunityObj.Accountid= accountObj.id;
opportunityObj.Pricebook2Id=pricebookId;
//opportunityObj.CurrencyIsoCode=standardPBE1.CurrencyIsoCode;
opportunityObj.Organization__c=organizationObj.id;
insert opportunityObj;
OpportunityTeamMember otm=new OpportunityTeamMember();
otm.userid=userinfo.getuserid();
otm.TeamMemberRole='High Level';
otm.opportunityid=opportunityObj.id;
otm.Lead_Type__c='Test Lead';
insert otm;
oliList = new List<OpportunityLineItem>();
for(integer i = 0; i<= 5; i++) {
opptyLineItemObj = new OpportunityLineItem();
opptyLineItemObj.Quantity=1;
opptyLineItemObj.Oppty_Team_Members__c ='['+ otm.User.Name +','+ otm.Lead_Type__c +']';
opptyLineItemObj.TotalPrice=500;
opptyLineItemObj.Delivery_Date_Start__c = system.today().addDays(5);
opptyLineItemObj.Delivery_Date_Last__c = system.today().addDays(7);
opptyLineItemObj.Revenue_Date_Last__c = system.today().addDays(5);
opptyLineItemObj.Revenue_Date_Start__c = system.today().addDays(7);
opptyLineItemObj.Quote_Package_Name__c = 'packageName';
//opptyLineItemObj.HasSchedule = true;
opptyLineItemObj.PricebookEntryId=standardPBE.id;
// opptyLineItemObj.PricebookEntryId=standardPBE1.id;
opptyLineItemObj.opportunityid=opportunityObj.id;
opptyLineItemObj.ServiceDate = system.today().addDays(5);
opptyLineItemObj.Invoice_Date__c = system.today().addDays(5);
oliList.add(opptyLineItemObj);
}
insert oliList;
}
static testmethod void testInsertOLI() {
setData();
/*
List<OpportunityLineItem> olis = new List<OpportunityLineItem>();
List<PricebookEntry> pbe = new List<PricebookEntry>();
Opportunity oppty = TestDataHelper.createOpptyWithOfferings('Product',olis);
*/
string oliIds = '';
for (OpportunityLineItem oli : oliList) {
oliIds = oliIds + ',' + oli.id;
}
oliIds = oliIds.substring(1);
Test.startTest();
ApexPages.currentPage().getParameters().put('opptyid',opportunityObj.id);
ApexPages.currentPage().getParameters().put('ids',oliIds);
OpportunityLineItemMultiInsert ctr = new OpportunityLineItemMultiInsert();
ctr.save();
ctr.cancel();
//ctr.qtyToQtyHelper();
ctr.olis = oliList;
Boolean testValue;
if(ctr != null){
testValue = true;
}
System.assert(testValue);
}
}
Any help will be appreciated
Thanks,
Haneef
Error:System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: []
stacktrace:
Class.OpportunityLineItemMultiInsertTest.setData: line 54, column 1
Class.OpportunityLineItemMultiInsertTest.testInsertOLI: line 112, column 1
Apex class:
public class OpportunityLineItemMultiInsert{
public List<OLIWrapper> wrappers {get; set;}
public List<OpportunityLineItem> olis {get; set;}
public Opportunity oppty {get; set;}
public String opportunityId {get; set;}
private Id opptyId ;
private List<string> pbeIds;
private List<string> pbeIdscleaned;
public static Integer toDelIdent {get; set;}
public static Integer addCount {get; set;}
private Integer nextIdent=0;
public Boolean showReload {get; set;}
public OpportunityLineItemMultiInsert() {
opportunityId = ApexPages.currentPage().getParameters().get('opptyid');
showReload = false;
opptyId = ApexPages.currentPage().getParameters().get('opptyid');
pbeIds = ApexPages.currentPage().getParameters().get('ids').split(',');
pbeIdscleaned = new List<string>();
for (String currIdent : pbeIds ) {
if (currIdent != '') {
pbeIdscleaned.add(currIdent);
}
}
Map<Id, String> allPBEs = new Map<Id, String>();
for (PricebookEntry currPBEc : [select id, Name, UnitPrice from PricebookEntry where id in :pbeIdscleaned]) {
allPBEs.put(currPBEc.Id, currPBEc.Name);
}
wrappers=new List<OLIWrapper>();
//nextIdent = pbeIds.size()+1;
for (Integer idx=0; idx<pbeIdscleaned.size(); idx++)
{
OLIWrapper curr = new OLIWrapper(nextIdent++);
curr.acc.PricebookEntryId = pbeIdscleaned[idx]; //'01u24000004Nq7yAAC';
curr.productName = allPBEs.get(pbeIdscleaned[idx]);
/*
if (allPBEs.get(pbeIdscleaned[idx]).length() > 17) {
curr.acc.zz_Previous_OLI_ID__c= allPBEs.get(pbeIdscleaned[idx]).substring(0,17);
} else {
curr.acc.zz_Previous_OLI_ID__c= allPBEs.get(pbeIdscleaned[idx]);
}
*/
curr.acc.UnitPrice = 1;
curr.acc.OpportunityId = opptyId ;
wrappers.add(curr );
}
oppty = [select id, Name from Opportunity where id = :opptyId];
/*
olis = [select Id,
Name,
Quantity,
TotalQtyHelper__c,
Duration_months__c,
Unit_Margin__c,
Units_for_Quantity__c,
Qty_month__c,
Unit_Cost__c,
UnitPrice,
TotalPrice,
Total_Cost__c,
ServiceDate,
Invoice_Date__c,
Description,
CurrencyIsoCode
from OpportunityLineItem
where id in : pbeIdscleaned];
*/
//qtyToQtyHelper();
}
public PageReference save() {
List<OpportunityLineItem > accs=new List<OpportunityLineItem >();
for (OLIWrapper wrap : wrappers)
{
wrap.acc.Quantity = wrap.acc.TotalQtyHelper__c;
accs.add(wrap.acc);
}
System.debug('olis:' + accs);
insert accs;
showReload = true;
//return new PageReference('/' + opptyId);
return null;
}
public PageReference cancel() {
return new PageReference('/' + opptyId);
}
public class OLIWrapper
{
public OpportunityLineItem acc {get; private set;}
public Integer ident {get; private set;}
public String productName {get; set;}
public OLIWrapper(Integer inIdent)
{
ident=inIdent;
acc=new OpportunityLineItem (description = String.valueOf(ident));
}
}
// TotalQtyHelper__c allows to leave the field blank where Quantity can't be blank
private void qtyToQtyHelper() {
for (OpportunityLineItem oli : olis) {
oli.TotalQtyHelper__c = oli.Quantity;
}
}
}
Test class:
@isTest
private class OpportunityLineItemMultiInsertTest {
private static OpportunityLineItem opptyLineItemObj;
private static Opportunity opportunityObj;
private static List<OpportunityLineItem> oliList ;
private static void setData() {
Account accountObj = (Account)TestDataHelper.createSObject('Account');
accountObj.SAP_id__c='0011254999';
accountObj.BillingCity = 'pune' ;
accountObj.BillingStreet = 'bhel chowk' ;
accountObj.BillingCountry = 'india' ;
accountObj.BillingPostalCode = '345210' ;
insert accountObj;
Organization__c organizationObj = (Organization__c)TestDataHelper.createSObject('Organization__c');
//organizationObj.Active__c = true;
insert organizationObj;
RecordType rec = [Select id,name from recordtype where developername = 'Solution'];
Product2 prod = new Product2(Name = 'Laptop X200',
Family = '2_PLA_BUSS',
Hierarchy_Level__c = 'SKU',
ProductCode = 'abc123',
CanUseRevenueSchedule=true,
CanUseQuantitySchedule=true,
recordtypeId = rec.id
);
insert prod;
/* RecordType rec = [Select id,name from recordtype where developername = 'Solution'];
Product2 prod1 = new Product2(Name = 'Laptop X200',
Family = '2_PLA_BUSS',
Hierarchy_Level__c = 'SKU',
ProductCode = 'abc123',
CanUseRevenueSchedule=true,
CanUseQuantitySchedule=true,
recordtypeId = rec.id
);
insert prod1;
*/
Id pricebookId = Test.getStandardPricebookId();
PricebookEntry standardPBE = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = prod.Id,
UnitPrice = 10000, IsActive = true,UseStandardPrice = true);
system.debug(standardPBE);
insert standardPBE;
//List<PricebookEntry> pbe = [select id, name, CurrencyIsoCode from PriceBookEntry where Pricebook2id =: 'VALUE' and Product2.Id in: VALUE.keySet() ];
/*PricebookEntry standardPBE1 = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = prod1.Id,
UnitPrice = 10000, IsActive = true);
insert standardPBE1;
*/
opportunityObj = (Opportunity)TestDataHelper.createSObject('Opportunity');
opportunityObj.Accountid= accountObj.id;
opportunityObj.Pricebook2Id=pricebookId;
opportunityObj.CurrencyIsoCode=standardPBE.CurrencyIsoCode;
opportunityObj.Organization__c=organizationObj.id;
insert opportunityObj;
opportunityObj = (Opportunity)TestDataHelper.createSObject('Opportunity');
opportunityObj.Accountid= accountObj.id;
opportunityObj.Pricebook2Id=pricebookId;
//opportunityObj.CurrencyIsoCode=standardPBE1.CurrencyIsoCode;
opportunityObj.Organization__c=organizationObj.id;
insert opportunityObj;
OpportunityTeamMember otm=new OpportunityTeamMember();
otm.userid=userinfo.getuserid();
otm.TeamMemberRole='High Level';
otm.opportunityid=opportunityObj.id;
otm.Lead_Type__c='Test Lead';
insert otm;
oliList = new List<OpportunityLineItem>();
for(integer i = 0; i<= 5; i++) {
opptyLineItemObj = new OpportunityLineItem();
opptyLineItemObj.Quantity=1;
opptyLineItemObj.Oppty_Team_Members__c ='['+ otm.User.Name +','+ otm.Lead_Type__c +']';
opptyLineItemObj.TotalPrice=500;
opptyLineItemObj.Delivery_Date_Start__c = system.today().addDays(5);
opptyLineItemObj.Delivery_Date_Last__c = system.today().addDays(7);
opptyLineItemObj.Revenue_Date_Last__c = system.today().addDays(5);
opptyLineItemObj.Revenue_Date_Start__c = system.today().addDays(7);
opptyLineItemObj.Quote_Package_Name__c = 'packageName';
//opptyLineItemObj.HasSchedule = true;
opptyLineItemObj.PricebookEntryId=standardPBE.id;
// opptyLineItemObj.PricebookEntryId=standardPBE1.id;
opptyLineItemObj.opportunityid=opportunityObj.id;
opptyLineItemObj.ServiceDate = system.today().addDays(5);
opptyLineItemObj.Invoice_Date__c = system.today().addDays(5);
oliList.add(opptyLineItemObj);
}
insert oliList;
}
static testmethod void testInsertOLI() {
setData();
/*
List<OpportunityLineItem> olis = new List<OpportunityLineItem>();
List<PricebookEntry> pbe = new List<PricebookEntry>();
Opportunity oppty = TestDataHelper.createOpptyWithOfferings('Product',olis);
*/
string oliIds = '';
for (OpportunityLineItem oli : oliList) {
oliIds = oliIds + ',' + oli.id;
}
oliIds = oliIds.substring(1);
Test.startTest();
ApexPages.currentPage().getParameters().put('opptyid',opportunityObj.id);
ApexPages.currentPage().getParameters().put('ids',oliIds);
OpportunityLineItemMultiInsert ctr = new OpportunityLineItemMultiInsert();
ctr.save();
ctr.cancel();
//ctr.qtyToQtyHelper();
ctr.olis = oliList;
Boolean testValue;
if(ctr != null){
testValue = true;
}
System.assert(testValue);
}
}
Any help will be appreciated
Thanks,
Haneef
- Haneef S
- October 15, 2018
- Like
- 0
- Continue reading or reply
Error while displaying list of accounts in lightning
Hi Team,
I need to Create an application which displays all the accounts in my org. But i am getting below error, can some one please help.
Here is my code:
DisplayAllaccounts.app
<aura:application >
<c:DisplayAllAccountscomp />
</aura:application>
DisplayAllAccountsComp.cmp
<aura:component controller="displayAccounts">
<aura:attribute name="accountrows" type="object[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit1}"/>
<div class="container">
<p>
<b> List of Contacts </b>
</p>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th><strong> Id </strong></th>
<th> <strong> Name </strong> </th>
</tr>
</thead>
<tbody>
<aura:iteration var="cell" items="{!v.accountrows}">
<tr>
<td> <a href="{! '/'+cell.Id}"> {!cell.Id} </a> </td>
<td> {!cell.Name} </td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</aura:component>
DisplayAllAccountshelper.js
({
getallaccounts : function(component, event,helper) {
var action1 = component.get("c.getaccounts");
action1.setcallback(this,function(a){
component.set("v.accountrows",a.getReturnValue());
});
$A.enqueueAction(action1);
}
})
DisplayAllAccountsController.js
({
doInit1 : function(component, event, helper) {
helper.getallaccounts(component);
}
})
I am getting below error:
I need to Create an application which displays all the accounts in my org. But i am getting below error, can some one please help.
Here is my code:
DisplayAllaccounts.app
<aura:application >
<c:DisplayAllAccountscomp />
</aura:application>
DisplayAllAccountsComp.cmp
<aura:component controller="displayAccounts">
<aura:attribute name="accountrows" type="object[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit1}"/>
<div class="container">
<p>
<b> List of Contacts </b>
</p>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th><strong> Id </strong></th>
<th> <strong> Name </strong> </th>
</tr>
</thead>
<tbody>
<aura:iteration var="cell" items="{!v.accountrows}">
<tr>
<td> <a href="{! '/'+cell.Id}"> {!cell.Id} </a> </td>
<td> {!cell.Name} </td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</aura:component>
DisplayAllAccountshelper.js
({
getallaccounts : function(component, event,helper) {
var action1 = component.get("c.getaccounts");
action1.setcallback(this,function(a){
component.set("v.accountrows",a.getReturnValue());
});
$A.enqueueAction(action1);
}
})
DisplayAllAccountsController.js
({
doInit1 : function(component, event, helper) {
helper.getallaccounts(component);
}
})
I am getting below error:
- Haneef S
- July 19, 2018
- Like
- 0
- Continue reading or reply
Post an attachment on a chatter group automatically using Trigger
Hello All,
I have a requirement to write a trigger and also I am new to salesforce.
Can anyone pls help me
Requirement is:
I have custom object say test__c which is also having notes and attachments related list on it.
when a field called "state__c" is updated to "complete" on test__c object then an attachment(in notes & attchments section) starting with "abc-xxxx" needs to be posted automatically in a group called "my chatter".
My code is:
trigger AttachmentTriggger on Attachment (after insert) {
Map<Id,Id> testAttachmentMap = new Map<Id,Id>();
set<Id> testIds = new set<Id>();
for(Attachment att : Trigger.New)
{
if(att.ParentId.getSobjectType() == test__c.SobjectType){
accountAttachmentMap.put(att.ParentId,att.Id);
}
}
//fetching the account to check the condition
List<test__c> testList = new List<test__c>();
testList =[select id,state from test__c where Id IN : testAttachmentMap.keySet()];
//checking if account is meting the required condition
for(test__c testatt : testList){
if(testatt.state='completed'){
testIds.add(testatt.Id);
}
//add code here to post attachments in group
}
Any help much appreciated.
Thanks
I have a requirement to write a trigger and also I am new to salesforce.
Can anyone pls help me
Requirement is:
I have custom object say test__c which is also having notes and attachments related list on it.
when a field called "state__c" is updated to "complete" on test__c object then an attachment(in notes & attchments section) starting with "abc-xxxx" needs to be posted automatically in a group called "my chatter".
My code is:
trigger AttachmentTriggger on Attachment (after insert) {
Map<Id,Id> testAttachmentMap = new Map<Id,Id>();
set<Id> testIds = new set<Id>();
for(Attachment att : Trigger.New)
{
if(att.ParentId.getSobjectType() == test__c.SobjectType){
accountAttachmentMap.put(att.ParentId,att.Id);
}
}
//fetching the account to check the condition
List<test__c> testList = new List<test__c>();
testList =[select id,state from test__c where Id IN : testAttachmentMap.keySet()];
//checking if account is meting the required condition
for(test__c testatt : testList){
if(testatt.state='completed'){
testIds.add(testatt.Id);
}
//add code here to post attachments in group
}
Any help much appreciated.
Thanks
- Haneef S
- July 03, 2018
- Like
- 0
- Continue reading or reply
Add contacts as a campaign member when the field on account is populated for first time.
Hi Team,
Can someone please help me with below requirement.
When a specific field on account is populated for the first time, its active contacts should get added on campaign(contact country same as campaign country)as campaign member.
Thanks
Can someone please help me with below requirement.
When a specific field on account is populated for the first time, its active contacts should get added on campaign(contact country same as campaign country)as campaign member.
Thanks
- Haneef S
- November 14, 2019
- Like
- 0
- Continue reading or reply
insert a new record using custom button
Hi All,
I am new to lightning, can some one please help me with the below code:
I have my existing code that displays accounts and when clicked particular account it shows its own contacts.
Now, on the same page there should be one button for Add Account. On click of this button, popup will ask for account details and after click on submit button this new account will add to database, go to previous page and previous page also will refresh.
when I click on preview I get below error:
Below is my code:
component:
<aura:component controller="AccountPagination" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<ltng:require styles="/resource/SLDS244/styles/salesforce-lightning-design-system.css" />
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<h1 class="slds-text-heading--medium">Accounts List</h1>
</div>
</div>
</div>
<aura:attribute name="acccountList" type="Account[]" />
<aura:attribute name="contacts" type="Contact[]"/>
<aura:attribute name="paginationList" type="Account[]"/>
<aura:attribute name="pageSize" type="Integer" default="15"/>
<aura:attribute name="totalSize" type="Integer"/>
<aura:attribute name="start" type="Integer" />
<aura:attribute name="end" type="Integer"/>
<table class="slds-table slds-table--bordered ">
<thead>
<tr style="color:Grey;font-weight:bold">
<!--<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading-/-medium">Id</h1></th>
</div>
</div>
</div></td>-->
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Name</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">AccountNumber</h1></th>
</div>
</div>
</div></td>
<!--<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading-/-medium">AccountOwnerId</h1></th>
</div>
</div>
</div></td>-->
<!--<th>Id</th>
<th>Name</th>
<th>Phone</th>
<th>AccountNumber</th>
<th>BillingAddress</th>-->
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.paginationList}" var="item">
<tr>
<!--<td><lightning:input value="{!item.Id}"/></td>
<td><lightning:input value="{!item.Name}"/></td>
<td><lightning:input value="{!item.AccountNumber}"/></td>
<td><lightning:input value="{!item.OwnerId}"/></td>
<td><lightning:input value="{!item.Owner.Name}"/></td>-->
<!--<td><ui:outputText value="{!item.Id}" /></td>-->
<td><a href="javascript:void(0);" onclick="{!c.Clicked}" data-value="{!item.Id}">{!item.Name}
</a></td>
<td><ui:outputText value="{!item.AccountNumber}"/></td>
<!--<td><ui:outputText value="{!item.OwnerId}"/></td>-->
</tr>
</aura:iteration>
<!-- <lightning:button label="Previous" disabled="{!v.start == 0}" onclick="{!c.previous}" />
<lightning:button label="Next" disabled="{!v.end >= v.totalSize}" onclick="{!c.next}" />-->
</tbody>
</table>
<lightning:button label="Previous" disabled="{!v.start == 0}" onclick="{!c.previous}" />
<lightning:button label="Next" disabled="{!v.end >= v.totalSize}" onclick="{!c.next}" />
<lightning:button label="Create New account" onclick="{!c.createRecord}" />
<div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<h1 class="slds-text-heading--medium">Contacts associated with account</h1>
</div>
</div>
</div>
<table class="slds-table slds-table--bordered ">
<thead>
<tr style="color:Grey;font-weight:bold">
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Contact Id</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Contact Name</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Account Id</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Account Name</h1></th>
</div>
</div>
</div></td>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.contacts}" var="con">
<tr>
<td><ui:outputText value="{!con.Id}" /></td>
<td><ui:outputText value="{!con.Name}" /></td>
<td><ui:outputText value="{!con.AccountId}" /></td>
<td><ui:outputText value="{!con.Account.Name}" /></td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
Accountpaginationcontroller.js
({
doInit : function(component, event, helper)
{
var pageSize = component.get("v.pageSize");
var action = component.get("c.getAccounts");
action.setCallback(this, function(response)
{
var state = response.getState();
if (component.isValid() && state === "SUCCESS")
{
console.log(response.getReturnValue());
component.set('v.acccountList', response.getReturnValue());
component.set("v.totalSize", component.get("v.acccountList").length);
component.set("v.start",0);
component.set("v.end",pageSize-1);
var paginationList = [];
for(var i=0; i< pageSize; i++)
{
paginationList.push(response.getReturnValue()[i]);
}
component.set('v.paginationList', paginationList);
}
});
$A.enqueueAction(action);
},
next : function(component, event, helper)
{
var accountList = component.get("v.acccountList");
var end = component.get("v.end");
var start = component.get("v.start");
var pageSize = component.get("v.pageSize");
var paginationList = [];
var counter = 0;
for(var i=end+1; i<end+pageSize+1; i++)
{
if(accountList.length > end)
{
paginationList.push(accountList[i]);
counter ++ ;
}
}
start = start + counter;
end = end + counter;
component.set("v.start",start);
component.set("v.end",end);
component.set('v.paginationList', paginationList);
},
previous : function(component, event, helper)
{
var accountList = component.get("v.acccountList");
var end = component.get("v.end");
var start = component.get("v.start");
var pageSize = component.get("v.pageSize");
var paginationList = [];
var counter = 0;
for(var i= start-pageSize; i < start ; i++)
{
if(i > -1)
{
paginationList.push(accountList[i]);
counter ++;
}
else
{
start++;
}
}
start = start - counter;
end = end - counter;
component.set("v.start",start);
component.set("v.end",end);
component.set('v.paginationList', paginationList);
},
Clicked : function(component, event, helper){
var ctarget = event.currentTarget;
var id_str = ctarget.dataset.value;
console.log(id_str);
var action = component.get("c.getContactRecords");
action.setParams({ accId : id_str});
action.setCallback(this, function(response) {
var state = response.getState(); //Checking response status
console.log("contactsss... "+JSON.stringify(response.getReturnValue()));
if (component.isValid() && state === "SUCCESS"){
if(response.getReturnValue() !=''){
component.set("v.contacts", response.getReturnValue());
}
else{
alert('contacts are not available for this account');
// Adding values in Aura attribute variable.
}
} });
$A.enqueueAction(action);
},
createRecord: function(component, event, helper) {
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Account" // using account standard object for this sample
});
createRecordEvent.fire();
}
})
accountpagination.apxc
public with sharing class AccountPagination
{
/*@AuraEnabled
public static List<Account> getAccounts()
{
List<Account> accs = [SELECT Id, Name,Phone,AccountNumber,BillingAddress,Fax,OwnerId,Owner.Name,(SELECT Id,FirstName,LastName,Email from contacts) FROM Account];
return accs;
}*/
@AuraEnabled
public static List<Account> getAccounts() {
return new List<Account>([SELECT Id, Name,Phone,AccountNumber,BillingAddress,Fax,OwnerId,Owner.Name FROM Account]);
}
@AuraEnabled
public static List<Contact> getContactRecords(string accId) {
return new List<Contact>([Select id,Name,Account.Name,AccountId from Contact Where AccountId =: accId LIMIT 100]);
}
}
accountpaginationapp.app:
<aura:application >
<c:AccountPagination/>
</aura:application>
Can anyone please help
I am new to lightning, can some one please help me with the below code:
I have my existing code that displays accounts and when clicked particular account it shows its own contacts.
Now, on the same page there should be one button for Add Account. On click of this button, popup will ask for account details and after click on submit button this new account will add to database, go to previous page and previous page also will refresh.
when I click on preview I get below error:
Below is my code:
component:
<aura:component controller="AccountPagination" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<ltng:require styles="/resource/SLDS244/styles/salesforce-lightning-design-system.css" />
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<h1 class="slds-text-heading--medium">Accounts List</h1>
</div>
</div>
</div>
<aura:attribute name="acccountList" type="Account[]" />
<aura:attribute name="contacts" type="Contact[]"/>
<aura:attribute name="paginationList" type="Account[]"/>
<aura:attribute name="pageSize" type="Integer" default="15"/>
<aura:attribute name="totalSize" type="Integer"/>
<aura:attribute name="start" type="Integer" />
<aura:attribute name="end" type="Integer"/>
<table class="slds-table slds-table--bordered ">
<thead>
<tr style="color:Grey;font-weight:bold">
<!--<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading-/-medium">Id</h1></th>
</div>
</div>
</div></td>-->
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Name</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">AccountNumber</h1></th>
</div>
</div>
</div></td>
<!--<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading-/-medium">AccountOwnerId</h1></th>
</div>
</div>
</div></td>-->
<!--<th>Id</th>
<th>Name</th>
<th>Phone</th>
<th>AccountNumber</th>
<th>BillingAddress</th>-->
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.paginationList}" var="item">
<tr>
<!--<td><lightning:input value="{!item.Id}"/></td>
<td><lightning:input value="{!item.Name}"/></td>
<td><lightning:input value="{!item.AccountNumber}"/></td>
<td><lightning:input value="{!item.OwnerId}"/></td>
<td><lightning:input value="{!item.Owner.Name}"/></td>-->
<!--<td><ui:outputText value="{!item.Id}" /></td>-->
<td><a href="javascript:void(0);" onclick="{!c.Clicked}" data-value="{!item.Id}">{!item.Name}
</a></td>
<td><ui:outputText value="{!item.AccountNumber}"/></td>
<!--<td><ui:outputText value="{!item.OwnerId}"/></td>-->
</tr>
</aura:iteration>
<!-- <lightning:button label="Previous" disabled="{!v.start == 0}" onclick="{!c.previous}" />
<lightning:button label="Next" disabled="{!v.end >= v.totalSize}" onclick="{!c.next}" />-->
</tbody>
</table>
<lightning:button label="Previous" disabled="{!v.start == 0}" onclick="{!c.previous}" />
<lightning:button label="Next" disabled="{!v.end >= v.totalSize}" onclick="{!c.next}" />
<lightning:button label="Create New account" onclick="{!c.createRecord}" />
<div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<h1 class="slds-text-heading--medium">Contacts associated with account</h1>
</div>
</div>
</div>
<table class="slds-table slds-table--bordered ">
<thead>
<tr style="color:Grey;font-weight:bold">
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Contact Id</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Contact Name</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Account Id</h1></th>
</div>
</div>
</div></td>
<td> <div class="slds-page-header" role="banner" >
<div class="slds-grid">
<div class="slds-col" >
<th><h1 class="slds-text-heading--medium">Account Name</h1></th>
</div>
</div>
</div></td>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.contacts}" var="con">
<tr>
<td><ui:outputText value="{!con.Id}" /></td>
<td><ui:outputText value="{!con.Name}" /></td>
<td><ui:outputText value="{!con.AccountId}" /></td>
<td><ui:outputText value="{!con.Account.Name}" /></td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
Accountpaginationcontroller.js
({
doInit : function(component, event, helper)
{
var pageSize = component.get("v.pageSize");
var action = component.get("c.getAccounts");
action.setCallback(this, function(response)
{
var state = response.getState();
if (component.isValid() && state === "SUCCESS")
{
console.log(response.getReturnValue());
component.set('v.acccountList', response.getReturnValue());
component.set("v.totalSize", component.get("v.acccountList").length);
component.set("v.start",0);
component.set("v.end",pageSize-1);
var paginationList = [];
for(var i=0; i< pageSize; i++)
{
paginationList.push(response.getReturnValue()[i]);
}
component.set('v.paginationList', paginationList);
}
});
$A.enqueueAction(action);
},
next : function(component, event, helper)
{
var accountList = component.get("v.acccountList");
var end = component.get("v.end");
var start = component.get("v.start");
var pageSize = component.get("v.pageSize");
var paginationList = [];
var counter = 0;
for(var i=end+1; i<end+pageSize+1; i++)
{
if(accountList.length > end)
{
paginationList.push(accountList[i]);
counter ++ ;
}
}
start = start + counter;
end = end + counter;
component.set("v.start",start);
component.set("v.end",end);
component.set('v.paginationList', paginationList);
},
previous : function(component, event, helper)
{
var accountList = component.get("v.acccountList");
var end = component.get("v.end");
var start = component.get("v.start");
var pageSize = component.get("v.pageSize");
var paginationList = [];
var counter = 0;
for(var i= start-pageSize; i < start ; i++)
{
if(i > -1)
{
paginationList.push(accountList[i]);
counter ++;
}
else
{
start++;
}
}
start = start - counter;
end = end - counter;
component.set("v.start",start);
component.set("v.end",end);
component.set('v.paginationList', paginationList);
},
Clicked : function(component, event, helper){
var ctarget = event.currentTarget;
var id_str = ctarget.dataset.value;
console.log(id_str);
var action = component.get("c.getContactRecords");
action.setParams({ accId : id_str});
action.setCallback(this, function(response) {
var state = response.getState(); //Checking response status
console.log("contactsss... "+JSON.stringify(response.getReturnValue()));
if (component.isValid() && state === "SUCCESS"){
if(response.getReturnValue() !=''){
component.set("v.contacts", response.getReturnValue());
}
else{
alert('contacts are not available for this account');
// Adding values in Aura attribute variable.
}
} });
$A.enqueueAction(action);
},
createRecord: function(component, event, helper) {
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Account" // using account standard object for this sample
});
createRecordEvent.fire();
}
})
accountpagination.apxc
public with sharing class AccountPagination
{
/*@AuraEnabled
public static List<Account> getAccounts()
{
List<Account> accs = [SELECT Id, Name,Phone,AccountNumber,BillingAddress,Fax,OwnerId,Owner.Name,(SELECT Id,FirstName,LastName,Email from contacts) FROM Account];
return accs;
}*/
@AuraEnabled
public static List<Account> getAccounts() {
return new List<Account>([SELECT Id, Name,Phone,AccountNumber,BillingAddress,Fax,OwnerId,Owner.Name FROM Account]);
}
@AuraEnabled
public static List<Contact> getContactRecords(string accId) {
return new List<Contact>([Select id,Name,Account.Name,AccountId from Contact Where AccountId =: accId LIMIT 100]);
}
}
accountpaginationapp.app:
<aura:application >
<c:AccountPagination/>
</aura:application>
Can anyone please help
- Haneef S
- October 24, 2018
- Like
- 0
- Continue reading or reply
I am facing error for the below test class
I have created test class and facing below exception:
Error:System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: []
stacktrace:
Class.OpportunityLineItemMultiInsertTest.setData: line 54, column 1
Class.OpportunityLineItemMultiInsertTest.testInsertOLI: line 112, column 1
Apex class:
public class OpportunityLineItemMultiInsert{
public List<OLIWrapper> wrappers {get; set;}
public List<OpportunityLineItem> olis {get; set;}
public Opportunity oppty {get; set;}
public String opportunityId {get; set;}
private Id opptyId ;
private List<string> pbeIds;
private List<string> pbeIdscleaned;
public static Integer toDelIdent {get; set;}
public static Integer addCount {get; set;}
private Integer nextIdent=0;
public Boolean showReload {get; set;}
public OpportunityLineItemMultiInsert() {
opportunityId = ApexPages.currentPage().getParameters().get('opptyid');
showReload = false;
opptyId = ApexPages.currentPage().getParameters().get('opptyid');
pbeIds = ApexPages.currentPage().getParameters().get('ids').split(',');
pbeIdscleaned = new List<string>();
for (String currIdent : pbeIds ) {
if (currIdent != '') {
pbeIdscleaned.add(currIdent);
}
}
Map<Id, String> allPBEs = new Map<Id, String>();
for (PricebookEntry currPBEc : [select id, Name, UnitPrice from PricebookEntry where id in :pbeIdscleaned]) {
allPBEs.put(currPBEc.Id, currPBEc.Name);
}
wrappers=new List<OLIWrapper>();
//nextIdent = pbeIds.size()+1;
for (Integer idx=0; idx<pbeIdscleaned.size(); idx++)
{
OLIWrapper curr = new OLIWrapper(nextIdent++);
curr.acc.PricebookEntryId = pbeIdscleaned[idx]; //'01u24000004Nq7yAAC';
curr.productName = allPBEs.get(pbeIdscleaned[idx]);
/*
if (allPBEs.get(pbeIdscleaned[idx]).length() > 17) {
curr.acc.zz_Previous_OLI_ID__c= allPBEs.get(pbeIdscleaned[idx]).substring(0,17);
} else {
curr.acc.zz_Previous_OLI_ID__c= allPBEs.get(pbeIdscleaned[idx]);
}
*/
curr.acc.UnitPrice = 1;
curr.acc.OpportunityId = opptyId ;
wrappers.add(curr );
}
oppty = [select id, Name from Opportunity where id = :opptyId];
/*
olis = [select Id,
Name,
Quantity,
TotalQtyHelper__c,
Duration_months__c,
Unit_Margin__c,
Units_for_Quantity__c,
Qty_month__c,
Unit_Cost__c,
UnitPrice,
TotalPrice,
Total_Cost__c,
ServiceDate,
Invoice_Date__c,
Description,
CurrencyIsoCode
from OpportunityLineItem
where id in : pbeIdscleaned];
*/
//qtyToQtyHelper();
}
public PageReference save() {
List<OpportunityLineItem > accs=new List<OpportunityLineItem >();
for (OLIWrapper wrap : wrappers)
{
wrap.acc.Quantity = wrap.acc.TotalQtyHelper__c;
accs.add(wrap.acc);
}
System.debug('olis:' + accs);
insert accs;
showReload = true;
//return new PageReference('/' + opptyId);
return null;
}
public PageReference cancel() {
return new PageReference('/' + opptyId);
}
public class OLIWrapper
{
public OpportunityLineItem acc {get; private set;}
public Integer ident {get; private set;}
public String productName {get; set;}
public OLIWrapper(Integer inIdent)
{
ident=inIdent;
acc=new OpportunityLineItem (description = String.valueOf(ident));
}
}
// TotalQtyHelper__c allows to leave the field blank where Quantity can't be blank
private void qtyToQtyHelper() {
for (OpportunityLineItem oli : olis) {
oli.TotalQtyHelper__c = oli.Quantity;
}
}
}
Test class:
@isTest
private class OpportunityLineItemMultiInsertTest {
private static OpportunityLineItem opptyLineItemObj;
private static Opportunity opportunityObj;
private static List<OpportunityLineItem> oliList ;
private static void setData() {
Account accountObj = (Account)TestDataHelper.createSObject('Account');
accountObj.SAP_id__c='0011254999';
accountObj.BillingCity = 'pune' ;
accountObj.BillingStreet = 'bhel chowk' ;
accountObj.BillingCountry = 'india' ;
accountObj.BillingPostalCode = '345210' ;
insert accountObj;
Organization__c organizationObj = (Organization__c)TestDataHelper.createSObject('Organization__c');
//organizationObj.Active__c = true;
insert organizationObj;
RecordType rec = [Select id,name from recordtype where developername = 'Solution'];
Product2 prod = new Product2(Name = 'Laptop X200',
Family = '2_PLA_BUSS',
Hierarchy_Level__c = 'SKU',
ProductCode = 'abc123',
CanUseRevenueSchedule=true,
CanUseQuantitySchedule=true,
recordtypeId = rec.id
);
insert prod;
/* RecordType rec = [Select id,name from recordtype where developername = 'Solution'];
Product2 prod1 = new Product2(Name = 'Laptop X200',
Family = '2_PLA_BUSS',
Hierarchy_Level__c = 'SKU',
ProductCode = 'abc123',
CanUseRevenueSchedule=true,
CanUseQuantitySchedule=true,
recordtypeId = rec.id
);
insert prod1;
*/
Id pricebookId = Test.getStandardPricebookId();
PricebookEntry standardPBE = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = prod.Id,
UnitPrice = 10000, IsActive = true,UseStandardPrice = true);
system.debug(standardPBE);
insert standardPBE;
//List<PricebookEntry> pbe = [select id, name, CurrencyIsoCode from PriceBookEntry where Pricebook2id =: 'VALUE' and Product2.Id in: VALUE.keySet() ];
/*PricebookEntry standardPBE1 = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = prod1.Id,
UnitPrice = 10000, IsActive = true);
insert standardPBE1;
*/
opportunityObj = (Opportunity)TestDataHelper.createSObject('Opportunity');
opportunityObj.Accountid= accountObj.id;
opportunityObj.Pricebook2Id=pricebookId;
opportunityObj.CurrencyIsoCode=standardPBE.CurrencyIsoCode;
opportunityObj.Organization__c=organizationObj.id;
insert opportunityObj;
opportunityObj = (Opportunity)TestDataHelper.createSObject('Opportunity');
opportunityObj.Accountid= accountObj.id;
opportunityObj.Pricebook2Id=pricebookId;
//opportunityObj.CurrencyIsoCode=standardPBE1.CurrencyIsoCode;
opportunityObj.Organization__c=organizationObj.id;
insert opportunityObj;
OpportunityTeamMember otm=new OpportunityTeamMember();
otm.userid=userinfo.getuserid();
otm.TeamMemberRole='High Level';
otm.opportunityid=opportunityObj.id;
otm.Lead_Type__c='Test Lead';
insert otm;
oliList = new List<OpportunityLineItem>();
for(integer i = 0; i<= 5; i++) {
opptyLineItemObj = new OpportunityLineItem();
opptyLineItemObj.Quantity=1;
opptyLineItemObj.Oppty_Team_Members__c ='['+ otm.User.Name +','+ otm.Lead_Type__c +']';
opptyLineItemObj.TotalPrice=500;
opptyLineItemObj.Delivery_Date_Start__c = system.today().addDays(5);
opptyLineItemObj.Delivery_Date_Last__c = system.today().addDays(7);
opptyLineItemObj.Revenue_Date_Last__c = system.today().addDays(5);
opptyLineItemObj.Revenue_Date_Start__c = system.today().addDays(7);
opptyLineItemObj.Quote_Package_Name__c = 'packageName';
//opptyLineItemObj.HasSchedule = true;
opptyLineItemObj.PricebookEntryId=standardPBE.id;
// opptyLineItemObj.PricebookEntryId=standardPBE1.id;
opptyLineItemObj.opportunityid=opportunityObj.id;
opptyLineItemObj.ServiceDate = system.today().addDays(5);
opptyLineItemObj.Invoice_Date__c = system.today().addDays(5);
oliList.add(opptyLineItemObj);
}
insert oliList;
}
static testmethod void testInsertOLI() {
setData();
/*
List<OpportunityLineItem> olis = new List<OpportunityLineItem>();
List<PricebookEntry> pbe = new List<PricebookEntry>();
Opportunity oppty = TestDataHelper.createOpptyWithOfferings('Product',olis);
*/
string oliIds = '';
for (OpportunityLineItem oli : oliList) {
oliIds = oliIds + ',' + oli.id;
}
oliIds = oliIds.substring(1);
Test.startTest();
ApexPages.currentPage().getParameters().put('opptyid',opportunityObj.id);
ApexPages.currentPage().getParameters().put('ids',oliIds);
OpportunityLineItemMultiInsert ctr = new OpportunityLineItemMultiInsert();
ctr.save();
ctr.cancel();
//ctr.qtyToQtyHelper();
ctr.olis = oliList;
Boolean testValue;
if(ctr != null){
testValue = true;
}
System.assert(testValue);
}
}
Any help will be appreciated
Thanks,
Haneef
Error:System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: []
stacktrace:
Class.OpportunityLineItemMultiInsertTest.setData: line 54, column 1
Class.OpportunityLineItemMultiInsertTest.testInsertOLI: line 112, column 1
Apex class:
public class OpportunityLineItemMultiInsert{
public List<OLIWrapper> wrappers {get; set;}
public List<OpportunityLineItem> olis {get; set;}
public Opportunity oppty {get; set;}
public String opportunityId {get; set;}
private Id opptyId ;
private List<string> pbeIds;
private List<string> pbeIdscleaned;
public static Integer toDelIdent {get; set;}
public static Integer addCount {get; set;}
private Integer nextIdent=0;
public Boolean showReload {get; set;}
public OpportunityLineItemMultiInsert() {
opportunityId = ApexPages.currentPage().getParameters().get('opptyid');
showReload = false;
opptyId = ApexPages.currentPage().getParameters().get('opptyid');
pbeIds = ApexPages.currentPage().getParameters().get('ids').split(',');
pbeIdscleaned = new List<string>();
for (String currIdent : pbeIds ) {
if (currIdent != '') {
pbeIdscleaned.add(currIdent);
}
}
Map<Id, String> allPBEs = new Map<Id, String>();
for (PricebookEntry currPBEc : [select id, Name, UnitPrice from PricebookEntry where id in :pbeIdscleaned]) {
allPBEs.put(currPBEc.Id, currPBEc.Name);
}
wrappers=new List<OLIWrapper>();
//nextIdent = pbeIds.size()+1;
for (Integer idx=0; idx<pbeIdscleaned.size(); idx++)
{
OLIWrapper curr = new OLIWrapper(nextIdent++);
curr.acc.PricebookEntryId = pbeIdscleaned[idx]; //'01u24000004Nq7yAAC';
curr.productName = allPBEs.get(pbeIdscleaned[idx]);
/*
if (allPBEs.get(pbeIdscleaned[idx]).length() > 17) {
curr.acc.zz_Previous_OLI_ID__c= allPBEs.get(pbeIdscleaned[idx]).substring(0,17);
} else {
curr.acc.zz_Previous_OLI_ID__c= allPBEs.get(pbeIdscleaned[idx]);
}
*/
curr.acc.UnitPrice = 1;
curr.acc.OpportunityId = opptyId ;
wrappers.add(curr );
}
oppty = [select id, Name from Opportunity where id = :opptyId];
/*
olis = [select Id,
Name,
Quantity,
TotalQtyHelper__c,
Duration_months__c,
Unit_Margin__c,
Units_for_Quantity__c,
Qty_month__c,
Unit_Cost__c,
UnitPrice,
TotalPrice,
Total_Cost__c,
ServiceDate,
Invoice_Date__c,
Description,
CurrencyIsoCode
from OpportunityLineItem
where id in : pbeIdscleaned];
*/
//qtyToQtyHelper();
}
public PageReference save() {
List<OpportunityLineItem > accs=new List<OpportunityLineItem >();
for (OLIWrapper wrap : wrappers)
{
wrap.acc.Quantity = wrap.acc.TotalQtyHelper__c;
accs.add(wrap.acc);
}
System.debug('olis:' + accs);
insert accs;
showReload = true;
//return new PageReference('/' + opptyId);
return null;
}
public PageReference cancel() {
return new PageReference('/' + opptyId);
}
public class OLIWrapper
{
public OpportunityLineItem acc {get; private set;}
public Integer ident {get; private set;}
public String productName {get; set;}
public OLIWrapper(Integer inIdent)
{
ident=inIdent;
acc=new OpportunityLineItem (description = String.valueOf(ident));
}
}
// TotalQtyHelper__c allows to leave the field blank where Quantity can't be blank
private void qtyToQtyHelper() {
for (OpportunityLineItem oli : olis) {
oli.TotalQtyHelper__c = oli.Quantity;
}
}
}
Test class:
@isTest
private class OpportunityLineItemMultiInsertTest {
private static OpportunityLineItem opptyLineItemObj;
private static Opportunity opportunityObj;
private static List<OpportunityLineItem> oliList ;
private static void setData() {
Account accountObj = (Account)TestDataHelper.createSObject('Account');
accountObj.SAP_id__c='0011254999';
accountObj.BillingCity = 'pune' ;
accountObj.BillingStreet = 'bhel chowk' ;
accountObj.BillingCountry = 'india' ;
accountObj.BillingPostalCode = '345210' ;
insert accountObj;
Organization__c organizationObj = (Organization__c)TestDataHelper.createSObject('Organization__c');
//organizationObj.Active__c = true;
insert organizationObj;
RecordType rec = [Select id,name from recordtype where developername = 'Solution'];
Product2 prod = new Product2(Name = 'Laptop X200',
Family = '2_PLA_BUSS',
Hierarchy_Level__c = 'SKU',
ProductCode = 'abc123',
CanUseRevenueSchedule=true,
CanUseQuantitySchedule=true,
recordtypeId = rec.id
);
insert prod;
/* RecordType rec = [Select id,name from recordtype where developername = 'Solution'];
Product2 prod1 = new Product2(Name = 'Laptop X200',
Family = '2_PLA_BUSS',
Hierarchy_Level__c = 'SKU',
ProductCode = 'abc123',
CanUseRevenueSchedule=true,
CanUseQuantitySchedule=true,
recordtypeId = rec.id
);
insert prod1;
*/
Id pricebookId = Test.getStandardPricebookId();
PricebookEntry standardPBE = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = prod.Id,
UnitPrice = 10000, IsActive = true,UseStandardPrice = true);
system.debug(standardPBE);
insert standardPBE;
//List<PricebookEntry> pbe = [select id, name, CurrencyIsoCode from PriceBookEntry where Pricebook2id =: 'VALUE' and Product2.Id in: VALUE.keySet() ];
/*PricebookEntry standardPBE1 = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = prod1.Id,
UnitPrice = 10000, IsActive = true);
insert standardPBE1;
*/
opportunityObj = (Opportunity)TestDataHelper.createSObject('Opportunity');
opportunityObj.Accountid= accountObj.id;
opportunityObj.Pricebook2Id=pricebookId;
opportunityObj.CurrencyIsoCode=standardPBE.CurrencyIsoCode;
opportunityObj.Organization__c=organizationObj.id;
insert opportunityObj;
opportunityObj = (Opportunity)TestDataHelper.createSObject('Opportunity');
opportunityObj.Accountid= accountObj.id;
opportunityObj.Pricebook2Id=pricebookId;
//opportunityObj.CurrencyIsoCode=standardPBE1.CurrencyIsoCode;
opportunityObj.Organization__c=organizationObj.id;
insert opportunityObj;
OpportunityTeamMember otm=new OpportunityTeamMember();
otm.userid=userinfo.getuserid();
otm.TeamMemberRole='High Level';
otm.opportunityid=opportunityObj.id;
otm.Lead_Type__c='Test Lead';
insert otm;
oliList = new List<OpportunityLineItem>();
for(integer i = 0; i<= 5; i++) {
opptyLineItemObj = new OpportunityLineItem();
opptyLineItemObj.Quantity=1;
opptyLineItemObj.Oppty_Team_Members__c ='['+ otm.User.Name +','+ otm.Lead_Type__c +']';
opptyLineItemObj.TotalPrice=500;
opptyLineItemObj.Delivery_Date_Start__c = system.today().addDays(5);
opptyLineItemObj.Delivery_Date_Last__c = system.today().addDays(7);
opptyLineItemObj.Revenue_Date_Last__c = system.today().addDays(5);
opptyLineItemObj.Revenue_Date_Start__c = system.today().addDays(7);
opptyLineItemObj.Quote_Package_Name__c = 'packageName';
//opptyLineItemObj.HasSchedule = true;
opptyLineItemObj.PricebookEntryId=standardPBE.id;
// opptyLineItemObj.PricebookEntryId=standardPBE1.id;
opptyLineItemObj.opportunityid=opportunityObj.id;
opptyLineItemObj.ServiceDate = system.today().addDays(5);
opptyLineItemObj.Invoice_Date__c = system.today().addDays(5);
oliList.add(opptyLineItemObj);
}
insert oliList;
}
static testmethod void testInsertOLI() {
setData();
/*
List<OpportunityLineItem> olis = new List<OpportunityLineItem>();
List<PricebookEntry> pbe = new List<PricebookEntry>();
Opportunity oppty = TestDataHelper.createOpptyWithOfferings('Product',olis);
*/
string oliIds = '';
for (OpportunityLineItem oli : oliList) {
oliIds = oliIds + ',' + oli.id;
}
oliIds = oliIds.substring(1);
Test.startTest();
ApexPages.currentPage().getParameters().put('opptyid',opportunityObj.id);
ApexPages.currentPage().getParameters().put('ids',oliIds);
OpportunityLineItemMultiInsert ctr = new OpportunityLineItemMultiInsert();
ctr.save();
ctr.cancel();
//ctr.qtyToQtyHelper();
ctr.olis = oliList;
Boolean testValue;
if(ctr != null){
testValue = true;
}
System.assert(testValue);
}
}
Any help will be appreciated
Thanks,
Haneef
- Haneef S
- October 15, 2018
- Like
- 0
- Continue reading or reply
Error while displaying list of accounts in lightning
Hi Team,
I need to Create an application which displays all the accounts in my org. But i am getting below error, can some one please help.
Here is my code:
DisplayAllaccounts.app
<aura:application >
<c:DisplayAllAccountscomp />
</aura:application>
DisplayAllAccountsComp.cmp
<aura:component controller="displayAccounts">
<aura:attribute name="accountrows" type="object[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit1}"/>
<div class="container">
<p>
<b> List of Contacts </b>
</p>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th><strong> Id </strong></th>
<th> <strong> Name </strong> </th>
</tr>
</thead>
<tbody>
<aura:iteration var="cell" items="{!v.accountrows}">
<tr>
<td> <a href="{! '/'+cell.Id}"> {!cell.Id} </a> </td>
<td> {!cell.Name} </td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</aura:component>
DisplayAllAccountshelper.js
({
getallaccounts : function(component, event,helper) {
var action1 = component.get("c.getaccounts");
action1.setcallback(this,function(a){
component.set("v.accountrows",a.getReturnValue());
});
$A.enqueueAction(action1);
}
})
DisplayAllAccountsController.js
({
doInit1 : function(component, event, helper) {
helper.getallaccounts(component);
}
})
I am getting below error:
I need to Create an application which displays all the accounts in my org. But i am getting below error, can some one please help.
Here is my code:
DisplayAllaccounts.app
<aura:application >
<c:DisplayAllAccountscomp />
</aura:application>
DisplayAllAccountsComp.cmp
<aura:component controller="displayAccounts">
<aura:attribute name="accountrows" type="object[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit1}"/>
<div class="container">
<p>
<b> List of Contacts </b>
</p>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th><strong> Id </strong></th>
<th> <strong> Name </strong> </th>
</tr>
</thead>
<tbody>
<aura:iteration var="cell" items="{!v.accountrows}">
<tr>
<td> <a href="{! '/'+cell.Id}"> {!cell.Id} </a> </td>
<td> {!cell.Name} </td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</aura:component>
DisplayAllAccountshelper.js
({
getallaccounts : function(component, event,helper) {
var action1 = component.get("c.getaccounts");
action1.setcallback(this,function(a){
component.set("v.accountrows",a.getReturnValue());
});
$A.enqueueAction(action1);
}
})
DisplayAllAccountsController.js
({
doInit1 : function(component, event, helper) {
helper.getallaccounts(component);
}
})
I am getting below error:
- Haneef S
- July 19, 2018
- Like
- 0
- Continue reading or reply
Post an attachment on a chatter group automatically using Trigger
Hello All,
I have a requirement to write a trigger and also I am new to salesforce.
Can anyone pls help me
Requirement is:
I have custom object say test__c which is also having notes and attachments related list on it.
when a field called "state__c" is updated to "complete" on test__c object then an attachment(in notes & attchments section) starting with "abc-xxxx" needs to be posted automatically in a group called "my chatter".
My code is:
trigger AttachmentTriggger on Attachment (after insert) {
Map<Id,Id> testAttachmentMap = new Map<Id,Id>();
set<Id> testIds = new set<Id>();
for(Attachment att : Trigger.New)
{
if(att.ParentId.getSobjectType() == test__c.SobjectType){
accountAttachmentMap.put(att.ParentId,att.Id);
}
}
//fetching the account to check the condition
List<test__c> testList = new List<test__c>();
testList =[select id,state from test__c where Id IN : testAttachmentMap.keySet()];
//checking if account is meting the required condition
for(test__c testatt : testList){
if(testatt.state='completed'){
testIds.add(testatt.Id);
}
//add code here to post attachments in group
}
Any help much appreciated.
Thanks
I have a requirement to write a trigger and also I am new to salesforce.
Can anyone pls help me
Requirement is:
I have custom object say test__c which is also having notes and attachments related list on it.
when a field called "state__c" is updated to "complete" on test__c object then an attachment(in notes & attchments section) starting with "abc-xxxx" needs to be posted automatically in a group called "my chatter".
My code is:
trigger AttachmentTriggger on Attachment (after insert) {
Map<Id,Id> testAttachmentMap = new Map<Id,Id>();
set<Id> testIds = new set<Id>();
for(Attachment att : Trigger.New)
{
if(att.ParentId.getSobjectType() == test__c.SobjectType){
accountAttachmentMap.put(att.ParentId,att.Id);
}
}
//fetching the account to check the condition
List<test__c> testList = new List<test__c>();
testList =[select id,state from test__c where Id IN : testAttachmentMap.keySet()];
//checking if account is meting the required condition
for(test__c testatt : testList){
if(testatt.state='completed'){
testIds.add(testatt.Id);
}
//add code here to post attachments in group
}
Any help much appreciated.
Thanks
- Haneef S
- July 03, 2018
- Like
- 0
- Continue reading or reply
The field 'Loan_Amount__c' either does not exists on the Contact object or it is not of type currency.
I am trying to add a new custom field of type Currency to the Contact object. When I click Challenge, I am facing with following issue:
Challenge not yet complete... here's what's wrong:
The field 'Loan_Amount__c' either does not exists on the Contact object or it is not of type currency.
Challenge not yet complete... here's what's wrong:
The field 'Loan_Amount__c' either does not exists on the Contact object or it is not of type currency.
- Raju Myadam
- July 03, 2018
- Like
- 0
- Continue reading or reply
Opportunity-Owner does not change when Account-Owner is changed
Hi guys,
I thought, that by default, when an Account Owner is changed, open Opportunities owned by said User are given to the new Account Owner as well.
I know that this is the default when Account Owner is changed via front end. I thought this was the default for Account Owner changes via Apex Trigger as well? Is it not?
We have a Trigger that changes the Account Owner. However, the open Opportunities that are owned by the old Account Owner, don't get transferred to the new Account Owner.
Any idea why? Or do we have to put that Opportunity-Owner change into the Apex explicitly?
Thanks and best regards
Toby
P.S.: I know that Opps don't get transfered when Account-Owner is changed via API. The API Version 35 (Winter16) offers new "OwnerChangeOption" for that though. Is there something equivalent in Apex Classes?
I thought, that by default, when an Account Owner is changed, open Opportunities owned by said User are given to the new Account Owner as well.
I know that this is the default when Account Owner is changed via front end. I thought this was the default for Account Owner changes via Apex Trigger as well? Is it not?
We have a Trigger that changes the Account Owner. However, the open Opportunities that are owned by the old Account Owner, don't get transferred to the new Account Owner.
Any idea why? Or do we have to put that Opportunity-Owner change into the Apex explicitly?
Thanks and best regards
Toby
P.S.: I know that Opps don't get transfered when Account-Owner is changed via API. The API Version 35 (Winter16) offers new "OwnerChangeOption" for that though. Is there something equivalent in Apex Classes?
- Tobias Toal - active
- March 24, 2016
- Like
- 0
- Continue reading or reply