• 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.
Can we do bulk retagging in salesforce. Are else we need to do one by one retagging?
Unable to map Account Source (Standard Field) because itsmissing in mapping detail page, Its a standard Field and why i could not able to see the field to map it.

Any one face this issue before. 
  • March 27, 2015
  • Like
  • 0
Unable to close firefox current tab using javascript

using Window.top.close(), workinginchrome and IE not in firefox.
Is there way to close tab in forefox usingjavascript?
<apex:commandButton onClick="window.top.close();"   value="Cancel"/>
                
  • March 20, 2015
  • Like
  • 0
cancel Functionality for visual force loading using Sites

I have created a page and its access using sites, when user loads the page out side the salesforce using site, and when they cancel the page by clicking cancel button its giving error:

Authorization Required 

You must first log in or register before accessing this page. 
If you have forgotten your password, click Forgot Password to reset it. 


How to cancel the page by command button

My code:
public class loadtrial {
    ApexPages.standardController load_t  = null;
    public loadtrial(ApexPages.standardController sc)
    {
      load_t = sc;
    }
  
    }
    public PageReference Cancel()
    {
      return load_t.cancel();
    }
    
}


 
  • March 12, 2015
  • Like
  • 0

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?

Error Message System.NullPointerException: Attempt to de-reference a null object   

 

"h" is holiday object (standard one)

 

error in this line - Class

b = h.ActivityDate.daysBetween(h.RecurrenceStartDate);

 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

 

  • April 03, 2013
  • Like
  • 0

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.

  • April 01, 2013
  • Like
  • 0

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,

                 

 

 

  • March 14, 2013
  • Like
  • 0

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>');

 

  • March 14, 2013
  • Like
  • 0

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

 

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

  • March 11, 2013
  • Like
  • 0

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 });
}
}

  • March 11, 2013
  • Like
  • 0

Compile Error: Initial term of field expression must be a concrete SObject: String at line 20 column 59

 

trigger Update_AccountID on Account (after insert,after update) {

public list<AccountID__c > AID =new list<AccountID__c >();
public Map<string,String> Map_Types=new Map<string,String>();
set<string> Typevalue=new set<string>();
for(account a1:trigger.new){
Typevalue.add(a1.type);
}
Account_Running_Number__c []ARN_ids=[select Id,Running_Number__c,Type__c from Account_Running_Number__c where Type__c in:Typevalue];
for(Account_Running_Number__c AR1:ARN_ids){
Map_Types.put(AR1.Type__c,AR1.Type__c);
}

for(Account a2:trigger.new){
for(Account a3:trigger.old)
{
if(a2.Type=='Tour Agent' && a3.Type!='Tour Agent')
{
AccountID__c t1 = new AccountID__c();
t1.Account_Id__c='TA'+Map_Types.get(a2.Type).Running_Number__c;
t1.Type__c=a2.Type;
AID.add(t1);
}
}
}
Insert AID;
}

 

 

Compilation error giving how to solve!!!, The way i used MAP is some where wrong. Can any one suggest.

  • March 09, 2013
  • Like
  • 0

I have a trigger which calls a class method, now inside the class i need to send message.

 

Eg:

 

Trigger: calling class Testclass

class: Testclass(){

if(somecondition)

{

from here i want pass messsage to trigger.

}

 

  • March 06, 2013
  • Like
  • 0

trigger.new[0].addError('Please select Region');

 

 

How to cover adderror line in test, Its inside IF() Condition, Able to cover if() statement. But not adderror statement!!

  • February 09, 2013
  • Like
  • 0

global class Test{
    webService static String Attachment(string obj, string id) {
    
        String retRes = '';
        String[] emails = new String[]{};
        String emailList = null;
        String theHTML = 'The report header goes here!';
        PageReference thepage = null;
        Blob bpagePDF = null;
        String bpageHTML = theHTML;
        Integer i = 0;
        
        Contract__c con = [Select id from Contract__c where Id = :Id];
        String AccountName = con.Opportunity__r.Account.Name;
        if(obj=='Account'){
            for(Contact c : [Select Email from Contact Where AccountId = :id]) {
                emails.add(c.Email);
                if(i==0) emailList = c.Email;
                else emailList = emailList + ', ' + c.Email;
                i++;
            }
        }
        else if(obj=='Contract'){
            for(Contact c : [Select Email, Account.Name from Contact Where AccountId = :con.Opportunity__r.AccountID]) {
                emails.add(c.Email);
                if(i==0) emailList = c.Email;
                else emailList = emailList + ', ' + c.Email;
                i++;
            }
        }
        else{
            retRes = 'Call to Send email is invalid. Please contact your developer. Error 112.' + obj;
            return retRes;
        }
        
        try{
            thepage = new PageReference('/apex/test?id='+id);
            thePage.setRedirect(true);
            bpagePDF = thepage.getContentAsPDF();
            bpageHTML = thepage.getContent().toString(); 
        } catch(exception e){
            retRes = 'Page Error: '+e.getMessage();
            return retRes;            
        }
        
        if(emails.size()==0) emails.add([Select Email from User where Id =:UserInfo.getUserID()].email); 

        try { 
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setToAddresses(emails);
            mail.setReplyTo('no-reply@mas.com');
            mail.setSenderDisplayName('test');
            mail.setSubject('test');
            mail.setHtmlBody(bpageHTML);
            mail.setWhatId(id);

            Messaging.EmailFileAttachment efaPage = new Messaging.EmailFileAttachment();
            efaPage.setContentType('application/pdf');
            efaPage.setFileName(AccountName+' test.pdf');
            efaPage.setinline(true);
            efaPage.setBody(bpagePDF);
            
            mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efaPage});    //efaTable                    
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            retRes = 'Mail Sent Successfully to: ' + emailList;
            retRes = retRes + '\nFor Account: ' + AccountName;
        } catch(EmailException ex){
            System.debug(ex.getMessage());
            retRes = 'Email Error: '+ex.getMessage();
        } catch(Exception ex) {
           System.debug('Error-'+ ex);
           retRes = 'Exception error: '+ex.getMessage();
        }
        return retRes;
    }    
}

 

How to pass parameters in testcase. Above is my class.

  • February 07, 2013
  • Like
  • 0
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

 

  • April 03, 2013
  • Like
  • 0

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.

  • April 01, 2013
  • Like
  • 0

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,

                 

 

 

  • March 14, 2013
  • Like
  • 0

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>');

 

  • March 14, 2013
  • Like
  • 0

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

 

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

  • March 11, 2013
  • Like
  • 0

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 });
}
}

  • March 11, 2013
  • Like
  • 0

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?