• teja
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 1
    Likes Given
  • 10
    Questions
  • 4
    Replies
Consider  a checkbox field as "abc" is checked on quote, I want to apply the change to all quote line items attached to it with the same change(I have the same checkbox field on both quote and quote line items). And similarly when the checkbox is unchecked and saved, It should do the same. I observed that I can't achieve this using field updates. Can Someone help me With how I can achieve this using apex trigger.

I am attaching my trigger that I have done sofar, but it has errors, Can some one help me to get it executed. 

trigger updateabc on Quote (after insert, after update){

    QuoteLineItem ql = [select abc__c from QuoteLineItem where Quote = :trigger.new[0].id ];

    for(Quote q: trigger.new){

        if(q.abc__c == true){

            ql.abc__c = true;
        }
        if(q.abc__c == false){

            ql.abc__c = false;

        }
    }

    update ql;
}
  • March 18, 2014
  • Like
  • 1
If a checkbox field on quote is checked can i reflect the change on all quote line items in salesforce?

Consider  a checkbox field as "abc" is checked on quote, I want to apply the change to all quote line items attached to it with the same change(I have the same checkbox field on both quote and quote line items). And similarly when the checkbox is unchecked and saved, It should do the same. I observed that I can't achieve this using field updates. Can Someone help me With how I can achieve this using apex trigger.

Thank you in advance for your insights. :)
  • March 18, 2014
  • Like
  • 0

Hi All,

 

I am relatively new to visual force development. Can someone help me with the tax estimator i am trying to develop. Thank you in advance.

 

Controller:
--------------
public class QuickTaxEstimateController {
public string pingResult { get; set; }
public string pingMessages { get; set; }
public string validateResult { get; set; }
public string validateMessages { get; set; }
public string item1TaxCode { get; set; }
public string taxResult { get; set; }
public string taxMessages { get; set; }
public string totalTax { get; set; }
public string totalAmount { get; set; }
public string taxResultText { get; set; }

public EO_TNQT.AddressSvc.AddressSvcSoap getAddressService() {
// EO_TNQT.AddressSvc.AddressSvcSoap addressService = new EO_TNQT.AddressSvc.AddressSvcSoap( 'https://development.avalara.net' );
EO_TNQT.AddressSvc.AddressSvcSoap addressService = new EO_TNQT.AddressSvc.AddressSvcSoap( 'https://rest.avalara.net' );
EO_TNQT.AddressSvc.Security security = new EO_TNQT.AddressSvc.Security();
EO_TNQT.AddressSvc.UsernameToken_element token = new EO_TNQT.AddressSvc.UsernameToken_element();

token.username = 'abc@example.com';
token.password = 'xyz123';
security.UsernameToken = token;
addressService.Security = security;
EO_TNQT.AddressSvc.Profile profile = new EO_TNQT.AddressSvc.Profile();
profile.Client = 'TaxSvcTest,4.0.0.0';
addressService.Profile = profile;
return addressService;
}

public void pingServer() {
EO_TNQT.AddressSvc.AddressSvcSoap addressService = getAddressService();
EO_TNQT.AddressSvc.PingResult result;
result = addressService.Ping( 'Test' );
pingResult = result.ResultCode;
pingMessages = '' + result.Messages;
integer i = 1;
System.debug( 'PING:' + result.Messages );
// for( EO_TNQT.AddressSvc.Message message : result.Messages.Message ) {
// pingMessages = ' ' + i + '-' + message.summary + ':' + message.details;
// }

}

public void validateAddress() {
EO_TNQT.AddressSvc.AddressSvcSoap addressService = getAddressService();
EO_TNQT.AddressSvc.ValidateRequest validateRequest = new EO_TNQT.AddressSvc.ValidateRequest();
EO_TNQT.AddressSvc.BaseAddress address = new EO_TNQT.AddressSvc.BaseAddress();
address.City = 'City';
address.Country = 'USA';
address.Line1 = '123, universal Address';
address.Region = 'Region';
address.PostalCode = '12345';
validateRequest.Address = address;
EO_TNQT.AddressSvc.ValidateResult result = addressService.Validate( validateRequest );
validateResult = result.ResultCode;
validateMessages = '' + result.Messages;
System.debug( 'Validate Result:' + result.ResultCode );
System.debug( 'Validate Result Messages:' + result.Messages );
}

public EO_TNQT.TaxSvc.TaxSvcSoap getTaxService() {
// EO_TNQT.TaxSvc.TaxSvcSoap taxService = new EO_TNQT.TaxSvc.TaxSvcSoap( 'https://development.avalara.net' ); // Dev
EO_TNQT.TaxSvc.TaxSvcSoap taxService = new EO_TNQT.TaxSvc.TaxSvcSoap( 'https://avatax.avalara.net' ); // Production
EO_TNQT.TaxSvc.Security security = new EO_TNQT.TaxSvc.Security();
EO_TNQT.AddressSvc.UsernameToken_element token = new EO_TNQT.AddressSvc.UsernameToken_element();

token.username = 'abc@example.com'; // Production
token.password = 'xyz123';
security.UsernameToken = token;
taxService.Security = security;
EO_TNQT.TaxSvc.Profile profile = new EO_TNQT.TaxSvc.Profile();
profile.Client = 'TaxSvcTest,4.0.0.0';
taxService.Profile = profile;
return taxService;
}

public void getTax() {
EO_TNQT.TaxSvc.GetTaxRequest request = new EO_TNQT.TaxSvc.GetTaxRequest();
Date taxDate = Date.today();
request.DocCode = 'SfQuickTaxTest-' + taxDate;
request.DocType = 'SalesInvoice';
request.DocDate = taxDate;
request.CompanyCode = 'xyz';
request.CustomerCode = 'TaxSvcTest';
request.SalesPersonCode = 'abc';
request.OriginCode = 'Origin';
request.DestinationCode = 'Destination';
request.DetailLevel = 'Line';

// Add the origin and destination addresses referred to by the
// setOriginCode and setDestinationCode properties above.
EO_TNQT.TaxSvc.ArrayOfBaseAddress addresses = new EO_TNQT.TaxSvc.ArrayOfBaseAddress();
EO_TNQT.TaxSvc.BaseAddress origin = new EO_TNQT.TaxSvc.BaseAddress();
origin.AddressCode = 'Origin';
/* origin.Line1 = 'xyz';
origin.Line2 = '321 shgqsl';
origin.Line3 = 'Suite 111';
origin.City = 'City';
origin.Region = 'Region';
origin.PostalCode = '11223';
origin.Country = 'USA'; /**/

addresses.BaseAddress = new List<EO_TNQT.TaxSvc.BaseAddress>();
addresses.BaseAddress.add( origin );

EO_TNQT.TaxSvc.BaseAddress destination = new EO_TNQT.TaxSvc.BaseAddress();
destination.AddressCode = 'Destination';

/* destination.Line1 = '123 galaxy';
destination.City = 'City';
destination.Region = 'Region';
destination.PostalCode = '54321';
destination.Country = 'USA'; /**/

addresses.BaseAddress.add( destination );

request.Addresses = addresses;

EO_TNQT.TaxSvc.ArrayOfLine lines = new EO_TNQT.TaxSvc.ArrayOfLine();
EO_TNQT.TaxSvc.Line line;

/* line = new EO_TNQT.TaxSvc.Line();
line.No = '101';
// line.ItemCode = 'Item001';
line.TaxCode = item1TaxCode;
line.Qty = 1;
// line.Amount = 1000.00;
line.Amount = 890.00;
//added in 4.12 release
// line.CustomerUsageType = 'G'; // I think the usage type is to denote tax exempt status per Anya
// line.CustomerUsageType = 'ST080120';
line.Description = 'Sample Description';
lines.Line = new List<EO_TNQT.TaxSvc.Line>();
lines.Line.add( line );

// line = new EO_TNQT.TaxSvc.Line();
// line.No = '102';
//// line.ItemCode = 'FR'; // Anya also recommended sending freight over with FR as the tax code not the item code
//// line.TaxCode = 'FR';
// line.Qty = 1;
// line.Amount = 10.00;
// lines.Line.add( line );
/**/
lines.Line = new List<EO_TNQT.TaxSvc.Line>();

line = new EO_TNQT.TaxSvc.Line();
line.No = '101';
line.ItemCode = 'IHOME';
line.TaxCode = 'P0000000';
line.Qty = 1;
line.Amount = 595.00;
line.Description = 'IHOME';
lines.Line.add( line );

line = new EO_TNQT.TaxSvc.Line();
line.No = '102';
line.ItemCode = 'OPP';
line.TaxCode = 'P0000000';
line.Qty = 1;
line.Amount = 295.00;
line.Description = 'OPP';
lines.Line.add( line );

request.Lines = lines;

EO_TNQT.TaxSvc.TaxSvcSoap taxService = getTaxService();
EO_TNQT.TaxSvc.GetTaxResult result = taxService.GetTax( request );

EO_TNQT.TaxSvc.ArrayOfTaxLine taxLineArray = result.TaxLines;
taxResultText = '';
taxResult = result.ResultCode;
taxMessages = '' + result.Messages;
if( result.ResultCode.equals( 'Success' ) ) {
for( EO_TNQT.TaxSvc.TaxLine taxLine : taxLineArray.TaxLine ) {
taxResultText = taxResultText + taxLine + '\n\n';
}
System.debug( 'GET TAX Doc Code: ' + result.DocCode );
totalTax = '' + result.TotalTax;
System.debug( 'GET TAX Total Tax: ' + result.TotalTax );
totalAmount = '' + result.TotalAmount;
System.debug( 'GET TAX Total Amount: ' + result.TotalAmount );
} else {
System.debug( 'GET TAX MESSAGES: ' + result.Messages );
}
}
}


VF Page:
--------

<apex:page controller="QuickTaxEstimateController">
<apex:pageBlock >
<apex:form >
<apex:outputText value="Ping Result: {!pingResult}" />
<br />
<apex:outputText value="Ping Messages: {!pingMessages}" />
<br />
<apex:commandButton action="{!pingServer}" value="Ping Server" />
<br />
<apex:outputText value="Validate Result: {!validateResult}" />
<br />
<apex:outputText value="Validate Messages: {!validateMessages}" />
<br />
<apex:commandButton action="{!validateAddress}" value="Validate Address" />
<br />
<apex:inputText label="Item 1 Tax Code" value="{!item1TaxCode}"/>
<br />
<apex:outputText value="Get Tax Result: {!taxResult}" />
<br />
<apex:outputText value="Get Tax Messages: {!taxMessages}" />
<br />
<apex:outputText value="Get Total Tax: {!totalTax}" />
<br />
<apex:outputText value="Get Total Amount: {!totalAmount}" />
<br />
<apex:commandButton action="{!getTax}" value="Get Tax" />
<br />
<apex:inputTextArea label="Result" value="{!taxResultText}" rows="20"/>
</apex:form>
</apex:pageBlock>
</apex:page>

 

Expecting Result :
-------------------------

Taxable Amount : --------------
Non taxable Amount : -------------
Sub : -----------------(sum(Taxable and Non taxable amounts))
Tax :---------------(shld be automatically generated)
Total : -------------(sum of (sub + tax))

  • June 28, 2013
  • Like
  • 0

I want to write a trigger to update the open task count of  leads

 

Trigger:

 

 trigger UpdateLeadOpenTasksCount on Task (after delete, after insert, after undelete, after update) {


    // Declare the variables
    public set<Id> LeadIDs = new Set<Id>();
    public list<Lead> LeadsToUpdate = new List<Lead>();
    
    // Build the list of Leads to update
    if(Trigger.isInsert || Trigger.isUnDelete || Trigger.isUpdate){
        for(Task t: Trigger.new){
            if(t.WhoId != NULL && string.valueOf(t.WhoId) != NULL && string.valueOf(t.WhoId).startsWith('00Q'))
                LeadIDs.add(t.WhoId);
        }
    }
    if(Trigger.isDelete || Trigger.isUpdate){
        for(Task t: Trigger.old){
            if(t.WhoId != NULL && string.valueOf(t.WhoId) != NULL && string.valueOf(t.WhoId).startsWith('00Q'))
                LeadIDs.add(t.WhoId);
        }
    }

    // Update the Leads
    if(LeadIDs.size()>0){
        for(Lead l: [Select l.Id, l.Open_Tasks_Count__C,
            (Select Id From Tasks where IsClosed = False)
                From Lead l where Id in :LeadIDs])
            LeadsToUpdate.add(new Lead(Id=l.Id, Open_Tasks_Count__C = l.Tasks.size()));
        update LeadsToUpdate;
    }
}

 

But still many leads are not updating except a few. Can anyone help on this. It needs to check each and every lead already existed and newly upcoming leads and check if there is any activity and update the count. If anyone have any other existing trigger to solve this purpose please post it along with the test code. Thank you in advance.

  • May 23, 2013
  • Like
  • 0
  • May 23, 2013
  • Like
  • 0

I just wanted to know. As an admin how can i give access or permissions to my marketing user to activate and deactivate the campaign.

 

I already tried enabling them as marketing user and gave all permissions to read, create, edit, delete, view all and modify all permissions on campaign still after creating a campaign they can't check it as active while creating a campaign. 

 

Any help will be appreciated.

  • May 10, 2013
  • Like
  • 0

I got assigned a work to implement the open task count of leads.So i implemented the trigger and wrote a test class

 

I got a test coverage of 78%. so i deployed it to the production and the admin is saying he got the following errors:
 
 
: TBN_CountCompletedCallsPerOpptyBatch.test_TBN_CountCompletedCallsPerOpptyBatch() Class 120 1 Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateLeadOpenTasksCount: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.UpdateLeadOpenTasksCount: line 12, column 1: []", Failure St...
TBN_TaskContactAssignTriggerHandler.test_TBN_TaskContactAssignTriggerHandler() Class 113 1 Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateLeadOpenTasksCount: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.UpdateLeadOpenTasksCount: line 12, column 1: []", Failure St...
 
 
Trigger:
 
trigger UpdateLeadOpenTasksCount on Task (after delete, after insert, after undelete,
after update) {

// Declare the variables

public set<Id> LeadIDs = new Set<Id>();
public list<Lead> LeadsToUpdate = new List<Lead>();

// Build the list of Leads to update
if(Trigger.isInsert || Trigger.isUnDelete || Trigger.isUpdate){
    for(Task t: Trigger.new){
    if(string.valueOf(t.WhoId).startsWith('00Q'))
    LeadIDs.add(t.WhoId);
    }
}

if(Trigger.isDelete || Trigger.isUpdate){
    for(Task t: Trigger.old){
    if(string.valueOf(t.WhoId).startsWith('00Q'))
    LeadIDs.add(t.WhoId);
    }
}

// Update the Leads

if(LeadIDs.size()>0){
for(Lead l: [Select l.Id, l.Open_Tasks_Count__c,
(Select Id From Tasks where IsClosed = False)
From Lead l where Id in :LeadIDs])
LeadsToUpdate.add(new Lead(Id=l.Id, Open_Tasks_Count__c = l.Tasks.size()));
update LeadsToUpdate;
}
}
 
Test class:
 
@isTest
private class TestOpenTasksCountUpdate {
static testMethod void LeadTest(){
// Create a Lead
Lead newLead = new Lead(LastName='Test', Company='ABC', Status='Targeted');
insert newLead;

// Create a Task
Task newTask = new Task(Subject='Open Tasks Count', Status='Not Started', WhoId=newLead.Id);
test.startTest();
insert newTask;
test.stopTest();

// Verify that the # Open Tasks Count is correct
newLead = [select Open_Tasks_Count__c from Lead where Id=:newLead.Id ];
System.assertEquals(1,newLead.Open_Tasks_Count__c);
}

static testMethod void CompletedTest(){
// Create a Lead
Lead newLead = new Lead(LastName='Test', Company='ABC', Status='Targeted');
insert newLead;

// Create a Completed Task
Task newTask = new Task(Subject='Open Tasks Count', Status='Completed', WhoId=newLead.Id);
test.startTest();
insert newTask;
test.stopTest();

// Verify that the # Open Tasks is empty
newLead = [select Open_Tasks_Count__c from Lead where Id=:newLead.Id ];
System.assertEquals(0,newLead.Open_Tasks_Count__c);
}

static testMethod void BatchTest(){
// Create 100 Leads
List<Lead> newLeads = new List<Lead>();
for (Integer i = 0; i < 200; i++) {
newLeads.add(new Lead(LastName='Test '+i, Company='ABC', Status='Targeted'));
}
insert newLeads;

// Create a task for each one
List<Task> newTasks = new List<Task>();
for(Lead l : newLeads){
newTasks.add(new Task(Subject='Open Tasks Count', Status='Completed', WhoId=l.Id));
}

// Insert the tasks
test.startTest();
insert newTasks;
test.stopTest();

// We could verify that the Open Tasks fields were updated correctly,
// but this is just testing the governor limits so it's not necessary
}
}
 
Can you suggest anything on how to resolve this.
  • April 25, 2013
  • Like
  • 0

I want to implement a trigger to scan the activities and check whoid to see if it is a lead. if not ignore it
and if it is alead i want to pull the next activity date of every lead and display it lead detail page by creating
a field something like Next open Activity Date or Earliest Activity Date.

 

Any help will be highly appreciated.
Thank you.

  • April 19, 2013
  • Like
  • 0

I just want to write a trigger to see the open activity of leads. How can we do it?

  • April 18, 2013
  • Like
  • 0
Consider  a checkbox field as "abc" is checked on quote, I want to apply the change to all quote line items attached to it with the same change(I have the same checkbox field on both quote and quote line items). And similarly when the checkbox is unchecked and saved, It should do the same. I observed that I can't achieve this using field updates. Can Someone help me With how I can achieve this using apex trigger.

I am attaching my trigger that I have done sofar, but it has errors, Can some one help me to get it executed. 

trigger updateabc on Quote (after insert, after update){

    QuoteLineItem ql = [select abc__c from QuoteLineItem where Quote = :trigger.new[0].id ];

    for(Quote q: trigger.new){

        if(q.abc__c == true){

            ql.abc__c = true;
        }
        if(q.abc__c == false){

            ql.abc__c = false;

        }
    }

    update ql;
}
  • March 18, 2014
  • Like
  • 1
Consider  a checkbox field as "abc" is checked on quote, I want to apply the change to all quote line items attached to it with the same change(I have the same checkbox field on both quote and quote line items). And similarly when the checkbox is unchecked and saved, It should do the same. I observed that I can't achieve this using field updates. Can Someone help me With how I can achieve this using apex trigger.

I am attaching my trigger that I have done sofar, but it has errors, Can some one help me to get it executed. 

trigger updateabc on Quote (after insert, after update){

    QuoteLineItem ql = [select abc__c from QuoteLineItem where Quote = :trigger.new[0].id ];

    for(Quote q: trigger.new){

        if(q.abc__c == true){

            ql.abc__c = true;
        }
        if(q.abc__c == false){

            ql.abc__c = false;

        }
    }

    update ql;
}
  • March 18, 2014
  • Like
  • 1

I want to write a trigger to update the open task count of  leads

 

Trigger:

 

 trigger UpdateLeadOpenTasksCount on Task (after delete, after insert, after undelete, after update) {


    // Declare the variables
    public set<Id> LeadIDs = new Set<Id>();
    public list<Lead> LeadsToUpdate = new List<Lead>();
    
    // Build the list of Leads to update
    if(Trigger.isInsert || Trigger.isUnDelete || Trigger.isUpdate){
        for(Task t: Trigger.new){
            if(t.WhoId != NULL && string.valueOf(t.WhoId) != NULL && string.valueOf(t.WhoId).startsWith('00Q'))
                LeadIDs.add(t.WhoId);
        }
    }
    if(Trigger.isDelete || Trigger.isUpdate){
        for(Task t: Trigger.old){
            if(t.WhoId != NULL && string.valueOf(t.WhoId) != NULL && string.valueOf(t.WhoId).startsWith('00Q'))
                LeadIDs.add(t.WhoId);
        }
    }

    // Update the Leads
    if(LeadIDs.size()>0){
        for(Lead l: [Select l.Id, l.Open_Tasks_Count__C,
            (Select Id From Tasks where IsClosed = False)
                From Lead l where Id in :LeadIDs])
            LeadsToUpdate.add(new Lead(Id=l.Id, Open_Tasks_Count__C = l.Tasks.size()));
        update LeadsToUpdate;
    }
}

 

But still many leads are not updating except a few. Can anyone help on this. It needs to check each and every lead already existed and newly upcoming leads and check if there is any activity and update the count. If anyone have any other existing trigger to solve this purpose please post it along with the test code. Thank you in advance.

  • May 23, 2013
  • Like
  • 0

I just wanted to know. As an admin how can i give access or permissions to my marketing user to activate and deactivate the campaign.

 

I already tried enabling them as marketing user and gave all permissions to read, create, edit, delete, view all and modify all permissions on campaign still after creating a campaign they can't check it as active while creating a campaign. 

 

Any help will be appreciated.

  • May 10, 2013
  • Like
  • 0

This afternoon, one of our users started seeing "Insufficient Privileges" messages on a specific case record when trying to reply or send an Email.

 

This is only happening for this specific case, not for other case records.

 

Any thoughts?