• SF DEV
  • NEWBIE
  • 3 Points
  • Member since 2011
  • Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 43
    Questions
  • 62
    Replies
From standard functionality of converting lead, how can i create only contact. No account records should be created.
I tried but account is mandatory, is there any way i can skip the creation of account and just create contact.

Hello

I am wanting to delete the lead record which triggers the after insert oif the field TriggerDelete__c=true

I get an soql 101 error due to it not being batchified from my test class inserting 200 records. 

Can anyone give me a pointer on how I would do this?
 

trigger Lead_HDL_AI on Lead (after insert) {
	
	//list<Lead> LeadList = [SELECT Id FROM Lead WHERE Id =:record.Id LIMIT 1];	

    for(Lead record: Trigger.new) {
        //Query Lead
        List<Lead> LeadList = [SELECT Id FROM Lead WHERE Id =:record.Id LIMIT 1]; 
        //Delete Lead
        if(record.TriggerDelete__c==true){try{DELETE LeadList;}catch(Exception e){}                          
        }
    }   
}

 

what the difference between servce and sales cloud. Does they differ by application? if so what applicatiion they belongs to, how to  differenciate?

Able to cover only for insert , how to cover delete and update. The functionality is to have only 2 records for the object in ths instance

 

trigger Surcharge_Records on Surcharge__c (before insert,before delete,before update) {
 
 if(Trigger.isInsert && Trigger.isBefore){
     for(Surcharge__c  s :Trigger.New){
        s.adderror('Sorry!! Cannot insert Surcharge');
     }
 }
 
 
 if(Trigger.isDelete){
     for(Surcharge__c  s :Trigger.Old){
        s.adderror('Sorry!! Cannot delete Surcharge');
     }
 }
 if(Trigger.isUpdate){
     for(Surcharge__c  s :Trigger.New){
        Surcharge__c  oldSurr = Trigger.oldMap.get(s.Id);
        if(s.Name != oldSurr.Name || s.Surcharge_Type__c != oldSurr.Surcharge_Type__c ){
           s.adderror('Sorry!! Cannot update name and Type'); 
        }
        
     }
 }
 
}

for(Task T1:trigger.new)
{
try{

for(opportunity o:Oppids)
{

if(T1.WhatId == o.id && (T1.Subject).startsWith('Email: BAS') ){

if(o.StageName =='Booking Acknowledged'){
o.BAS_Sent_Date__c=date.valueof(T1.CreatedDate);
o.StageName='Booking Verified';

}}

}
}catch(Exception e){system.debug('Exception Here'+e);}

i got two classes with code coverage 86, 95.

But when im migrating its not allowing, the lines which are covered its showing as not under coverage. 

How to solve?

 if(trigger.isInsert){
        For(contract__c con:trigger.new){
        
        datetime s;
        Try{
            if(con.Contract_Status__c == 'Renewal'){
                Contract__c Cold = [Select Contract_Expiry_Date__c From Contract__c where ID=:con.Contract_Old__c];
                s = cold.Contract_Expiry_Date__c; 
                datetime e = date.Today();
                date startDate = Date.newInstance(s.year(),s.month(),s.day());
                date enddate = date.newInstance(e.year(),e.month(),e.day());
                integer numberDaysDue = startDate.daysBetween(enddate);
                    if(numberDaysDue < 7){
                        con.Renewal_Duration__c = 'Less than 1 week';
                    }
                    if(numberDaysDue >= 7 && numberDaysDue <= 30 ){
                        con.Renewal_Duration__c = '2 to 4 weeks';
                    }
                    if(numberDaysDue > 30 ){
                        con.Renewal_Duration__c = 'More than 1 Month';
                    }
            }
        }
        catch(Exception e){}
        
        }
    }

 

 

 

i want to update the contract it self , when its getting inserted, from above code i want remove query from for loop, i did using set<id>. as below code, as im checking for ID's its give null bez its before insert, How to remove query from for loop.

 

 

if(trigger.isInsert){
For(contract__c con:trigger.new){
if(con.Contract_Status__c == 'Renewal'){
contracts_oldids.add(con.Contract_Old__c);
}
}
if(contracts_oldids.size()>0){
contract_oldque = [Select Contract_Old__c,Contract_Expiry_Date__c From Contract__c where ID IN:contracts_oldids];
}

For(contract__c con:trigger.new){
for(Opportunity o:oppall){
if(Con.Opportunity__c == o.ID ){
if(o.Probability != 100){
trigger.new[0].addError('Opportunity Percentage 100%');
}
}
}
datetime s;
Try{
if(con.Contract_Status__c == 'Renewal'){
for(Contract__c Cold:contract_oldque ){


if(Cold.Contract_Old__c==con.id){

this id getting empty

 

Hi All,

      we created a custom convert button on custom object,which is to convert  

For(contract__c con:trigger.new){

con.Owner__c = con.Opportunity__r.Account.createdBy.ID;
con.Region__c= con.Opportunity__r.Account.Region__c;
}

 

con.Opportunity__r.Account.createdBy.ID,con.Opportunity__r.Account.Region__c these values are  NULL ,  How to pass values into Contract when they are related other opportunity and opportunity related to contract.

I have text field - (Reg ID) which will get update as 

 

Reg_ID__c=Sudent_Name__c++'-'+ Class_No__c

Class_No__c  ---  Number field

 

Now i want format to be;

Reg_Id__c = Eg 1: John-000001

                        Eg 2: Clark-000012

                        Eg 3:  Tom-000013

 

 

How to for format number field before concatinating.

Im getting as john-1, clark-12, Tom-13,

                 

 

 

Unable to get hyperlink in add.error code, In trigger.

 

I have seen codes in forum, but wrkg out, as its giving like output text, i need in clickable format.

 

i tried this:

o.addError('ERROR TRM100: There is already an identical record: <a href=\'https://cs2.salesforce.com/' + Acctid.id + '\'>Record Number ' + Acctid.id + '</a>');

 

How to check field value starts with 'World***'

 

 if(T1.WhatId  ==  o.id && T1.Subject == 'Email: 'World.........'' ){

I want check for duplicate id getting inserted in account, I have called batch class from trigger.

 

trigger id with its name need to pass to batch class, and chek against all account if the record with name already existing.

 

But my batch not executing, below is my code 

 

 

global class DuplicateAccount implements Database.Batchable<sObject>
{
Public integer leadcount{get;set;}
global  String Query;
set<id> ACCTIDS=new set<id>();
global account []A {get;set;}
list<String> MainAccounts = new list<String >();
 global DuplicateAccount (list<string> listAccounts)
    {   
    system.debug('daaaaaa'+listAccounts);
        MainAccounts = listAccounts;
         system.debug('mmmmmmmmmaaaaaaaaaaaaa'+MainAccounts );
    }

global Database.QueryLocator start(Database.BatchableContext BC)
{ system.debug('ffffffffffffff');
            query='SELECT Id FROM account WHERE name IN: MainAccounts';
            system.debug('mmmmmmmmmmmmmmmmmmmm'+MainAccounts);
            return Database.getQueryLocator(query);

}


global void execute(Database.BatchableContext BC, List<Account> scope)
{system.debug('aaaaaaaaaaaaaaaaaaaa');
 Account []aname=[select name from account where name in: MainAccounts ];
 for(account ac: scope){
    if(ac.name==aname[0].name){system.debug('dssdcsdc');}
 }
 }

global void finish(Database.BatchableContext BC)
{
//Send an email to the User after your batch completes
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'sforce2009@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex Batch Job is done');
mail.setPlainTextBody('The batch Apex job processed ');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}

Here is a requrement from client: 

 

 

In one line I need: field name, filed itself, and button.

This must be fitted inside one column of: <apex:pageBlockSection columns="2" >

 

So I came up with this:

 

<apex:pageBlockSectionItem >
    <apex:inputField label="Activation Counter" id="activationCounter" value="{!object.field__c}"/>
    <apex:commandButton value="Reset"/>
</apex:pageBlockSectionItem>

 which results in missing label:

 

So I wanted to add field label like this:

 

<apex:pageBlockSectionItem >
    <apex:outputLabel value="Activation Counter" for="activationCounter"/>
    <apex:inputField label="Activation Counter" id="activationCounter" value="{!object.field__c}"/>
    <apex:commandButton value="Reset"/>
</apex:pageBlockSectionItem>

 an now getting error:

 

Error: <apex:pageBlockSectionItem> may have no more than 2 child components

 

Is there a way to get it working together?