-
ChatterFeed
-
1Best Answers
-
1Likes Received
-
0Likes Given
-
7Questions
-
9Replies
Test Class for afrer update trigger
Hi,
I have following After Update Trigger... I have to write test class for same...
Please some one help me..?
trigger AccountChanged on Asset (after update) {
List<Opportunity> OppList= new List<Opportunity>();
for (Asset newAsset : Trigger.new) {
// If account of equipment is changed..
if ( newAsset.AccountId != Trigger.oldMap.get( newAsset.Id ).AccountId ){
//Create new Opportunity for Sales i.e. OEM Record Type...
Opportunity newOpp1 = new Opportunity();
Id oppRecordTypeId1 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('OEM').getRecordTypeId();
newOpp1.RecordTypeId = oppRecordTypeId1;
newOpp1.Asset__c = newAsset.id;
newOpp1.Name = 'New Sales Opportunity';
newOpp1.AccountId = newAsset.AccountId;
newOpp1.StageName = 'Qualification';
newOpp1.CloseDate = system.today();
OppList.add(newOpp1);
//Create new Opportunity for Parts i.e. Parts Record Type...
Opportunity newOpp2 = new Opportunity();
Id oppRecordTypeId2 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Parts').getRecordTypeId();
newOpp2.RecordTypeId = oppRecordTypeId2;
newOpp2.Asset__c = newAsset.id;
newOpp2.Name = 'New Parts Opportunity';
newOpp2.AccountId = newAsset.AccountId;
newOpp2.StageName = 'Qualification';
newOpp2.CloseDate = system.today();
OppList.add(newOpp2);
If(OppList.Size()>0){
Insert OppList;
}
}
}
}
I have following After Update Trigger... I have to write test class for same...
Please some one help me..?
trigger AccountChanged on Asset (after update) {
List<Opportunity> OppList= new List<Opportunity>();
for (Asset newAsset : Trigger.new) {
// If account of equipment is changed..
if ( newAsset.AccountId != Trigger.oldMap.get( newAsset.Id ).AccountId ){
//Create new Opportunity for Sales i.e. OEM Record Type...
Opportunity newOpp1 = new Opportunity();
Id oppRecordTypeId1 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('OEM').getRecordTypeId();
newOpp1.RecordTypeId = oppRecordTypeId1;
newOpp1.Asset__c = newAsset.id;
newOpp1.Name = 'New Sales Opportunity';
newOpp1.AccountId = newAsset.AccountId;
newOpp1.StageName = 'Qualification';
newOpp1.CloseDate = system.today();
OppList.add(newOpp1);
//Create new Opportunity for Parts i.e. Parts Record Type...
Opportunity newOpp2 = new Opportunity();
Id oppRecordTypeId2 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Parts').getRecordTypeId();
newOpp2.RecordTypeId = oppRecordTypeId2;
newOpp2.Asset__c = newAsset.id;
newOpp2.Name = 'New Parts Opportunity';
newOpp2.AccountId = newAsset.AccountId;
newOpp2.StageName = 'Qualification';
newOpp2.CloseDate = system.today();
OppList.add(newOpp2);
If(OppList.Size()>0){
Insert OppList;
}
}
}
}
-
- Puja Patil 13
- December 20, 2016
- Like
- 0
- Continue reading or reply
"AccountTrigger: System.LimitException: Apex CPU time limit exceeded" error at the time of bulk data import.
Hi All,
Please help me to bulkiefy the following :
private void getAccountD(List<Account> acc){
List<Account> account = new List<Account>();
List<State_Master__c> SM = [SELECT TerritoryState__c,District__c,Town__c,Zone__c,RO__c,Territory_Code__c FROM State_Master__c];
for(State_Master__c e : SM){
for(Account g : acc){
if((e.TerritoryState__c == g.State_Name__c) && (e.District__c == g.District__c) && (e.Town__c == g.Town__c)){
system.debug('Update Acc');
g.Sales_Office_Text__c = e.Zone__c;
g.Sales_District_Text__c = e.Territory_Code__c;
g.Sales_Group_Text__c = e.RO__c;
account.add(g);
}
}
}
if(account.size() <= 0){
for(Account g : acc){
g.Sales_Office_Text__c = '';
g.Sales_District_Text__c = '';
g.Sales_Group_Text__c = '';
account.add(g);
}
}
}
It is working fine for individual record insert and update event.
But it gives
"AccountTrigger: System.LimitException: Apex CPU time limit exceeded" this error at the time of bulk data import.
Thanks in Advance,
Puja
Please help me to bulkiefy the following :
private void getAccountD(List<Account> acc){
List<Account> account = new List<Account>();
List<State_Master__c> SM = [SELECT TerritoryState__c,District__c,Town__c,Zone__c,RO__c,Territory_Code__c FROM State_Master__c];
for(State_Master__c e : SM){
for(Account g : acc){
if((e.TerritoryState__c == g.State_Name__c) && (e.District__c == g.District__c) && (e.Town__c == g.Town__c)){
system.debug('Update Acc');
g.Sales_Office_Text__c = e.Zone__c;
g.Sales_District_Text__c = e.Territory_Code__c;
g.Sales_Group_Text__c = e.RO__c;
account.add(g);
}
}
}
if(account.size() <= 0){
for(Account g : acc){
g.Sales_Office_Text__c = '';
g.Sales_District_Text__c = '';
g.Sales_Group_Text__c = '';
account.add(g);
}
}
}
It is working fine for individual record insert and update event.
But it gives
"AccountTrigger: System.LimitException: Apex CPU time limit exceeded" this error at the time of bulk data import.
Thanks in Advance,
Puja
-
- Puja Dev 6
- November 08, 2017
- Like
- 0
- Continue reading or reply
Custom Lookup Field error
Hello All,
<!-- NewAccount -->
<aura:component implements="force:appHostable" controller="AccountController">
<aura:attribute name="newAccount" type="Account" default="{ 'sobjectType': 'Account', 'Name': '', }" access="public"/>
<div >
<center>
<form>
Name <force:inputField aura:id="Name" value="{!v.newAccount.Name}"/>
Note <force:inputField aura:id="Note" value="{!v.newAccount.Description}"/>
Categories<force:inputField aura:id="Categories" value="{!v.newAccount.Categories_del__c}"/>
SubCategories<force:inputField aura:id="SubCategories" value="{!v.newAccount.Sub_Categories__c }"/>
Assign to<force:inputField aura:id="Assign To " value="{!v.newAccount.Assigned_To__c}"/>
Billing Street <force:inputField aura:id="Street " value="{!v.newAccount.BillingStreet}"/>
Billing City <force:inputField aura:id="City " value="{!v.newAccount.BillingCity}"/>
Billing State <force:inputField aura:id="State " value="{!v.newAccount.BillingState}"/>
Billing Country <force:inputField aura:id="Country " value="{!v.newAccount.BillingCountry}"/>
Billing Postal Code<force:inputField aura:id="Postal Code " value="{!v.newAccount.BillingPostalCode}"/>
<lightning:button label="Save" onclick="{!c.createAccount}" />
</form>
</center>
</div>
</aura:component>
This is my sample code to save Account Record using Lightning Component. "Assign To" is custom field of "User Lookup" , but it gives the following error. Check screen shot as well. I also enabled Lightning component checkbox.
"This page has an error. You might just need to refresh it.
Access Check Failed! AttributeSet.get(): attribute 'inContextOfRecordId' of component 'markup://c:NewAccount {3:0}' is not visible to 'markup://c:NewAccount {3:0}'.
Failing descriptor: {markup://c:NewAccount}"
<!-- NewAccount -->
<aura:component implements="force:appHostable" controller="AccountController">
<aura:attribute name="newAccount" type="Account" default="{ 'sobjectType': 'Account', 'Name': '', }" access="public"/>
<div >
<center>
<form>
Name <force:inputField aura:id="Name" value="{!v.newAccount.Name}"/>
Note <force:inputField aura:id="Note" value="{!v.newAccount.Description}"/>
Categories<force:inputField aura:id="Categories" value="{!v.newAccount.Categories_del__c}"/>
SubCategories<force:inputField aura:id="SubCategories" value="{!v.newAccount.Sub_Categories__c }"/>
Assign to<force:inputField aura:id="Assign To " value="{!v.newAccount.Assigned_To__c}"/>
Billing Street <force:inputField aura:id="Street " value="{!v.newAccount.BillingStreet}"/>
Billing City <force:inputField aura:id="City " value="{!v.newAccount.BillingCity}"/>
Billing State <force:inputField aura:id="State " value="{!v.newAccount.BillingState}"/>
Billing Country <force:inputField aura:id="Country " value="{!v.newAccount.BillingCountry}"/>
Billing Postal Code<force:inputField aura:id="Postal Code " value="{!v.newAccount.BillingPostalCode}"/>
<lightning:button label="Save" onclick="{!c.createAccount}" />
</form>
</center>
</div>
</aura:component>
This is my sample code to save Account Record using Lightning Component. "Assign To" is custom field of "User Lookup" , but it gives the following error. Check screen shot as well. I also enabled Lightning component checkbox.
"This page has an error. You might just need to refresh it.
Access Check Failed! AttributeSet.get(): attribute 'inContextOfRecordId' of component 'markup://c:NewAccount {3:0}' is not visible to 'markup://c:NewAccount {3:0}'.
Failing descriptor: {markup://c:NewAccount}"
-
- Puja Dev 6
- September 01, 2017
- Like
- 0
- Continue reading or reply
How to store Picklist and Lookup field from Lightning Component into Account Object...?
Hi
I have the following Lightning Component to save the record into Account Object.
It saves standard field (Acc Name, Description). But not Custom fields.
I want to add one picklist field and one lookup field on Component.
<!-- NewAccount -->
<aura:component implements="force:appHostable" controller="AccountController">
<aura:attribute name="newAccount" type="Account" default="{ 'sobjectType': 'Account', 'Name': '', }"/>
<div >
<center>
<form>
<lightning:input aura:id="AccountName" name="New Account Name" label="Account Name"
value="{!v.newAccount.Name}" required="true"/>
<lightning:input aura:id="Description" name="New Account Name" label="Note"
value="{!v.newAccount.Description}" required="true"/>
<lightning:input aura:id="Categories" name="New Account Name" label="Categories"
value="{!v.newAccount.Categories_del__c}" required="true"/>
<lightning:select aura:id="myselection" value="{!v.selectValue}">
<aura:iteration items="{!v.options}" item="option">
<option value="{!option}">{!option}</option>
</aura:iteration>
</lightning:select>
<lightning:button label="Save" onclick="{!c.createAccount}" />
</form>
</center>
</div>
</aura:component>
How to store Picklist and Lookup field ...?
I have the following Lightning Component to save the record into Account Object.
It saves standard field (Acc Name, Description). But not Custom fields.
I want to add one picklist field and one lookup field on Component.
<!-- NewAccount -->
<aura:component implements="force:appHostable" controller="AccountController">
<aura:attribute name="newAccount" type="Account" default="{ 'sobjectType': 'Account', 'Name': '', }"/>
<div >
<center>
<form>
<lightning:input aura:id="AccountName" name="New Account Name" label="Account Name"
value="{!v.newAccount.Name}" required="true"/>
<lightning:input aura:id="Description" name="New Account Name" label="Note"
value="{!v.newAccount.Description}" required="true"/>
<lightning:input aura:id="Categories" name="New Account Name" label="Categories"
value="{!v.newAccount.Categories_del__c}" required="true"/>
<lightning:select aura:id="myselection" value="{!v.selectValue}">
<aura:iteration items="{!v.options}" item="option">
<option value="{!option}">{!option}</option>
</aura:iteration>
</lightning:select>
<lightning:button label="Save" onclick="{!c.createAccount}" />
</form>
</center>
</div>
</aura:component>
How to store Picklist and Lookup field ...?
-
- Puja Dev 6
- August 31, 2017
- Like
- 0
- Continue reading or reply
Formila field Images not showing on Render as PDF.
Hi All,
I have formula field of text datatype. It used to captured QR code of each Campaign Member Record.
On VFPage it's working fine.
But on Render as PDF, it shows currepted image.
Following is the formula field :
QR Code :
IMAGE('https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=MECARD://tjt--aresssbox.cs64.my.salesforce.com/'&Id ,'Scan QR code to open record in mobile.')
I have formula field of text datatype. It used to captured QR code of each Campaign Member Record.
On VFPage it's working fine.
But on Render as PDF, it shows currepted image.
Following is the formula field :
QR Code :
IMAGE('https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=MECARD://tjt--aresssbox.cs64.my.salesforce.com/'&Id ,'Scan QR code to open record in mobile.')
-
- Puja Dev 6
- August 14, 2017
- Like
- 1
- Continue reading or reply
how to fire Workflow Rule or Process builder on change in formula field.
Hi,
Can we fire Workflow Rule or Process builder on change in formula field..?
Can we fire Workflow Rule or Process builder on change in formula field..?
-
- Puja Dev 6
- July 31, 2017
- Like
- 0
- Continue reading or reply
How to copy value of currency field into "Unit Price" field of "OrderLine Item"...?
Hi,
I want to copy value of "discounted box price(Currency field)" in to the standard field "Unit Price" of OrderLineItem Object.
I have tryed using Workflow rule. Its working but it can not fullfill my requirment. So,I want trigger to copy "discounted box price" to "Unit Price".
Please let me know the solution.
Thanks, in advanced.
Puja
I want to copy value of "discounted box price(Currency field)" in to the standard field "Unit Price" of OrderLineItem Object.
I have tryed using Workflow rule. Its working but it can not fullfill my requirment. So,I want trigger to copy "discounted box price" to "Unit Price".
Please let me know the solution.
Thanks, in advanced.
Puja
-
- Puja Dev 6
- July 06, 2017
- Like
- 0
- Continue reading or reply
How to give access permission to Junction Object..?
Hi,
I have Junction object "Enrollment" (for Student Details and Test).
and I have Role Hierarchy, as folllowing :
Admin ---- > Center Head --- > User
1. When I set OWD as "Private" for Student Details and Test then no any data is visible to "User". Not even self data.
2. When I set OWD as "Public Read/write" for Student Details and Test then all data is visible to "User". Data of admin too.
I want to show only User's data.
Please someone help to solve my issue...?
Regards,
Puja
I have Junction object "Enrollment" (for Student Details and Test).
and I have Role Hierarchy, as folllowing :
Admin ---- > Center Head --- > User
1. When I set OWD as "Private" for Student Details and Test then no any data is visible to "User". Not even self data.
2. When I set OWD as "Public Read/write" for Student Details and Test then all data is visible to "User". Data of admin too.
I want to show only User's data.
Please someone help to solve my issue...?
Regards,
Puja
-
- Puja Dev 6
- March 16, 2017
- Like
- 0
- Continue reading or reply
Formila field Images not showing on Render as PDF.
Hi All,
I have formula field of text datatype. It used to captured QR code of each Campaign Member Record.
On VFPage it's working fine.
But on Render as PDF, it shows currepted image.
Following is the formula field :
QR Code :
IMAGE('https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=MECARD://tjt--aresssbox.cs64.my.salesforce.com/'&Id ,'Scan QR code to open record in mobile.')
I have formula field of text datatype. It used to captured QR code of each Campaign Member Record.
On VFPage it's working fine.
But on Render as PDF, it shows currepted image.
Following is the formula field :
QR Code :
IMAGE('https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=MECARD://tjt--aresssbox.cs64.my.salesforce.com/'&Id ,'Scan QR code to open record in mobile.')
-
- Puja Dev 6
- August 14, 2017
- Like
- 1
- Continue reading or reply
"AccountTrigger: System.LimitException: Apex CPU time limit exceeded" error at the time of bulk data import.
Hi All,
Please help me to bulkiefy the following :
private void getAccountD(List<Account> acc){
List<Account> account = new List<Account>();
List<State_Master__c> SM = [SELECT TerritoryState__c,District__c,Town__c,Zone__c,RO__c,Territory_Code__c FROM State_Master__c];
for(State_Master__c e : SM){
for(Account g : acc){
if((e.TerritoryState__c == g.State_Name__c) && (e.District__c == g.District__c) && (e.Town__c == g.Town__c)){
system.debug('Update Acc');
g.Sales_Office_Text__c = e.Zone__c;
g.Sales_District_Text__c = e.Territory_Code__c;
g.Sales_Group_Text__c = e.RO__c;
account.add(g);
}
}
}
if(account.size() <= 0){
for(Account g : acc){
g.Sales_Office_Text__c = '';
g.Sales_District_Text__c = '';
g.Sales_Group_Text__c = '';
account.add(g);
}
}
}
It is working fine for individual record insert and update event.
But it gives
"AccountTrigger: System.LimitException: Apex CPU time limit exceeded" this error at the time of bulk data import.
Thanks in Advance,
Puja
Please help me to bulkiefy the following :
private void getAccountD(List<Account> acc){
List<Account> account = new List<Account>();
List<State_Master__c> SM = [SELECT TerritoryState__c,District__c,Town__c,Zone__c,RO__c,Territory_Code__c FROM State_Master__c];
for(State_Master__c e : SM){
for(Account g : acc){
if((e.TerritoryState__c == g.State_Name__c) && (e.District__c == g.District__c) && (e.Town__c == g.Town__c)){
system.debug('Update Acc');
g.Sales_Office_Text__c = e.Zone__c;
g.Sales_District_Text__c = e.Territory_Code__c;
g.Sales_Group_Text__c = e.RO__c;
account.add(g);
}
}
}
if(account.size() <= 0){
for(Account g : acc){
g.Sales_Office_Text__c = '';
g.Sales_District_Text__c = '';
g.Sales_Group_Text__c = '';
account.add(g);
}
}
}
It is working fine for individual record insert and update event.
But it gives
"AccountTrigger: System.LimitException: Apex CPU time limit exceeded" this error at the time of bulk data import.
Thanks in Advance,
Puja
- Puja Dev 6
- November 08, 2017
- Like
- 0
- Continue reading or reply
Custom Lookup Field error
Hello All,
<!-- NewAccount -->
<aura:component implements="force:appHostable" controller="AccountController">
<aura:attribute name="newAccount" type="Account" default="{ 'sobjectType': 'Account', 'Name': '', }" access="public"/>
<div >
<center>
<form>
Name <force:inputField aura:id="Name" value="{!v.newAccount.Name}"/>
Note <force:inputField aura:id="Note" value="{!v.newAccount.Description}"/>
Categories<force:inputField aura:id="Categories" value="{!v.newAccount.Categories_del__c}"/>
SubCategories<force:inputField aura:id="SubCategories" value="{!v.newAccount.Sub_Categories__c }"/>
Assign to<force:inputField aura:id="Assign To " value="{!v.newAccount.Assigned_To__c}"/>
Billing Street <force:inputField aura:id="Street " value="{!v.newAccount.BillingStreet}"/>
Billing City <force:inputField aura:id="City " value="{!v.newAccount.BillingCity}"/>
Billing State <force:inputField aura:id="State " value="{!v.newAccount.BillingState}"/>
Billing Country <force:inputField aura:id="Country " value="{!v.newAccount.BillingCountry}"/>
Billing Postal Code<force:inputField aura:id="Postal Code " value="{!v.newAccount.BillingPostalCode}"/>
<lightning:button label="Save" onclick="{!c.createAccount}" />
</form>
</center>
</div>
</aura:component>
This is my sample code to save Account Record using Lightning Component. "Assign To" is custom field of "User Lookup" , but it gives the following error. Check screen shot as well. I also enabled Lightning component checkbox.
"This page has an error. You might just need to refresh it.
Access Check Failed! AttributeSet.get(): attribute 'inContextOfRecordId' of component 'markup://c:NewAccount {3:0}' is not visible to 'markup://c:NewAccount {3:0}'.
Failing descriptor: {markup://c:NewAccount}"
<!-- NewAccount -->
<aura:component implements="force:appHostable" controller="AccountController">
<aura:attribute name="newAccount" type="Account" default="{ 'sobjectType': 'Account', 'Name': '', }" access="public"/>
<div >
<center>
<form>
Name <force:inputField aura:id="Name" value="{!v.newAccount.Name}"/>
Note <force:inputField aura:id="Note" value="{!v.newAccount.Description}"/>
Categories<force:inputField aura:id="Categories" value="{!v.newAccount.Categories_del__c}"/>
SubCategories<force:inputField aura:id="SubCategories" value="{!v.newAccount.Sub_Categories__c }"/>
Assign to<force:inputField aura:id="Assign To " value="{!v.newAccount.Assigned_To__c}"/>
Billing Street <force:inputField aura:id="Street " value="{!v.newAccount.BillingStreet}"/>
Billing City <force:inputField aura:id="City " value="{!v.newAccount.BillingCity}"/>
Billing State <force:inputField aura:id="State " value="{!v.newAccount.BillingState}"/>
Billing Country <force:inputField aura:id="Country " value="{!v.newAccount.BillingCountry}"/>
Billing Postal Code<force:inputField aura:id="Postal Code " value="{!v.newAccount.BillingPostalCode}"/>
<lightning:button label="Save" onclick="{!c.createAccount}" />
</form>
</center>
</div>
</aura:component>
This is my sample code to save Account Record using Lightning Component. "Assign To" is custom field of "User Lookup" , but it gives the following error. Check screen shot as well. I also enabled Lightning component checkbox.
"This page has an error. You might just need to refresh it.
Access Check Failed! AttributeSet.get(): attribute 'inContextOfRecordId' of component 'markup://c:NewAccount {3:0}' is not visible to 'markup://c:NewAccount {3:0}'.
Failing descriptor: {markup://c:NewAccount}"
- Puja Dev 6
- September 01, 2017
- Like
- 0
- Continue reading or reply
Formila field Images not showing on Render as PDF.
Hi All,
I have formula field of text datatype. It used to captured QR code of each Campaign Member Record.
On VFPage it's working fine.
But on Render as PDF, it shows currepted image.
Following is the formula field :
QR Code :
IMAGE('https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=MECARD://tjt--aresssbox.cs64.my.salesforce.com/'&Id ,'Scan QR code to open record in mobile.')
I have formula field of text datatype. It used to captured QR code of each Campaign Member Record.
On VFPage it's working fine.
But on Render as PDF, it shows currepted image.
Following is the formula field :
QR Code :
IMAGE('https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=MECARD://tjt--aresssbox.cs64.my.salesforce.com/'&Id ,'Scan QR code to open record in mobile.')
- Puja Dev 6
- August 14, 2017
- Like
- 1
- Continue reading or reply
How to copy value of currency field into "Unit Price" field of "OrderLine Item"...?
Hi,
I want to copy value of "discounted box price(Currency field)" in to the standard field "Unit Price" of OrderLineItem Object.
I have tryed using Workflow rule. Its working but it can not fullfill my requirment. So,I want trigger to copy "discounted box price" to "Unit Price".
Please let me know the solution.
Thanks, in advanced.
Puja
I want to copy value of "discounted box price(Currency field)" in to the standard field "Unit Price" of OrderLineItem Object.
I have tryed using Workflow rule. Its working but it can not fullfill my requirment. So,I want trigger to copy "discounted box price" to "Unit Price".
Please let me know the solution.
Thanks, in advanced.
Puja
- Puja Dev 6
- July 06, 2017
- Like
- 0
- Continue reading or reply
Test Class for afrer update trigger
Hi,
I have following After Update Trigger... I have to write test class for same...
Please some one help me..?
trigger AccountChanged on Asset (after update) {
List<Opportunity> OppList= new List<Opportunity>();
for (Asset newAsset : Trigger.new) {
// If account of equipment is changed..
if ( newAsset.AccountId != Trigger.oldMap.get( newAsset.Id ).AccountId ){
//Create new Opportunity for Sales i.e. OEM Record Type...
Opportunity newOpp1 = new Opportunity();
Id oppRecordTypeId1 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('OEM').getRecordTypeId();
newOpp1.RecordTypeId = oppRecordTypeId1;
newOpp1.Asset__c = newAsset.id;
newOpp1.Name = 'New Sales Opportunity';
newOpp1.AccountId = newAsset.AccountId;
newOpp1.StageName = 'Qualification';
newOpp1.CloseDate = system.today();
OppList.add(newOpp1);
//Create new Opportunity for Parts i.e. Parts Record Type...
Opportunity newOpp2 = new Opportunity();
Id oppRecordTypeId2 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Parts').getRecordTypeId();
newOpp2.RecordTypeId = oppRecordTypeId2;
newOpp2.Asset__c = newAsset.id;
newOpp2.Name = 'New Parts Opportunity';
newOpp2.AccountId = newAsset.AccountId;
newOpp2.StageName = 'Qualification';
newOpp2.CloseDate = system.today();
OppList.add(newOpp2);
If(OppList.Size()>0){
Insert OppList;
}
}
}
}
I have following After Update Trigger... I have to write test class for same...
Please some one help me..?
trigger AccountChanged on Asset (after update) {
List<Opportunity> OppList= new List<Opportunity>();
for (Asset newAsset : Trigger.new) {
// If account of equipment is changed..
if ( newAsset.AccountId != Trigger.oldMap.get( newAsset.Id ).AccountId ){
//Create new Opportunity for Sales i.e. OEM Record Type...
Opportunity newOpp1 = new Opportunity();
Id oppRecordTypeId1 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('OEM').getRecordTypeId();
newOpp1.RecordTypeId = oppRecordTypeId1;
newOpp1.Asset__c = newAsset.id;
newOpp1.Name = 'New Sales Opportunity';
newOpp1.AccountId = newAsset.AccountId;
newOpp1.StageName = 'Qualification';
newOpp1.CloseDate = system.today();
OppList.add(newOpp1);
//Create new Opportunity for Parts i.e. Parts Record Type...
Opportunity newOpp2 = new Opportunity();
Id oppRecordTypeId2 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Parts').getRecordTypeId();
newOpp2.RecordTypeId = oppRecordTypeId2;
newOpp2.Asset__c = newAsset.id;
newOpp2.Name = 'New Parts Opportunity';
newOpp2.AccountId = newAsset.AccountId;
newOpp2.StageName = 'Qualification';
newOpp2.CloseDate = system.today();
OppList.add(newOpp2);
If(OppList.Size()>0){
Insert OppList;
}
}
}
}
- Puja Patil 13
- December 20, 2016
- Like
- 0
- Continue reading or reply